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 featurelayer shows up in the JSON when I log in to ArcGIS Online Assistant.
Thank you ahead of time for any help.
Solved! Go to Solution.
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
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
Excellent, thank you Robert.
Don't forget to mark this question as answered by clicking on the "Mark Correct" link on the reply that answered your question.