Off Center Zoom

2357
6
Jump to solution
12-19-2014 07:42 AM
WesAskew
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.

0 Kudos
1 Solution

Accepted Solutions
HeikoHeijenga
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?

View solution in original post

6 Replies
HeikoHeijenga
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?

HeikoHeijenga
Esri Contributor

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

0 Kudos
WesAskew
New Contributor II

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

0 Kudos
HeikoHeijenga
Esri Contributor

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

0 Kudos
WesAskew
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?

0 Kudos
HeikoHeijenga
Esri Contributor

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

0 Kudos