//use the locator to find the input location function findLocation() { var searchText = dojo.byId('searchField').value; //clear any existing map graphics map.graphics.clear(); var address = {}; address[configOptions.placefinder.singlelinefieldname] = searchText; var options = { address:address, outFields:["*"] }; locator.addressToLocations(options); } //display the location results on the map function showResults(candidates) { var candidate; var geom; //hide the info window if displayed if(map.infoWindow.isShowing){ map.infoWindow.clearFeatures(); map.infoWindow.hide(); } var zoomExtent; dojo.every(candidates, function (candidate) { if (candidate.score > 80) { geom = candidate.location; map.infoWindow.setTitle(i18n.tools.search.title); map.infoWindow.setContent(candidate.address); map.infoWindow.show(geom); zoomExtent = new esri.geometry.Extent(candidate.attributes.West_Lon, candidate.attributes.South_Lat,candidate.attributes.East_Lon, candidate.attributes.North_Lat, new esri.SpatialReference({wkid:4326})); console.log(zoomExtent.toJson()); return false; //break out of loop after one candidate with score greater than 80 is found. } }); if (geom !== undefined) { //if the extent is constrained check to see if geocode result is within extent.If it is then zoom otherwise don't. if((configOptions.constrainmapextent === 'true' || configOptions.constrainmapextent === true) && !webmapExtent.contains(geom)){ dojo.byId('searchField').value = i18n.tools.search.errors.missingLocation; map.infoWindow.hide(); }else{ map.setExtent(esri.geometry.geographicToWebMercator(zoomExtent)); } }else{ //no matches found dojo.byId('searchField').value = i18n.tools.search.errors.missingLocation; } }
Hi Mike,I am also trying to set the zoom level for the locator search. What am I missing? I am utilizing the basic viewer template (2.8 javascript api). Which I think included your code sample. However I am still unable to change the zoom level I even added. if (geom !== undefined) { map.centerAndZoom(geom,12); to the layout.jsI know if is probable very simple. help
if (geom !== undefined) { map.centerAndZoom(geom,12); //if the extent is constrained check to see if geocode result is within extent.If it is then zoom otherwise don't. if ((configOptions.constrainmapextent === 'true' || configOptions.constrainmapextent === true) && !webmapExtent.contains(geom)) { dojo.byId('searchField').value = i18n.tools.search.errors.missingLocation; map.infoWindow.hide(); } else { map.setExtent(esri.geometry.geographicToWebMercator(zoomExtent)); } } else { //no matches found dojo.byId('searchField').value = i18n.tools.search.errors.missingLocation; } }
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.