[mapserver-users] Drawing features dynamically
E Perik
erwin at perik.nu
Mon Mar 18 17:42:19 PST 2002
Hi Ricardo,
Seems like a popular subject ;-)
I used 2 'dummy map-layers' set to OFF by default, and added point en
rectangle to those 2 layers.
The two 'dummy' layers are named:
$query + Rectangle
$query + Point
*** PHP code:
// Open the map
$HighLightMap = ms_newMapObj("YOUR.map"); //<-- modify !!!
// 2 'New' layers:
// $shape_layer = for rectangle
// $pt_layer = for point
// 'Create' the layers and turn them ON
$shape_layer = ms_newLayerObj($HighLightMap);
$shape_layer = $HighLightMap->getLayerByName($qlayer . "Rectangle");
$shape_layer->set("status", 1);
$pt_layer = ms_newLayerObj($HighLightMap);
$pt_layer = $HighLightMap->getLayerByName($qlayer . "Point");
$pt_layer->set("status", 1);
// create point object
$pt = ms_newPointObj();
$pt->setXY($YourYcoord, $YourYcoord); //<-- modify !!!
// create line objects
$ln[0] = ms_newLineObj();
$ln[1] = ms_newLineObj();
$ln[2] = ms_newLineObj();
$ln[3] = ms_newLineObj();
// Rectangle factor
$RectangleFactor = 20; //<-- modify !!!
// Determine lines of rectangle
$ln[0]->addXY( ($pt->x - $RectangleFactor), ($pt->y - $RectangleFactor)
);
$ln[0]->addXY( ($pt->x + $RectangleFactor), ($pt->y - $RectangleFactor)
);
$ln[1]->addXY( ($pt->x + $RectangleFactor), ($pt->y - $RectangleFactor)
);
$ln[1]->addXY( ($pt->x + $RectangleFactor), ($pt->y + $RectangleFactor)
);
$ln[2]->addXY( ($pt->x + $RectangleFactor), ($pt->y + $RectangleFactor)
);
$ln[2]->addXY( ($pt->x - $RectangleFactor), ($pt->y + $RectangleFactor)
);
$ln[3]->addXY( ($pt->x - $RectangleFactor), ($pt->y + $RectangleFactor)
);
$ln[3]->addXY( ($pt->x - $RectangleFactor), ($pt->y - $RectangleFactor)
);
// create shape objects
$shp = ms_newShapeObj(MS_SHAPE_POLYGON);
$shp->add($ln[0]);
$shp->add($ln[1]);
$shp->add($ln[2]);
$shp->add($ln[3]);
// draw rectangle-shape on the dummy-layers
$shp->draw($HighLightMap, $shape_layer, $ImgHighLight, 0, "TEST");
// draw point-object on layers
$pt->draw($HighLightMap, $pt_layer, $ImgHighLight, 0, "TEST");
// Save image
$UrlHighLight = $ImgHighLight->saveWebImage($ImgHighLight, 0, 0, -1);
*** The 2 'dummy' MAP-layers:
LAYER
NAME "parkRectangle" # For showing rectangle
TYPE LINE
STATUS OFF
CLASS
NAME "parkQuery"
SYMBOL 'circle'
COLOR 0 0 0
SIZE 3
END
END # Layer
LAYER
NAME "parkPoint" # For showing 'point'
TYPE POINT
STATUS OFF
CLASS
SYMBOL 'circle'
END
END # Layer
Polygons could be done too, just slight modifications in above code.
Erwin
-----Original Message-----
From: owner-mapserver-users at lists.gis.umn.edu
[mailto:owner-mapserver-users at lists.gis.umn.edu] On Behalf Of Ricardo
Scachetti Pereira
Sent: Monday, March 18, 2002 7:57 PM
To: mapserver-users at lists.gis.umn.edu
Subject: [mapserver-users] Drawing features dynamically
Does anyone know how to draw features (points, lines and polygons)
dynamically over a base map using Perl or PHP mapscript?
I would like to draw data points coming from disparate (remote) data
sources, which are providing data as a XML documents. Each document can
contain a large number of features (thousands). I would like to avoid
writing individual shapefiles for each dataset, just to display them. I
would like to know if mapserver has any built in mechanism to display
dynamic features, besides the one described on the CGI documentation
(which is designed to handle small amounts of data).
I've been exploring the pointObj and its methods (especially the
draw() method), because it seems to be developed to implement the kind
of feature I'm looking for. However, I couldn't write anything that does
what I want. Mostly, I get segmentation fault errors. Does anyone know
any sample scripts that draw points using this object?
Ricardo
--
Ricardo Scachetti Pereira
Gerente de Pesquisa
Centro de Referência em Informação Ambiental - CRIA
http://www.cria.org.br/
More information about the MapServer-users
mailing list