PHPMAPSCRITP Drawing a POINT !!!
Robert Albrecht
robert.albrecht at TKK.FI
Thu Mar 16 06:46:58 PST 2006
Alessandro MAZZELLA wrote:
> Hi everybody,
>
> is it possible to draw a point (or a cross !!) over the mouseclick
> point ? Any idea ?
>
I use the following function to get the coordinates of a click on the map:
public function pixelsToCoordinates($x, $y, $width, $height, $extent)
{
$dx = $x / $width;
$dy = 1 - $y / $height;
$x_georef = $extent->minx + ($extent->maxx - $extent->minx) * $dx;
$y_georef = $extent->miny + ($extent->maxy - $extent->miny) * $dy;
$point = ms_newPointObj();
$point->setXY($x_georef, $y_georef);
return $point;
}
$x, $y is the point clicked on the image map, in pixels, from the top
left corner.
$width, $height is the size of the image map.
$extent is the georeferenced extents of the image map.
To draw points you need to create a point layer:
$point_layer = ms_newLayerObj($mapObj);
$point_layer->set("status", MS_ON);
$point_layer->set("type", MS_LAYER_POINT);
$point_layer->set("transparency", MS_GD_ALPHA);
$class = ms_newClassObj($point_layer);
$class->set("status", MS_ON);
$style = ms_newStyleObj($class);
$style->set("symbolname", "/path/of/the/symbol/you/want/to/draw.gif");
and add the point:
$point = ms_newPointObj();
$point->setXY($x, $y);
$line = ms_newLineObj();
$line->add($point);
$shape = ms_newShapeObj(MS_SHAPE_POINT);
$shape->set("classindex", 0);
$shape->add($line);
$point_layer->addFeature($shape);
It's a bit complicated, but I don't know any easier way to do it.
Regards,
Robert Albrecht
More information about the MapServer-users
mailing list