Drawing points and lines dynamically
Camden Daily
cdaily at GMAIL.COM
Fri Apr 15 07:05:42 PDT 2005
If you turn off all of the other layers, can you see the point then?
It might be a matter of extents or projections. Are your extents in
latitude/longitude degrees as well?
> One thing that I am confused about is to whether or not the layer that I
> want to create the point
> on has to be already defined in the map file or whether the code below
> actually creates a 'dynamic'
> layer.
It creates a dynamic layer. You do not need to pre-define the layer
in the .map file. Althought I've not actually tried it, I believe
that you could make your entire .map file definition through
mapscript.
I'm not sure why else the point might not show up, but I would suggest
looking at the layer->addFeature() function. I think it's much more
straightforward than drawing the map, and then calling point->draw()
over it. Just do something like this to add a point to a layer:
function add_point_to_layer($layer, $longitude, $latitude) {
// create and initialize new point object
$point = ms_newPointObj();
$point->setXY($longitude, $latitude);
// create and initialize new line object
$line = ms_newLineObj();
$line->add($point);
// create and initialize new shape object
$shape = ms_newShapeObj(MS_SHAPE_POINT);
$shape->add($line);
// add our shape
$layer->addFeature($shape);
}
Then, once you've added the points, just call $image = $map->draw();
and everything should draw nicely.
-Camden
> regards
> Simon
>
> $layer = ms_newLayerObj($map);
> $layer->set("name", "Route");
> $layer->set("type", MS_LAYER_POINT);
> $layer->set("status", MS_DEFAULT);
> $layer->set("transform", TRUE);
>
> $class = ms_newClassObj($layer);
> $class->label->set("font", "arial");
> $class->label->color->setRGB(255, 0, 0);
>
> $symbol = $map->getSymbolByName("circle");
> $style = ms_newStyleObj($class);
> $style->set("symbol", $symbol);
> $style->set("size", 8);
> $style->color->setRGB(255, 0, 0);
>
> $image = $map->draw();
>
> $point = ms_newPointObj();
> $point->setXY(0.0, 54.0);
> $point->draw($map, $layer, $image, 0, "test");
> $image_url=$image->saveWebImage();
> --
> No virus found in this outgoing message.
> Checked by AVG Anti-Virus.
> Version: 7.0.308 / Virus Database: 266.9.11 - Release Date: 14/04/2005
>
More information about the MapServer-users
mailing list