Mapguide OS's map Frame Methods provides screentomapunits for converting screen coordinates to map coordinates.
The API documentation is as follows:
Screentomapunits (x, y)
Converts a position expressed in pixels (screen units) to one expressed in map units, returning
Point Object:
Point {X; y ;}
Parameters:
X-The X coordinate, expressed in pixels.
Y-The Y coordinate, expressed in pixels.
See also:Getmapunitstype ()
However, MOS does not provide the correspondingMapunitstoScreen(X, y ). I don't know why?
What method should I use if I write it myself?
If we use the numerical calculation method, we can gradually approach it. However, this is too complicated and the performance is not good.
Can I directly perform linear interpolation?
Step1. calculate the X-pixel, Y-pixel,
Step 2: UseScreentomapunitsTo obtain X-map and Y-map.
Step 3: Perform linear interpolation based on the preceding two points in proportion.
Because it only involves the coordinates of a single screen and a single map, there should be no big error.
I checked JS again.Source codeThe following sources are found in the viewerfiles directory:Code
Function screentomapunits (x, y)
{
If (x> mapdevw-1)
X = mapdevw-1;
Else if (x <0)
X = "" 0 "";
If (y = ""> mapdevh-1)
Y = mapdevh-1;
Else if (Y <0)
Y = "" 0 "";
X = "" extx1 "+ (extx2 =" "-=" "extx1 =" ") * (x =" "/mapdevw );
Y = exty1-(exty1-exty2) * (y/mapdevh );
Return new point (x, y );
}
This shows that this function is a linear interpolation. Therefore, we can use this function in turn.