I am trying to use someone else's map service in my web map, but their symbology is atrocious so I need to render new colors through JavaScript API.
I try the following (amongst many other efforts spanning 2 days):
parcels = new ArcGISDynamicMapServiceLayer(config.mapServices.parcels, {id:"Parcels"});
parcels.on("load", function(){
var layerDrawingOptions = [];
var layerDrawingOption = new LayerDrawingOptions();
// set symbology overrides
layerDrawingOption.renderer = new SimpleRenderer(symbols.polygon);
// the following index represents the layers in the service to apply the renderer to
layerDrawingOptions[8] = layerDrawingOption;
parcels.setLayerDrawingOptions(layerDrawingOptions);
parcels.setImageFormat("png32");
parcels.setVisibleLayers([8]); //schools,streets,parks,parcels,boundaries,shields
}) ;
map.addLayer(parcels);
I am following this currently:
https://developers.arcgis.com/javascript/jsapi/layerdrawingoptions-amd.html#renderer
The few examples at the API deal with renderers for class-breaks, etc, I need to resymbolize all parcels, which should be a similar concept. Any ideas on how I can symbolize a dynamic layer at the client rather than the server using JS API?
Best Answer
the two most common gotchas for Dynamic Layers are:
the service itself doesn't support requests to alter symbology. (make sure Supports Dynamic Layers is
true
in the service metadata)the index position in the layer drawing options array doesn't match the index position of the layer.
i published a working sample here