Hello All,
I am writing a custom trace tool widget, and will need to highlight features on a web map returned from the REST API. I have a function called getFeatureLayers, and I'm calling it from the widget startup function, passing in a layerStructure that I get from the LayerStructure.getInstance(). To test highlighting, I am trying to highlight all features on the map first. I thought I needed to use the selectFeatures method on FeatureLayer, but nothing gets highlighted on the map. No errors or warnings are thrown, but nothing happens. The traversal seems to work, as I get back 14 feature layers. My code is below. What am I missing?
Solved! Go to Solution.
Damon,
Do a console.log on this.map.spatialReference and I bet you will find that it is null. the reason would be that you are not using lang.hitch to maintain the current code scope of the "this" object.
Damon,
I normally just create a Graphics Layer from the query results on the layers URL. If you are stuck on using the featurelayer select then you need to look into using the jimu.js selection manager class.
Hi Robert,
Thank you for the information. Are there any code examples available for either method?
Damon,
As for code examples you can look in the OTB Query Widget or custom widgets like my eSearch widget, or just look at the JS 3.x API samples.
Hi Robert,
Thank you again, I'll take a look at the widgets. I am trying to use the SelectionManager first, before moving onto the widgets. I called the setSelection method on the SelectionManager class, but nothing gets highlighted. Is my code wrong?
That code seems to be fine (assuming that val is not null and the graphics property is not null). Here is a line from the otb Edit widget that uses SelectionManager:
I found that the val.graphics property is empty, so I tried passing in features.features as the second parameter to setSelection (code below). I finally got a solid dot to render, but it rendered in Africa and I'm using the Naperville utility network sample. I used the queryFeatures method this time because it was the only way I could figure out how to get features to send to setSelection. I found some other samples online that suggested using the returnGeometry, outFields and outSpatialReference query properties, but those did not help. Any idea why the dot is so far off?
Damon,
Do a console.log on this.map.spatialReference and I bet you will find that it is null. the reason would be that you are not using lang.hitch to maintain the current code scope of the "this" object.
Thank you very much, the "this" object scope was the issue. I changed the code a bit and the dot is now rendering in the correct location. I added a variable to hold the "this" object, and used that to get the spatialReference property.