Problems drawing polygons
Julien Bessiere
julien.63 at FREE.FR
Wed Jul 12 12:47:20 PDT 2006
Hi,
I'm using a function to draw a polygon on my maps.
The user clicks wherever he wants and i store the coordinates in a php array and
pass the array to the function.
My problem is that the first point doesn't appear in my polygon.
For example, if i have 4 points, my polygon will be a triangle with the second,
the third and the fourth point.
My array is something like :
Array
(
[0] => Array
(
[0] => -80.4178572857
[1] => 9.310714794
)
[1] => Array
(
[0] => -79.4750001429
[1] => 9.69642909
)
[2] => Array
(
[0] => -79.0785715714
[1] => 9.0000005
)
[3] => Array
(
[0] => -80.0428572857
[1] => 8.442857628
)
)
And here is my function :
function drawPolygon($map,$polygon_coordinates){
$layer = ms_newLayerObj($map);
$layer->set("name","polygon");
$layer->set("status",MS_DEFAULT);
if (count($polygon_coordinates) < 3)
$layer->set("type",MS_POINT);
else
$layer->set("type",MS_LAYER_POLYGON);
$class = ms_newClassObj($layer);
$class->label->set("type",MS_BITMAP);
$stylepoint = ms_newStyleObj($class);
$stylepoint->set('symbolname',"circle");
$stylepoint->set('size',10);
$stylepoint->color->setRGB(200,200,0);
$line = ms_newLineObj();
foreach ($polygon_coordinates as $record){
$point = ms_newPointObj();
$x = $record[0];
$y = $record[1];
$point->setXY($x,$y);
$line->add($point);
}
$shape = ms_newShapeObj(MS_SHAPE_POLYGON);
$shape->set("classindex", 0);
$shape->add($line);
$shape->set("text","MYpolygon");
$layer->addFeature($shape);
$point->free();
$shape->free();
}
thanks in advance for your help
Julien
More information about the MapServer-users
mailing list