List and get a reference to featurelayer in Web Map

1278
3
Jump to solution
11-07-2018 04:59 AM
KeithGanzenmuller
Occasional Contributor II

I am in the preliminary stages of developing a widget which will require me to reference a featurelayer. Testing how to loop through layers in the map and then pick out the one I want. I found and inserted the following code which, although it runs fine, does not list the featurelayer.

  

onOpen: function () {
                console.log('onOpen');
                for (var j = 0; j < this.map.layerIds.length; j++) {
                    var layer = this.map.getLayer(this.map.layerIds[j]);
                    console.log(layer.id + ' ' + layer.opacity + ' ' + layer.visible);
                }
            },

The code generates the following output:

postCreate
WidgetManager.js?wab_dv=2.10:114 widget [widgets/SelectAccidentDemo/Widget] created.
Widget.js?wab_dv=2.10:25 startup
Widget.js?wab_dv=2.10:42 onOpen
Widget.js?wab_dv=2.10:45 World_Street_Map_8421 1 true
Widget.js?wab_dv=2.10:45 AerialPhotos2017_8247 1 true
Widget.js?wab_dv=2.10:45 AGSPro_TileLayer_4565 1 true
Widget.js?wab_dv=2.10:67 onSignOut

All is great except it is missing the hosted featurelayer.

The map is linked here

The featurelayer shows up in the JSON when I log in to ArcGIS Online Assistant.

Thank you ahead of time for any help. 

1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Keith,

   Your issue is that a FeatureLayer is not part of the layerIds array. It is part of the maps graphicsLayerIds array, since FeatureLayer extends from GraphicsLayer.

https://developers.arcgis.com/javascript/3/jsapi/map-amd.html#graphicslayerids 

View solution in original post

3 Replies
RobertScheitlin__GISP
MVP Emeritus

Keith,

   Your issue is that a FeatureLayer is not part of the layerIds array. It is part of the maps graphicsLayerIds array, since FeatureLayer extends from GraphicsLayer.

https://developers.arcgis.com/javascript/3/jsapi/map-amd.html#graphicslayerids 

KeithGanzenmuller
Occasional Contributor II

Excellent, thank you Robert. 

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Don't forget to mark this question as answered by clicking on the "Mark Correct" link on the reply that answered your question.