identifyTask = new esri.tasks.IdentifyTask(http://yourserver/ArcGIS/rest/services/serviceName/MapServer"); identifyParams = new esri.tasks.IdentifyParameters(); identifyParams.tolerance = 1; // identifyParams.returnGeometry = false; identifyParams.layerIds = [0,1,2]; identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE; identifyParams.spatialReference = spatialReference; identifyParams.extent = map.extent; identifyParams.width = map.width; identifyParams.height = map.height; dojo.connect(map, "onClick", function () {idFromClick = true;}); dojo.connect(map, "onClick", executeIdentifyTask);
//identify either from map click or geocoded location function executeIdentifyTask(evt) { identifyParams.mapExtent = map.extent.expand(0.1); identifyParams.geometry = evt; //input from address, evt is already a map point var inputPt = evt; if (idFromClick) { // input from map click identifyParams.geometry = evt.mapPoint; inputPt = evt.mapPoint; } var deferred = identifyTask.execute(identifyParams); deferred.addCallback(function(response) { return dojo.map(response, function(result) { var feature = result.feature; var layerName = result.layerName; feature.attributes.layerName = result.layerName; feature.setInfoTemplate(plainTemplate); return feature; }); }); map.infoWindow.setFeatures([ deferred ]); map.infoWindow.show(inputPt); //point type is the same coming from either method }
function showResults(candidates) { var candidate; var symbol = new esri.symbol.SimpleMarkerSymbol(); var addressTemplate = new esri.InfoTemplate("Location", "Address: ${address}<br />"); symbol.setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE); symbol.setColor(new dojo.Color([255,0,0,0.75])); dojo.every(candidates,function(candidate){ console.log(candidate.score); if (candidate.score > 80) { console.log(candidate.location); var attributes = { address: candidate.address, score:candidate.score, pt:candidate.location }; geometryPt = candidate.location; var graphic = new esri.Graphic(geometryPt, symbol, attributes, addressTemplate); map.graphics.add(graphic); var displayText = candidate.address; map.infoWindow.show(geometryPt); map.infoWindow.setTitle("Address"); return false; //break out of loop after one candidate with score greater than 80 is found. } }); map.centerAndZoom(geometryPt,12); executeIdentifyTask(geometryPt); } }
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.