AnsweredAssumed Answered

map.layers.items vs. map.layers._items

Question asked by processing... on Sep 24, 2015
Latest reply on Sep 29, 2015 by processing...

What is the proper way to reference a dynamically created graphics layer in 4.0 beta1? When I debug after map.add(graphicsLayer), I get the following data:

 

map.layers.items.length = 0

map.layers._items.length = 10 (expected number of dynamically added layers)

 

I've confirmed a map and mapview instance. I create a new GraphicsLayer (providing no id at this time... please see code snippet below). I add a graphic to the graphics layer. Then, I call map.add(graphicsLayer).

 

var graphicsLayer = new GraphicsLayer({ });       

graphicsLayer.add(graphic);           

map.add(graphicsLayer);

 

In the above code, I've made sure that:

- graphic's declaredClass is esri.Graphic

- graphic's geometry's declaredClass is esri.geometry.Point and that there is an x/y value.

- graphicsLayer's declaredClass is esri.GraphicsLayer

- graphics do appear on the map

 

So, my questions:

 

1. Why are there API objects prefixed with an underscore? Are they intended for internal use only? (I've noticed this in 3.x and 4.0 beta 1)

2. Why is there data in map.layers._items but not map.layers.items?

3. If I programmatically set a graphicslayer id, I can reference the layer by id. But, without setting an id, the id is automatically generated and I won't know the id in code. What's the proper way to reference a dynamically created layer without a provided id?

 

Slightly OT and not as important: Did 3.x code allow for graphicsLayers (or other layers) to have the same id as other layers on a map? I noticed a hiccup in my code where a set id is blank, but all of the graphicsLayers still appeared on the map in 3.x but not for 4.0beta1.

 

Thanks,

D

Outcomes