Zoom to extent working for multi points but not single point

976
2
05-30-2014 10:46 AM
DaveTaylor
New Contributor
I have a filter by points working so when a user types something into a text box and hits a button it queries the map and zooms them to the queried results. This works fine for multiple points but is not working when the result is just a single point. Below is my code. Thanks in advance!

//remove all graphics on the maps graphics layer
    map.graphics.clear();
 var extent = esri.graphicsExtent(featureSet.features); 
 map.setExtent(extent.expand(1), true);
0 Kudos
2 Replies
ScottGunn
New Contributor III
This is a limitation with graphicsExtent.  You basically have to check for a single point and, if that's the case, use the centerAndZoom function.  Look below for a solution:

http://forums.arcgis.com/threads/93686-graphicsExtent-and-the-single-point
0 Kudos
NoppadonHimananto
New Contributor II
I have a filter by points working so when a user types something into a text box and hits a button it queries the map and zooms them to the queried results. This works fine for multiple points but is not working when the result is just a single point. Below is my code. Thanks in advance!

//remove all graphics on the maps graphics layer
    map.graphics.clear();
 var extent = esri.graphicsExtent(featureSet.features); 
 map.setExtent(extent.expand(1), true);


You must create new extent and expand that single point like this.
var newExtent = new esri.geometry.Extent();
newExtent.xmin = YourSinglePointX - 100;
newExtent.ymin = YourSinglePointY - 100;
newExtent.xmax = YourSinglePointX + 100;
newExtent.ymax = YourSinglePointY + 100;
newExtent.spatialReference = map.spatialReference;
map.setExtent(newExtent);

0 Kudos