I'm contemplating how to set up my function so that it accepts a geometry (the user will be able to use the draw toolbar to create the search geometry) and will 'query' any layer in the map that is visible.
* All results will get written to a central graphics array so that I can put the results in a side panel, display 'selected' graphics on the map, and highlight the current attributes being viewed in the side panel.
* The map uses different layer types that all need to be queried at once and the results managed together: ArcGISDynamicMapServiceLayer, FeatureLayer, CSVLayer (from local user file), GraphicsLayer (build on demand from JSON string)
* Search geometry could be a point, line, or polygon
* Map layers could contain point, line, or polygon features/graphics
Suggestions on any of this would be appreciated.
Have a look at IdentifyTask | API Reference | ArcGIS API for JavaScript
You have a couple of issues to resolve to get this to work:
1. Creating the selection geometry:
This is the easy bit - just use the draw toolbar.
2. Query visible map layers:
This is where things start to get tricky. There is no way you can query them all at once. Your function will need to use a DeferedList to track when all queryTasks are completed. This post has some great information: How to use dojo.Deferred, dojo.DeferredList, and .then. When all results are returned then you can add them to your central graphics array.
Note that you will also need to develop slightly different query tasks depending on the layer type and selection geometry.
I've got the selection geometry working and am testing if the layer has supports Query capability (this gets me results for Dynamic and Feature layers). I'm hung up on how to handle graphics and csv layers though. Any suggestions? I was thinking that I'd have to find the extent of the search geometry and then run something like
var filteredGraphics = dojo.filter(featureLayer.graphics, function (graphic) {
return searchExtent.contains(graphic.geometry);
});
For graphics layers you have the right approach using the the extent.contains() method, or the extent.intersects() method. This sample shows using the draw toolbar to capture the selection extent and then uses the extent.contains() method to return points in the extent.
You should be able to use the same approach with a CSVLayer by looping through the CSVLayer.graphics array and using the extent.contains() method.