I need to draw a map .I have the latitude longitude values of it .I was able to map these to screen coordinates and then draw the map.Once the map is drawn,as the mouse moves over the map i need to show the latitude and longitude values. This is where i am struck .For the initial case its simple,just rearrangement of window to view port mapping formula .i.e.,
u = (x-xmin)* sx+ umin
v = (y-ymin)* sy + vmin
But once the zoom and pan operations are applied on the map, I dont know how to get the latitude longitude values for each screen coordinate .
If some one knows how to solve this ,Please help me
Thanks in advance
| Xs | = |eM11 0 | |X| + |eDx|
| Ys | |0 eM22| |Y| |eDy|
(Xs,Ys) are screen coordinates, (X,Y) are window/world coordinates.
This transform represents scaling in x (given by eM11), scaling in y (given by eM22) and translation (given by eDx and eDy). Scaling = zoom (eM11 and eM22 will always have the same value), translation = pan.
So, when you zoom, if the structure which represents the transform is called m_TWorld2Screen, you have to update eM11 and eM22, but also eDx and eDy, since the translation is affected by zoom (it's not the same distance):
m_TWorld2Screen.eM11 = newVal;
m_TWorld2Screen.eM22 = newVal;
m_TWorld2Screen.eDx = (m_TWorld2Screen - m_iWidth/2.0f) * newVal / oldZoomFactor + m_iWidth/2.0f;
m_TWorld2Screen.eDy = (m_TWorld2Screen.eDy- m_iHeight/2.0f) * newVal / oldZoomFactor + m_iHeight/2.0f;
-newVal is the new zoom factor (between 0 and 1)
-m_iWidth and m_iHeight are the viewport's dimensions
-oldZoomFactor is the previous zoom factor
And when you pan, you only need to update eDx and eDy:
m_TWorld2Screen.eDx = - m_TWorld2Screen.eDx / m_TWorld2Screen.eM11;
m_TWorld2Screen.eDy = - m_TWorld2Screen.eDy / m_TWorld2Screen.eM22;
The proof of these formulas is quite tedious to write without LaTeX, but this works for me.
You might need to define m_TScreen2World to do the inverse transform. If you understood my concept, ask away