Select to view content in your preferred language

Using esri.arcgis.utils.createMap, there's a Feature Layer being introduced

3142
8
01-14-2013 12:41 PM
JoanneMcGraw
Frequent Contributor
Hello all,

When I use esri.arcgis.utils.createMap and provide the id to a map that only has a basemap and a single Mapping Service in it, the map that is returned to the callback function has an extra layer in it. It is a FeatureLayer of the layer within the mapping service that is visible.

For example, if the mapping service included in the map is:

http://<my_domain>/arcgis/rest/services/<some_service>/MapServer

Then, this new Feature Layer's url is:

http://<my_domain>/arcgis/rest/services/<some_service>/MapServer/3 (assuming it's layer 3 that's displayed in the map).

Can anyone tell me where that's coming from? Why it's there? Can I stop it? And, most importantly, what property associated with it indicates that I can ignore it as some kind of internal layer that the ESRI JSAPI is making for some reason?

I am creating a tree that displays the Feature Layers and Mapping Layers of a map to allow users to check on/off individual layers in the display. But this layer isn't one that actually "exists" in the original map and shouldn't be showing up (like not showing the user the map_graphics layer) but I don't know how to differentiate it from a "legitimate" Feature Layer from the original map.

Hints? Clues? Anything?

Cheers,
jtm
0 Kudos
8 Replies
KellyHutchins
Esri Frequent Contributor
I think the easiest way to determine the layers in the web map is by using the response object. If you take a look at response.itemInfo.itemData you'll see baseMap which defines the basemap used by the web map and operationalLayers which is an array of the layers in your map.

The web map JSON format spec has details on the different types of layers:

http://resources.arcgis.com/en/help/arcgis-web-map-json/#/Web_map_format_overview/02qt00000007000000...
0 Kudos
JoanneMcGraw
Frequent Contributor
I have looked in the response's itemInfo.itemData and found that the operationalLayers array contains a single layer item, which is the only mapping service I added to the Web Map. In the response's map, however, it's _layers array contains two entries for this mapping service. One is the ArcGISDynamicMapServiceLayer I added (and which I would expect to see) and the second is a FeatureLayer for the single visible layer within that service that is displayed by default. It is that layer which is causing me problems.

Does anyone have any ideas why that is there? And, if it is necessary for the API, how do I differentiate that FeatureLayer that is being created dynamically for some reason from a FeatureLayer that I had actually added to the Web Map myself?

Thank you for your reply, Kelly.

Cheers,
jtm
0 Kudos
KellyHutchins
Esri Frequent Contributor
I suspect that the 'extra' feature layer is there to support pop-ups. To see the sub layers for the dynamic layer check the operationalLayers[layerId].resourceInfo.layers.

If you add a feature layer to the map you'll see that the resourceInfo.type is 'Feature Layer'.
0 Kudos
JoanneMcGraw
Frequent Contributor
This is good information to know, but I realize now that I haven't been clear that what I am looking for is a way to differentiate these feature layers within the map object not at the time of the createMap callback.

The tree I note in the initial post is created at the user's discretion; that is, they may (or may not) invoke functionality that requires the creation of this tree based on the current state of the map which is not necessarily what it was when it was initially loaded. Layers may have been added or removed or reordered since. Consequently, I need some way of identifying this FeatureLayer (or any other FeatureLayer that is being added dynamically to support internal API functionality) that the end user would never be aware of from looking at the map so that it isn't added to the tree.

You suggested it may be related to the pop-up functionality. Are you aware of any way that I can turn that off or disable it during the createMap functionality so that the layer is not created?

Thanking you again for your help, Kelly,
jtm
0 Kudos
JoanneMcGraw
Frequent Contributor
Further, I have a different web map that is not creating this FeatureLayer for Mapping Services contained in the Web Map.

So, there is something about how this Web Map is defined that is making it create one when the createMap is used. I can't track down what that might be if I don't know why it's being made in the first place.

Cheers,
jtm
0 Kudos
KellyHutchins
Esri Frequent Contributor
Is your web map public? If so can you share the id?

There may be several situations when feature layers are created for the dynamic layer including when using popups.  You could try disabling popups in the web map  or by setting the createMaps constructor option ignorePopups to true and see if that helps. But doing that will remove the built-in popup capability so if you have them defined for that map you will not see them in your app.

I don't see a property that will let you differentiate between a layer you add and the feature layer's added when a map is created based on a web map. You could add a property to layers you add through code and use this to check? Or compare the url with any map service urls in the map?
0 Kudos
JoanneMcGraw
Frequent Contributor
Unfortunately, it is not a Web Map that I have the authority to make public at this time.

I looked into whether the popups were enabled in it and they are, so that is most likely where it is coming from then. Certainly, when the user clicks on the map and the popup is displayed it is also showing the "selected feature" that was clicked on.

Perhaps I should think about this differently... Since it really is a FeatureLayer in the map, perhaps showing it to the user will not be the end of the world if I can make it act like the other FeatureLayers that were actually added to the Web Map. For example, should a setVisibility call on that layer work as it does for any other? Currently, it doesn't hide the feature that was clicked on...do you know if it should?

Cheer,s
jtm
0 Kudos
JoanneMcGraw
Frequent Contributor
Actually, does anyone know how ArcGIS Online knows not to display that FeatureLayer in the Contents list when popups are enabled on a mapping layer? If they're able to figure it out, I must be too.

Perhaps they are adding a property, too?

I'll look into that idea further tomorrow. Perhaps, during the createMap callback I can compare operationalLayers array with the graphicsLayerInfos and determine if there are "new" feature layers being added that aren't part of the original map and flag all the others as valid and displayable in this tree I'm making.

I'll let the forum know how it goes.

Thank you for your information and help, Kelly!!

Cheers,
jtm
0 Kudos