Strange Magic In Layer List ... Bug?

1100
11
11-09-2018 05:56 AM
JohnRichardson
New Contributor III

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,

   Have you checked the LayerList.operationalItems collection?

0 Kudos
JohnRichardson
New Contributor III

No ... let me investigate that

0 Kudos
JohnRichardson
New Contributor III

I can't make anything happen with the operationalitems collection either ... same result

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Same result.. Meaning that there is a layer listed there besides your 4 other layers?

0 Kudos
JohnRichardson
New Contributor III

Yes

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

So it sounds like you layer remove login is flawed. What does 

map.layers.length

say when you have completed your remove click function?

0 Kudos
JohnRichardson
New Contributor III

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

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

John,

  Have you tried re-setting the widget view property?

0 Kudos
JohnRichardson
New Contributor III

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

0 Kudos