zooming at specific scale to a latlon point
Kevin Grootendorst
kgrootendorst at BAIRD.COM
Fri Feb 4 13:40:18 PST 2005
I'm having a similar problem to the one you posted a couple of months ago...
Did you happen to figure out how to get your map to center on the lat-long
point at all scales?
On Fri, 15 Oct 2004 18:13:51 -0400, Thomas Shaw <thomas at REDMILENIO.COM>
wrote:
>Hello, I'm developing an application with mapserver 4 / phpmapscript,and
>it does the following:
>
>A user introduce, lat lon values to an input textbox, and then that values
>are inserted in a MySQL DB, so I fetch that values from DB and the thing
>I'm doing, is to create a pointobj, with that lat lon. The reason why I
>need that pointobj, is for two things: 1.- I add that point in a new
>layer, to show it on the map, 2.- I want to make a zoomscale to that
>point, because I want that the point be zoomed to an initial scale. The
>first thing is already working good, but my problem is in the second. The
>way I do that is as follows:
>
>1.- Convert the latlon point to pixel
>2.- zoomscale introducing the latlon2pixel pointobj parameter
>
>
>mapscript code:
>
>dl('php_mapscript.so');
>
>
$map_path="/usr/local/mapserver_4/www/trackerweb/modules/Localiza/";
> $map_file="mexico.map";
> $map = ms_newMapObj($map_path.$map_file);
> $extminx = $map->extent->minx;
> $extminy = $map->extent->miny;
> $extmaxx = $map->extent->maxx;
> $extmaxy = $map->extent->maxy;
>////ZOOMSCALE
> $x = $longitud; // this is taken from database
> $y = $latitud; // this is taken from database
>
> $col = $map->width;
> $row = $map->height;
> $px = ( ($x-$extminx) * $col ) / ($extmaxx -
$extminx); //this converts
>from latlon to pix x
> $py = ( ($extmaxy-$y) * $row ) / ($extmaxy -
$extminy); //this converts
>from latlon to pix y
>
> $point2 = ms_newpointobj();
> $point2->setXY($px, $py);
> $extent1 = ms_newrectObj();
> $extent1->setextent(doubleval($extminx),doubleval
($extminy),
>doubleval($extmaxx), doubleval($extmaxy));
> $scale = '150000';
> $zoom1= $map->zoomscale($scale, $point2, $map->width, $map-
>height,
>$extent1);
>
>
>
>When I convert the latlon to pixel, it seems that they are well converted,
>because de zoomscale presents the point centered in the map, but it only
>happens in a 1:2000000 scale, but if I put a 1:90000 scale, the pointobj
>doesn't appears in the center of the map, and if I put a 1:5000 scale, the
>point just does not appears in the map.
>
>When I convert latlon to pixel, it results (x,y) pixel values with 6
>decimal each one and with that values, I create a pointobj point and use
>it as a parameter of the zoomscale method, but I think that the zoomscale
>takes only the integer value of the (x,y) pixel values, and that's why it
>has an error that at a 1:5000 scale is greater because at that scale the
>extent is at a nearest to the point. That's because at a 1:2000000 scale
>the error apparently does not appears. So I hope that I was clear enogh
>with my explanation, and also hope that someone can help me to solve that
>error.
>
>Thanks in advance
>
>Tom Shaw
More information about the MapServer-users
mailing list