zooming at specific scale to a latlon point

Thomas Shaw thomas at REDMILENIO.COM
Fri Oct 15 18:13:51 EDT 2004


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