How to use IdentifyTask to query JSON

المشرف العام

Administrator
طاقم الإدارة
I have a map application that harvests it's map layers from a JSON string. I've managed to use the following code to show the map layers when a user clicks on a layer name in a table of contents but any success to use IdentifyTask to return individual features when someone clicks on a map layer is alluding me?! This is an extract of the code that returns the map layers:

for (index in jsonString.Recreation) { if (jsonString.Recreation[index].id == myID) { var layerURL = jsonString.Recreation[index].url; var layerids = jsonString.Recreation[index].layer; var fieldids = jsonString.Recreation[index].field; //alert('LayerURL or record ' + layerURL + layerids); addLayertoMap(layerURL, layerids, fieldids) //debugger; } }for (index in jsonString.Waste) {if (jsonString.Waste[index].id == myID) { var layerURL = jsonString.Waste[index].url; var layerids = jsonString.Waste[index].layer; var fieldids = jsonString.Waste[index].field; addLayertoMap(layerURL, layerids, fieldids) } } }); function addLayertoMap(layerURL, layerID) { var dynamicLayer = map.getLayer("DynamicLayer"); if (dynamicLayer) { map.removeLayer(dynamicLayer); } var dynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer(layerURL, { "id": "DynamicLayer" }); dynamicMapServiceLayer.setVisibleLayers([layerID]); map.addLayer(dynamicMapServiceLayer); }I've added the fieldids variable in the for loop so that I can use IdentifyTask to allow users to click on map layers to return their attributes, this is the code so far:

function initIdentify(evt) { //create identify tasks and setup parameters identifyTask = new esri.tasks.IdentifyTask(fieldids, { "id": "DynamicLayer" }); identifyParams = new IdentifyParameters(); identifyParams.tolerance = 12; identifyParams.returnGeometry = true; identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE; identifyParams.width = map.width; identifyParams.height = map.height; map.on("click", executeIdentifyTask); } Can anyone help to see where I'm going wrong?? I'd like to add the results of the IdentifyTask to a div if possible?? Any pointers are much appreciated.



أكثر...
 
أعلى