Solved! Go to Solution.
// 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
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
// 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
Here is a similar question & answer that is relevant here.