Mapguide Open Source Development Series V: screen coordinates and map coordinates (problem) Modified

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.