Zoom to Point...

511
4
11-09-2011 08:50 AM
GISAdmin1
New Contributor III
Is this still the method to zoom to a point using the ESRI Javascript API?

 var PointExtent = new esri.geometry.Extent();
 PointExtent.xmin = selectedAddress.geometry.x - .001;
 PointExtent.ymin = selectedAddress.geometry.y - .001;
 PointExtent.xmax = selectedAddress.geometry.x + .001;
 PointExtent.ymax = selectedAddress.geometry.y + .001;
 map.setExtent(PointExtent);


Or, is there a new method?

Thanks in advance,

M
0 Kudos
4 Replies
JeffPace
MVP Alum
Is this still the method to zoom to a point using the ESRI Javascript API?

 var PointExtent = new esri.geometry.Extent();
 PointExtent.xmin = selectedAddress.geometry.x - .001;
 PointExtent.ymin = selectedAddress.geometry.y - .001;
 PointExtent.xmax = selectedAddress.geometry.x + .001;
 PointExtent.ymax = selectedAddress.geometry.y + .001;
 map.setExtent(PointExtent);


Or, is there a new method?

Thanks in advance,

M


Since its a point, I prefer

map.centerAndZoom(selectedAddress.geometry,19); // 19 or whatever zoom scale you prefer.
0 Kudos
Mete_ErcanPakdil1
New Contributor III
Since its a point, I prefer

map.centerAndZoom(selectedAddress.geometry,19); // 19 or whatever zoom scale you prefer.


Jeff, I don't agree with you since it zooms more than current every time when it is called by user.
0 Kudos
JeffPace
MVP Alum
Jeff, I don't agree with you since it zooms more than current every time when it is called by user.


Well since by default a point does not have an extent, you have to assume one.  If you want to stay at the current, you are not zooming, you are panning, in which case just call map.centerAt(pt).
0 Kudos
derekswingley1
Frequent Contributor
Another option is to calculate a new extent from the map's current extent and use that to zoom. It's similar to the original code that was posted in this thread but instead of using a hard coded value, the value used to pad the point is calculated on the fly. Something like this:
var tolerance = 5,
    pxWidth = map.extent.getWidth() / map.width,
    padding = tolerance * pxWidth,
    newExtent = new esri.geometry.Extent({
      'xmin': evt.mapPoint.x - padding,
      'ymin': evt.mapPoint.y - padding,
      'xmax': evt.mapPoint.x + padding,
      'ymax': evt.mapPoint.y + padding,
      'spatialReference': evt.mapPoint.spatialReference
    });
map.setExtent(newExtent);
0 Kudos