MapScript (centering a dynamic point layer)

Steven Monai stevem at SPATIALMAPPING.COM
Fri Aug 6 11:37:42 EDT 2004


Jerod:

Check out the mapObj->setextent() method, here:
http://mapserver.gis.umn.edu/doc42/phpmapscript-class-guide.html#MapObj

(you'll have to scroll down the page a bit to find it).

My suggestion: What you'll want to do is to get the minimum and maximum x
and y coordinates from your set of points, call the setextent() method with
those values, and then, finally, call the draw() methods to draw the map.

A PHP implementation is left as an exercise for the reader, but the code
below looks like a good starting point.

Hope this helps,
-SM
--


On Thu, 5 Aug 2004 17:36:58 -0500, Jerod Clabaugh <jclabaugh at MAC.COM> wrote:

>Hi:
>
>I am just working my into the PHP/Mpascript world so bear with me.
>
>I am working to show a list of information about a biological
>specimen, displaying the locality of the specimen as a point on a
>small map.
>
>I can generate such a small map on-the fly by generating a dynamic
>point layer pulling UTM coordinates from PostgreSQL/PostGIS db (with
>dummy point layer in map file). No problems so far.
>
>My problem is that some species aren't showing up on these maps b/c
>they are not in the 'frame' (further south or north of the area of
>the map being drawn).  I need to readjust the map to center on the
>point being drawn.
>
>I know that this likely requires adjusting the extents and using the
>zoompoint method, but other than that I'm lost.
>
>[Specs: Mapserver 4.2.2, PHP 4.3.7 CGI, Apache2, PostgreSQL 7.4.2
>with PostGIS 0.81; all functional.]
>
>I have looked online and at the mapscript wiki but all the examples I
>find are trying to capture a user's click on a ma and my attempts to
>modify that code have failed.  Any help you can give me is much
>appreciated.
>
>Cheers,
>
>Jerod Clabaugh
>
>=-=-=PHP CODE=-=-=
>
>        //load Mapscript
>        dl('php_mapscript.so');
>
>        // generate and execute the query
>        $connection = pg_connect("user=xxxx dbname=xxxx host=localhost");
>        $query = "SELECT data_specimen.easting,
>data_specimen.northing from data_specimen WHERE
>                data_specimen.specimen_id = '$dcid'";
>        $result = pg_exec($connection, $query);
>
>
>        // get the number of rows in the resultset
>        $rows = pg_numrows($result);
>
>        // MapObj and ImageObj settings
>        $map_path="/Library/Apache2/htdocs/demo1.map";
>        $map = ms_newMapObj($map_path);
>        $img = $map->draw();
>
>        //get dummy point layer
>        $layer = $map->getLayerByName("species");
>
>        ///turn dummy point layer status to ON
>        $layer->set('status', MS_ON);
>
>                //loop through resultset, generating the points
>        for ($i=0; $i<$rows; ++$i) {
>        $row = pg_fetch_row($result, $i);
>        $pt = ms_newPointObj();
>        $pt->setXY($row[0],$row[1]);
>        $pt->draw($map, $layer, $img, 0, "TEST");
>        }
>
>        //create map image
>         $img_url=$img->saveWebImage(MS_PNG,1,1,0);
>
>        // close database connection
>        pg_close($connection);
>
>=-=-=HTML CODE =-=-=
>
><img src="<?php echo $img_url?>" border="1">
>
>
>=-=-=MAP FILE DUMMY POINT LAYER=-=-=
>LAYER
>  NAME species
>   TYPE POINT
>   STATUS OFF
>   CLASS
>   COLOR 255 255 0
>   OUTLINECOLOR 0 0 0
>   SYMBOL 'triangle'
>   SIZE 8
>  END
>END



More information about the mapserver-users mailing list