MapScript (centering a dynamic point layer)
Jerod Clabaugh
jclabaugh at MAC.COM
Thu Aug 5 15:36:58 PDT 2004
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