English

How To: Use ValueMapLabelRenderer object in ArcIMS Java Viewer

Summary

Instructions provided describe how to use ValueMapLabelRenderer in the ArcIMS Java Viewer object model.

Procedure

When using ValueMapLabelRenderer, make sure to call setField(), as well as setFields(), method on ValueLabelRenderer object. In the setField() method, it is necessary to pass the value field, whereas in the setFields() method, a collection of one or more label fields must be passed. Here is an example code:

Code:

function setValueLabelRenderer(){

var mapApplet=parent.mapFrame.document.IMSMap;
var layer=mapApplet.getSelectedLayer()

if (layer==null) {
alert('No Layer is active!')
return
}

//create a valuemap label renderer and set the value field
var labelRenderer=mapApplet.createRenderer('VALUE_LABEL_RENDERER')
labelRenderer.setField(layer,'STATE_NAME');

//call setFields method to specify the collection of label fields
var col = mapApplet.createCollection();
col.addStringElement('STATE_NAME');
labelRenderer.setSeparator(':');
labelRenderer.setFields(layer,col);

// create a label symbol object
var labelSymbol = mapApplet.createSymbol('TEXT_SYMBOL');

// set the label symbol object’s display properties
var newColor1 = mapApplet.createColor(255,0,0);
labelSymbol.setFont("Arial",10);
labelSymbol.setAntialiasing("true")
labelSymbol.setFontColor(newColor1);
labelSymbol.setTransparency(1.0);

//create a defaultsymbol for non-matching values
var defaultLabelSymbol=mapApplet.createSymbol('TEXT_SYMBOL')
defaultLabelSymbol.setTransparency(0.0);

//assign renderer to unique values
labelRenderer.setSymbolForUniqueValue(labelSymbol,layer,'STATE_NAME','California');
labelRenderer.setSymbolForUniqueValue(labelSymbol,layer,'STATE_NAME','Oregon');
labelRenderer.setSymbolForUniqueValue(labelSymbol,layer,'STATE_NAME','Nevada');

//assign the default symbol
labelRenderer.setDefaultSymbol(defaultLabelSymbol);

//set ValueMapLabelRenderer to the layer
mapApplet.setLayerLabelRenderer(layer, labelRenderer);

//redraw the map to apply the renderer changes

mapApplet.redraw();

}