# Off Center Zoom

1846
6
12-19-2014 07:42 AM
by
New Contributor II

I am trying to determine the best way to off center a zoom based on browser window size.  I have a div container nested within my map div on the right side which takes up 20% of the screen.  I would like to off center the map.centerAt() function 20% to the left to compensate for this taken space.  Does anyone have an idea on the best way of going about this?  Any suggestions are greatly appreciated.  Thanks in advance.

1 Solution

Accepted Solutions
Esri Contributor

Convert the point you want to center on to a screen point, this will give you the coordinates in pixel space. Then substract/add 0.2*map.width from the X value and convert the point back to map units and use that to center on. Makes sense?

6 Replies
Esri Contributor

Convert the point you want to center on to a screen point, this will give you the coordinates in pixel space. Then substract/add 0.2*map.width from the X value and convert the point back to map units and use that to center on. Makes sense?

Esri Contributor

You can also skip the unit conversion and use 0.2*map.extent.getWidth()...

by
New Contributor II

Thanks, worked perfectly for my point features.  Would a similar method be used for polygons?

Esri Contributor

to do what? map.centerAt only works with points...

by
New Contributor II

I would like to off center my polygon features the same way.  Currently I am using :  map.setExtent(polygonFeatureLayer.geometry.getExtent().expand(1.1));  Would I simply do the same for the x coordinate for the polygon and recalculate the extent?

Esri Contributor

Yeah, you would do it the same way; loop over all vertices in the polygon and offset the X.