We have made some changes to how the zoom works for the next release of the template that will determine the 'best fit extent' for the resulting address and zoom to that. Currently, the template uses a hardcoded a zoom level. Here�??s the updated code if you want to try it this in your app. You'll need to replace the existing findLocation and showResults functions in layout.js with these. //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;
}
}
Thanks,Mike