Zooming and Centering Question: Second Run
Bob Bruce
covariance at SHAW.CA
Mon Apr 25 14:44:01 PDT 2005
On Sun, 24 Apr 2005 23:01:06 -0400, Giridhar Manepalli <gmanepal at GMAIL.COM>
wrote:
>Hello All,
>I am using php mapscript. I cannot get the image to center when I
>click on the image and with some zooming factor.
>
>I am using image coordinates (not geographical coordinates) for zooming.
>
>1.)Can anyone think of possible reasons? I can provide with any
>necessary information.
>
>2.) Also, how do I center the image based on my click without zooming?
>
>3.) Finally, does the extent of the map automatically changed by
>mapscript, when I zoom?
>
>I hope, i can get this resolved!
>
>Thanks,
>Giridhar
>
>
>Hello All,
>I tried to center the image based on a click when I zoom using
>php/mapscript. For some reason, I am failing to do so.
>
>Is it because, the lat long I calculated using javascript is wrong?
>but it almost matches with 'ArcIMS Author'.?
>
>Can anyone write the snippet of php/mapscript code that will zoom to
>the point i click, provided I have the lat-long of the click? Also,
>can you explain what the new extent will be?
>
>Thanks,
>Giridhar
Giridhar:
here's a code snippet that I use for zooming in:
} elseif($_POST['mode'] == "ZoomInAtPT" ) {
$new_point = ms_newPointObj();
$new_point->setXY(floatval($_POST['mapimage_x']),floatval($_POST['mapimage_y']));
$map->zoomscale($mapscale/$mapScaleZoomFactor, $new_point,
$map->width, $map->width,
$mapRect, $maxmapRect);
the post variables are the image coordinates of the mouse click. You should
have those anyway and it shouldn't be necessary to convert them to Lat/Long.
I get $mapscale using the statement:
$mapscale = isset($_POST['mapscale']) ? floatval($_POST['mapscale']) :
$maxscale;
and I set the post value of mapscale using the following statements:
// now set up some web page display values
$currentscale = round($map->scale);
$char_scale = number_format($currentscale);
and this is my code to re-center the draw:
} elseif($_POST['mode'] == "recenter" ) {
$new_point = ms_newPointObj();
$new_point->setXY(floatval($_POST['mapimage_x']),floatval($_POST['mapimage_y']));
$map->zoomscale($mapscale, $new_point, $map->width, $map->width,
$mapRect, $maxmapRect);
(notice that I don't change the scale in this call)
and this is the code to set the last two values of the above call:
if(isset($_POST['mapextent'])) {
$extents = explode("+",$_POST['mapextent']);
$mapRect = ms_newRectObj();
$mapRect->setextent(floatval($extents[0]),floatval($extents[1]),floatval($extents[2]),floatval($extents[3]));
$maxmapextent = $_POST['maxmapextent']; // save this for the hidden
form variable
} else { // set this for the hidden form variable using the values
from the map file
$maxmapextent = $map->extent->minx . "+" . $map->extent->miny . "+"
. $map->extent->maxx . "+" . $map->extent->maxy;
}
if(isset($_POST['maxmapextent'])) {
$maxextents = explode("+",$_POST['maxmapextent']);
$maxmapRect = ms_newRectObj();
$maxmapRect->setextent(floatval($maxextents[0]),floatval($maxextents[1]),floatval($maxextents[2]),floatval($maxextents[3]));
}
hopefully there is enough here to get you going.
Bob Bruce
More information about the MapServer-users
mailing list