##
Zoom and Pan
To actually chage the extents, we need a way to access the coordinates of the zoombox, panbox or click. So how do we get at these from within the callback functions? In "zoom1.html" we used the same callback functions for zoom and pan as for the command button that displayed the maps. There is a crucial difference, however, between callback functions for simple buttons and the ones for dragging. The latter are always called with five parameters: the four coordinates of the corners of the dragbox (in screen coordinates), and the window where the dragging started. This window has the inner variables contentLeft and contentTop, which give the screen coordinates of the top left corner of its frame. With these the zoom- or panbox can be computed in local window coordinates.
In
I wrote three new callback functions for zoom, pan and click. They just show an alert with the coordinates of the zoombox
, panbox
, and click
. A menu is used to assign zoom, drag or click to the windows. Note that the second parameter to the global... functions (the one that specifies which window should be made responsive to zooming, dragging or clicking) is not an individual window, but an array of windows. Many functions in MapClient can take as a parameter both an individual element and an array of elements. In this case, all three windows are made responsive to the specified dragging operation.
So the only thing that remains is translating these returned coordinates to a MapServer call to produce a new map. This happens in
. The functions "submitZoom()", "submitPan()" "submitZoomOut()" and "submitZoomAll()' compute the corners of the dragged area, and set the MapServer variables "imgext", "imgbox" and "imgxy". With these, MapServer can compute a new extent, based on the former extent and the specified image coordinates.
These operations are completely independent of window resizing.
Note especially that variables are really persistent, so after a zoom operation the "imgbox", "imgext" and "imgxy" variables have to be removed explictly. Without doing so, they would be sent again, and interfere with the next map request.
And finally, mark the generic function "submitwin()" that is called when all three windows are resized. All callback functions from windows are called with the window that triggered the callback as first parameter. That way, the generic function can address individual windows.