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.
Solved! Go to Solution.
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?
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?
You can also skip the unit conversion and use 0.2*map.extent.getWidth()...
Thanks, worked perfectly for my point features. Would a similar method be used for polygons?
to do what? map.centerAt only works with points...
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?
Yeah, you would do it the same way; loop over all vertices in the polygon and offset the X.