Select to view content in your preferred language

Strange Magic In Layer List ... Bug?

1856
11
11-09-2018 05:56 AM
JohnRichardson
Regular Contributor

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!

0 Kudos
11 Replies
RobertScheitlin__GISP
MVP Emeritus

John,

  Your best bet it to develop a simplified as possible sample that you can share with esri tech support when you call then.

0 Kudos
JohnRichardson
Regular Contributor

Robert ... will do ... I will create a fiddle or something

Thanks for looking at this

0 Kudos