var geometryPt; var idFromClick = true;
dojo.connect(map, "onClick", function () {idFromClick = true;}); dojo.connect(map, "onClick", executeIdentifyTask);
function executeIdentifyTask(evt) { identifyParams.mapExtent = map.extent.expand(0.1); identifyParams.geometry = evt; 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) { // response is an array of identify result objects // Let's return an array of features. return dojo.map(response, function(result) { var feature = result.feature; feature.setInfoTemplate(myTemplate); return feature; }); }); // InfoWindow expects an array of features from each deferred object that you pass. If the response from the task execution // above is not an array of features, then you need to add a callback like the one above to post-process the response and return an // array of features. map.infoWindow.setFeatures([ deferred ]); map.infoWindow.resize(175,100); map.infoWindow.show(inputPt); //point type is the same coming from either method //map.infoWindow.show(evt.mapPoint); }
function locate() { You can see at the very end I'm using the geocoded point as the input to the identify. idFromClick = false; //executeIdentifyTask handles the type of point being passed. map.infoWindow.hide(); map.graphics.clear(); geometryPt = ""; var address = {"SingleLine":dojo.byId("txtAddress").value}; locator.outSpatialReference= map.spatialReference; var options = { address:address, outFields:["Loc_name"] }; locator.addressToLocations(options); } 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); //add a graphic to the map at the geocoded location map.graphics.add(graphic); //add a text symbol to the map listing the location of the matched address. 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. } }); if(geometryPt !== undefined){ var containsCountyPosition = (dojo.byId("txtAddress").value.toLowerCase().indexOf(" county")); if (containsCountyPosition > 0) { map.centerAndZoom(geometryPt,10); } else { 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.