I'm having a little trouble accessing my feature layer in the Web Appbuilder app. If I did the following outside of WAB, just in a testing JS 3.x environment, it would work.
<script>
</script>
But in WAB, myFL already exists in there, so if I do map.addLayer(myFL), it's adding it a second time, but that's the only way I can successfully return anything on a click event.
If I do the following in WAB, not adding the layer (because it's already in the map and I don't want it twice), I can't return anything on the click event. I'm not sure what I'm missing that I can't return anything?? I feel like I've tried everything to access this layer, I've tried map.getLayer(id), and that didn't work. Not sure why it isn't working...
<script>
</script>
Solved! Go to Solution.
Joel,
ConstructionSvcs_scratch_6492_6 means that the layer is a sub layer of a ArcGISDynamicMapServiceLayer so though the layer is added to the map an ArcGISDynamicMapServiceLayer sublayer is not an actual layer that can have a click event. An ArcGISDynamicMapServiceLayer is just an image returned from the server and thus no actual geometry is returned to the client that could be used for a click event. You need to add the layer as a Feature layer so that the client is getting actual geometries returned to it.
Joel,
If the layer is already added to the map then you just need to get a reference to the layer and add your on click method to the existing layer in the map.
var myfl = this.map.getLayer("your layer id");
Thanks Robert,
I was trying that before, the only thing I can think of is that I'm not getting the right ID.
in getLayer(ID), would it be "6" here? or "Taxlots"? Neither work, but I want to make sure I'm at least getting the right one. Does it matter that it's in a group layer, and it's a child of Landbase?
Joel,
Nope neither of those are the id as you have seen. The easyest way to find the layers ID is to open the layerlist widget and right click on the layer in your layerlist and choose inspect or inspect element. It will look something like this:
<div class="layer-title-div-ParcelViewerWM_1607 div-content jimu-float-leading ">Parcel Data</div>
The layers id is ParcelViewerWM_1607
Ok thanks,
Just so I'm not totally going insane here, looking at my code, is there any thing that jumps out at you with the onOpen method?
I keep getting this error, and I don't understand why.
TypeError: Unable to get property 'on' of undefined or null reference
<script>
</script>
Joel,
ConstructionSvcs_scratch_6492_6 means that the layer is a sub layer of a ArcGISDynamicMapServiceLayer so though the layer is added to the map an ArcGISDynamicMapServiceLayer sublayer is not an actual layer that can have a click event. An ArcGISDynamicMapServiceLayer is just an image returned from the server and thus no actual geometry is returned to the client that could be used for a click event. You need to add the layer as a Feature layer so that the client is getting actual geometries returned to it.
OK, that was the issue. Thanks Robert!!