I'm developing a web mapping application where the client specifically requested the ability to turn each layer on and off, while retaining the ability to select the visible features. Out of 17 total layers, 15 need to be selectable by the user using a "select by shape" tool. Of these 15, 11 are points and 4 are polygons.
Now, what's the best way to handle these 15 layers? Do I need to create a esri.layers.FeatureLayer for each of these 15? Since I'm just selecting them, could I use esri.layers.querytask instead? Would I need to create a separate map service for each of these 15 as well?
Has anybody been in this situation before where your application has multiple selectable layers? How do you organize them within your map service?
I apologize for the ignorance, but this is my first project, and needless to say, it isn't small.
Thanks,
Andrew
var identifyTask = new esri.tasks.IdentifyTask(your_mapService_URL); var identifyParams = new esri.tasks.IdentifyParameters(); identifyParams.tolerance = 2; identifyParams.returnGeometry = true; identifyParams.layerIds = your_selectable_layerids; identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE; identifyParams.geometry =your_drawn_shape; identifyParams.mapExtent =map.extent; identifyParams.width = map.width; identifyParams.height = map.height; identifyTask.execute(identifyParams, function(identifyResults){ ..... after identify logic go here.... });
From what you described, in my opinion, the feasible approach would be put all layers in one map service and use identify task to do the search or selection. The advantage of using identify task is you only need send one request to the server and get all the results from layers, and you can use spatial filter-the shape you draw (IdentifyParameters.geometry =your drawn shape) to do the selection, and you only search limited area (map.extent -what are on the current map). Code Snippet:var identifyTask = new esri.tasks.IdentifyTask(your_mapService_URL); var identifyParams = new esri.tasks.IdentifyParameters(); identifyParams.tolerance = 2; identifyParams.returnGeometry = true; identifyParams.layerIds = your_selectable_layerids; identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE; identifyParams.geometry =your_drawn_shape; identifyParams.mapExtent =map.extent; identifyParams.width = map.width; identifyParams.height = map.height; identifyTask.execute(identifyParams, function(identifyResults){ ..... after identify logic go here.... });
Thanks for the tip! I'm going to give it a try now. But I have one quick question, how would I highlight the selected points/polygons if they were queried? Would I use showFeature? Does it support multiple features?