function showResults(featureSet) { //remove all graphics on the maps graphics layer map.graphics.clear(); //Performance enhancer - assign featureSet array to a single variable. var resultFeatures = featureSet.features; //Loop through each feature returned for (var i = 0, il = resultFeatures.length; i < il; i++) { //Get the current feature from the featureSet. //Feature is a graphic var graphic = resultFeatures; graphic.setSymbol(symbol); //Set the infoTemplate. graphic.setInfoTemplate(infoTemplate); //Add graphic to the map graphics layer. nameGraphic = map.graphics.add(graphic); //set map extent to selected features //This works if more than one point// //var myFeatureExtent = esri.graphicsExtent(resultFeatures); //map.setExtent(myFeatureExtent); onQueryComplete(resultFeatures); //Want to use this function to determine zoom } }
function onQueryComplete(returnedPointFeatureSet) { var featureSet = returnedPointFeatureSet || {}; var features = featureSet.features || []; var extent = esri.graphicsExtent(features); if (!extent && features.length == 1) { var point = features[0]; map.centerAndZoom(point, 3); } else { map.setExtent(extent); } }
Solved! Go to Solution.
var theExtent = features[0].geometry.getExtent().expand(1.5); map.setExtent(theExtent);
var thePoint = features[0].geometry; var theExtent = pointToExtent(map,thePoint,15); map.setExtent(theExtent); //============================================================================= // Utility routine to convert a point's geographic location into a rectangle. // Used to provide a zoom extent for point features //============================================================================= function pointToExtent(map, point, toleranceInPixel) { //Function to convert a point coordinate into a rectangle area var pixelWidth = map.extent.getWidth() / map.width; var toleraceInMapCoords = toleranceInPixel * pixelWidth; return new esri.geometry.Extent( point.x - toleraceInMapCoords, point.y - toleraceInMapCoords, point.x + toleraceInMapCoords, point.y + toleraceInMapCoords, map.spatialReference ); }
var theExtent = features[0].geometry.getExtent().expand(1.5); map.setExtent(theExtent);
var thePoint = features[0].geometry; var theExtent = pointToExtent(map,thePoint,15); map.setExtent(theExtent); //============================================================================= // Utility routine to convert a point's geographic location into a rectangle. // Used to provide a zoom extent for point features //============================================================================= function pointToExtent(map, point, toleranceInPixel) { //Function to convert a point coordinate into a rectangle area var pixelWidth = map.extent.getWidth() / map.width; var toleraceInMapCoords = toleranceInPixel * pixelWidth; return new esri.geometry.Extent( point.x - toleraceInMapCoords, point.y - toleraceInMapCoords, point.x + toleraceInMapCoords, point.y + toleraceInMapCoords, map.spatialReference ); }
var thePoint = features[0].geometry; var theExtent = pointToExtent(map,thePoint,15); map.setExtent(theExtent);
function showResults(featureSet) { //remove all graphics on the maps graphics layer map.graphics.clear(); //Performance enhancer - assign featureSet array to a single variable. var resultFeatures = featureSet.features; //Loop through each feature returned for (var i = 0, il = resultFeatures.length; i < il; i++) { //Get the current feature from the featureSet. //Feature is a graphic var graphic = resultFeatures; graphic.setSymbol(symbol); //Set the infoTemplate. graphic.setInfoTemplate(infoTemplate); //Add graphic to the map graphics layer. nameGraphic = map.graphics.add(graphic); //set map extent to selected features if (resultFeatures.length == 1) { var thePoint = resultFeatures[0].geometry; map.centerAndZoom(thePoint, 3); } else { var myFeatureExtent = esri.graphicsExtent(resultFeatures); map.setExtent(myFeatureExtent); } } }