miribsystematics-co-il-esridist

Remove ArcGISDynamicServiceLayer

Discussion created by miribsystematics-co-il-esridist Employee on Oct 25, 2012
Latest reply on Oct 28, 2012 by miribsystematics-co-il-esridist
Hi,

I have a dynamic layer. I use Lavascript API 3.2.
I want to toggle visibility of DynamicLayer on each click on the button.

I tried to remove it in many ways but it is still show on the map.
The latest try is attached:





elecUrl = "http://gis2012.emap.co.il/arcgis/rest/services/CompareElections/MapServer";
elecLayer = new esri.layers.ArcGISDynamicMapServiceLayer(elecUrl, {
"id": "elec",
"opacity": 0.7
});
if (elecLayer != null) {
if (map.layerIds.length > 1) {
//var visible = [];
//visible.push(-1);
//elecLayer.setVisibleLayers(visible);

map.removeLayer(elecLayer);
}
else {
elecLayer.setVisibleLayers([0]);

var symbol = new esri.symbol.SimpleFillSymbol();
symbol.setColor(new dojo.Color([150, 150, 150, 0.5]));

var renderer = new esri.renderer.UniqueValueRenderer(symbol, "WinningParty");
renderer.addValue("א�?ת", new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([238, 31, 58, 1])));
renderer.addValue("�?", new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([132, 164, 203, 1])));
renderer.addValue("�?", new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([121, 71, 0, 1])));
renderer.addValue("�?", new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([126, 149, 102, 1])));
renderer.addValue("�?", new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([39, 166, 117, 1])));
renderer.addValue("�?", new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([71, 102, 36, 1])));
renderer.addValue("�?", new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([160, 160, 225, 1])));
renderer.addValue("�?�?", new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([255, 140, 0, 1])));
renderer.addValue("�?", new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([91, 91, 169, 1])));
renderer.addValue("�?�?�?", new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([25, 106, 255, 1])));
renderer.addValue("�?רץ", new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([0, 206, 0, 1])));
renderer.addValue("עם", new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([182, 212, 168, 1])));
renderer.addValue("שס", new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([136, 111, 69, 1])));



// set up the parameters for the dynamic layer
var optionsArray = [];
var drawingOptions = new esri.layers.LayerDrawingOptions();
drawingOptions.renderer = renderer;
optionsArray[0] = drawingOptions;
elecLayer.setLayerDrawingOptions(optionsArray);
// add the layer to the map
try {
map.addLayer(elecLayer);
}
catch (err) {
console.log(err.message);
}
}


What do I do wrong?
As you can see in comment, I tried setVisibleLayers but no impact on the map - it still shows the layer.

Please try to help ASAP.

Thanks a lot,
Miri

Outcomes