I have an application that has 4 layers that I want to stay available in my map at all times. In my layer list, they appear as follows:
The code that creates the layers follows:
var featurelayer = new FeatureLayer({ //adds a feature layer of 2018 Crime
url: "http://172.20.25.165:6080/arcgis/rest/services/Crime2018_110218/FeatureServer",
title: "2018 Crime",
renderer: crimeRenderer,
visible: false,
popupEnabled: false,
popupTemplate: crimePopupTemplate
});
map.add(featurelayer, 2);
var apdbeatsLayer = new FeatureLayer({ //adds a feature layer of APD Beats
url: "http://172.20.25.165:6080/arcgis/rest/services/APD_Beats_Feature/FeatureServer",
title: "APD Beats",
renderer: beatsRenderer,
popupEnabled: false,
popupTemplate: beatsPopupTemplate,
opacity: 0.5,
visible: false
});
map.add(apdbeatsLayer, 3);
var orthLayer = new ImageryLayer({ //adds an image layer of Orthos SCE
url: "http://172.20.25.165:6080/arcgis/rest/services/Ortho_SCE/ImageServer",
title: "Ortho - East",
visible: false
});
map.add(orthLayer, 0);
var orthLayer2 = new ImageryLayer({ //adds an image layer of Orthos SCW
url: "http://172.20.25.165:6080/arcgis/rest/services/Ortho_SCW/ImageServer",
title: "Ortho - West",
visible: false
});
map.add(orthLayer2, 1);
At any time, the user may choose a month from a menu, and a query runs against the 'featurelayer' and then displays only the crimes for that month in a new featurelayer :
Here you can see that I have added 4 months of crime data to the map, each layer a different color, and you can also see the layers show up in the layer list :
I have a radial menu, which has an icon to click to remove any added layers from the layer list, as it can get crowded quick:
The icon code for removing the added layers, and leaving the 4 default layers is as follows:
$("#ichyPic").click(function() {
var layLength = map.layers.length;
/*alert(layLength);
map.layers.removeAll();*/
while (layLength > 4) {
map.layers.removeAt(layLength-1);
layLength--;
}
});
If 4 or more layers have been added to the map, the code above eliminates all of the layers,but still leaves a straggler behind, at the bottom of the layer list ... this layer, as you can see in the picture below, is turned on, but nothing shows on the map ... the layer is not real, it just shows up ... I think this may be a bug?
Thank you!
John,
Have you checked the LayerList.operationalItems collection?
No ... let me investigate that
I can't make anything happen with the operationalitems collection either ... same result
Same result.. Meaning that there is a layer listed there besides your 4 other layers?
Yes
So it sounds like you layer remove login is flawed. What does
map.layers.length
say when you have completed your remove click function?
It says 4 ... the layer at the bottom is not really there ... seems like a bug ... you cannot view the layer listed at the bottom either ... empty
John,
Have you tried re-setting the widget view property?
Just tried it ... added layerList.view = view to the function ... still no luck ... weird
Another thing ... if you add 8 or more layers to the view, you get 2 stragglers at the bottom of the layer list, instead of just one ... very odd