Pan map by pixel (offset map centering)

2656
4
Jump to solution
02-24-2014 01:04 AM
MartinSirkovsky
Occasional Contributor
I would like to offset the map recentering by x number of pixels. How can I do this.

map.centerAt(point) - The argument takes a coordinates. However I would like to move the center 50 px to the left from real center.

I guess I could calculate the resolution of the pixel based on the current map scale and than calculate the distance I need to move the map. But I am wondering if there is a simpler way of panning the map by defining number of pixels, rather than the coordinates at which to center.

Thanks,
Martin
0 Kudos
1 Solution

Accepted Solutions
MartinSirkovsky
Occasional Contributor
Thanks for the tip. I investigating further after I posted my question and that is what I used.

Here is my code, using Jquery selectors:

// Get width of map div  var mapDivWidth = $("#mapDiv").width();  // Get width of the div which is partialy obscuring the mapDiv var tableListWidth = $("#propertyList").width();  // Get the min and max X coordinate of the current map  var minX = map.toMap(esri.geometry.ScreenPoint(0,0)); var maxX = map.toMap(esri.geometry.ScreenPoint((mapDivWidth-1),0));  // Calculate the current pixel resolution var pointResolution = (maxX.x - minX.x)/mapDivWidth;   // Get the correct map center var currentMapCenter = (mapDivWidth - tableListWidth) / 2;  // Get the wished offset in coordinate system units offset = ((mapDivWidth / 2) - currentMapCenter) * pointResolution;  //...... follows the code where I apply the offset

View solution in original post

0 Kudos
4 Replies
RobertoPepato
Occasional Contributor II
I would like to offset the map recentering by x number of pixels. How can I do this.

map.centerAt(point) - The argument takes a coordinates. However I would like to move the center 50 px to the left from real center.

I guess I could calculate the resolution of the pixel based on the current map scale and than calculate the distance I need to move the map. But I am wondering if there is a simpler way of panning the map by defining number of pixels, rather than the coordinates at which to center.

Thanks,
Martin


Hi Martin,

Take a look at the screenUtils class. By using this class you can convert your point to ScreenPoint, offset it the way you like and convert it back to MapPoint.

Let me know if it helps.
0 Kudos
MartinSirkovsky
Occasional Contributor
Thanks for the tip. I investigating further after I posted my question and that is what I used.

Here is my code, using Jquery selectors:

// Get width of map div  var mapDivWidth = $("#mapDiv").width();  // Get width of the div which is partialy obscuring the mapDiv var tableListWidth = $("#propertyList").width();  // Get the min and max X coordinate of the current map  var minX = map.toMap(esri.geometry.ScreenPoint(0,0)); var maxX = map.toMap(esri.geometry.ScreenPoint((mapDivWidth-1),0));  // Calculate the current pixel resolution var pointResolution = (maxX.x - minX.x)/mapDivWidth;   // Get the correct map center var currentMapCenter = (mapDivWidth - tableListWidth) / 2;  // Get the wished offset in coordinate system units offset = ((mapDivWidth / 2) - currentMapCenter) * pointResolution;  //...... follows the code where I apply the offset
0 Kudos
KenBuja
MVP Esteemed Contributor
Martin, you should mark your own post as the answer to help others who might have this same question.
0 Kudos
RyannGalea
New Contributor II

Here is a similar question & answer that is relevant here.

Is there a way to animate a padding change? 

0 Kudos