Pan to polygon - keep current extent

Discussion created by a.schaefer-esri-de-esridist on Jul 14, 2011
Latest reply on Jul 14, 2011 by a.schaefer-esri-de-esridist

maybe my question is piece of cake but I don't know a nice solution. I hope you can help.

I have a polygon graphic from a find-result and I want to pan to the location. I want to keep the current scale of the map (even if you can hardly see the polygon in the map).

The standard examples shows how to zoom to the polygon by


This changes the current scale of the map to the scale where the polygon fits.

I want to keep the current scale. My solution right now changes the scale afterwards to the previous scale. Like this:

var scale = esri.geometry.getScale(map);

// Wait until the extent change has completed
var tempHook = dojo.connect(map, "onUpdateEnd", function() {
  map.setExtent(esri.geometry.getExtentForScale(map, scale));
  // Dispose of the temporary listener

The disadvantage is: I have to create a temp-hook waiting for the map-update of my first zoom to the polygon. After that I change the extent back to the previous one (var scale). Two map requests and responses. And it looks grumpy because the map changes two times (zoom-in, zoom-out).

Is there a way to "pan" to the polygon directly? I don't know why I can't find it. There must be a way, I guess...