[mapserver-users] perl - zooming, panning, and such
Puneet Kishor
pkishor at GeoAnalytics.com
Fri Apr 19 15:24:30 PDT 2002
[cc-ing to the list for archival purposes]
> that's pretty much what i thought the process was. what i
> don't know from
> here is how do i actually apply the zoom factor/pan to the old extent
> and create the desired new extent. and how do i do that in
> relation to
> the mouse coordinates that were clicked on?
I did leave out some of the details from my explanation. Here is a more
detailed explanation. I am using PHP methods here, but they should be very
similar to the Perl methods... compare the docs, or better yet, parse
through the mapquakes.pl SDL sent you.
1. everytime you draw the map, you need to set the mapextent.
2. if you are doing this for the very first time, you would usually start
with the maximum extent of your map. otherwise, you would start with the
current extent of the map. The best way to determine that is to use sessions
(something like Session.pm on Perl should do the trick). Else, you could
set/get cookies or some http_var to the same effect. Using sessions,
assuming $maxextent is a session array
if(!isset($maxextent) ) {
$curextent[minx] = $mapObj->extent->minx; // array to hold the curextent
$curextent[miny] = $mapObj->extent->miny;
$curextent[maxx] = $mapObj->extent->maxx;
$curextent[maxy] = $mapObj->extent->maxy;
$maxextent = $curextent; // copy curextent to maxextent
// set the mapObj to the current extent
$mapObj->setextent($curextent[minx],
$curextent[miny],
$curextent[maxx],
$curextent[maxy]);
}
// if form variables are defined...
// $maxextent is set, so this is a return view.
// set the curextent using the values received from
// the form variables
if(isset($minx)) {
$curextent[minx] = $minx;
$curextent[miny] = $miny;
$curextent[maxx] = $maxx;
$curextent[maxy] = $maxy;
}
// set the mapObj to the current extent
$mapObj->setextent($curextent[minx],
$curextent[miny],
$curextent[maxx],
$curextent[maxy]);
// create a rectObj with curextent
$curExtObj = ms_newRectObj();
3. now you can do whatever else you want to do to the map... zoomin,
zoomout, pan, etc. for example, if you wanted to zoom in using a zoomfactor
of 3 you would use the following code
// create a point object at the point of click
// point of click is usually returned by the browser
// keep in mind, the x,y are in screen pixel coords
// you have to create a point using geog coords, so
// apply the requisite transformation
$pointObj = getMouseClick($x, $y);
// now set new extent using the zoompoint method
$mapObj->zoompoint(3, $pointObj, $map_width, $map_height, $curExtObj);
// now draw the map
$imgObj = $mapObj->draw();
$imgUrl = $imgObj->saveWebImage(MS_PNG, 0, 0, -1);
make sure when you send the above image back to the user that you send the
bounding box (minx, miny, maxx, maxy) as hidden form fields so you can reuse
them the next time.
3. so, let's reiterate... the first time is easy because you start with the
maxextents. at that point in time, you send the current extent (which
happens to be maxextents right now) to the client. you usually do that as
hidden form fields.
4. now the map is sitting on the client. the user chooses to zoomin. the act
of zooming in sends back to the server the point-of-click of zoomin, a
(usually) preset zoomfactor, and the current extents that were in the hidden
fields.
5. back at the server, you now start with these current extents and apply
the zoomfactor to get the new current extents. and the process continues...
this should get you going. As I said, the Perl logic will be similar (in
fact, any scripting logic will be similar... the syntax is all documented).
Hth.
pk/
More information about the MapServer-users
mailing list