Hi
I'm using the PrintingTools - ExportWebMap REST API to get images of a map. As a parameter I get longitude and latitude (East/North) coordinates, which represent the center of the map, which should be printed.
How can I calculate the mapOtions -> extent: xmin, ymin, xmax, ymax from the given coordinates.
{
mapOptions": {
"showAttribution": true,
"extent": {
"Xmin": 2599500.000,
"Ymin": 1199700.000,
"Xmax": 2600500.000,
"Ymax": 1200300.000,
"spatialReference": {
"wkid": 2056
}
},
[....]
I tried two different approaches.
The first approach is a a simple linear interpolation, where offsetEastInMeters and offsetNorthInMeters
var xmin = coordinates.East - (offsetEastInMeters / 2);
var ymin = coordinates.North - (offsetNorthInMeters / 2);
var xmax = coordinates.East + (offsetEastInMeters / 2);
var ymax = coordinates.North + (offsetNorthInMeters / 2);
Example I:
East/North: 2600000.000, 1200000.000
offsetEastInMeters: 1000 meters
offsetNorthInMeters: 600 meters
Results in:
xmin = 2599500.000
ymin = 1199700.000
xmax = 2600500.000
Ymax = 1200300.000
The second approach also takes into consideration the output size of the image, dpi and the scale:
image_length[mm] = pixel * 25.4mm (1 in) / dpi
xmin = x_coord - (image_length/1000 * scale)/2
This result in:
xmin = 2599365
ymin= 1199700
xmax = 2600635
ymax = 1200300
The issue with both approaches is, that the center of the returned image is not in the middle of the given longitude and latitude (East/North) coordinates. The given point is always on the left side. See the issue illustrated in the following picture:
How ist the calculation from a point to an area done right? What did I forget?
Tank you for any help!