Problems drawing polygons
Julien Bessiere
julien.63 at FREE.FR
Thu Jul 13 08:35:43 PDT 2006
Hi Matt,
That works fine.
thank you very much.
here below is the function.
Julien
//=========================================
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);
$style = ms_newStyleObj($class);
$style->set('symbolname',"circle");
$style->set('size',10);
$style->color->setRGB(255,255,0);
$style->outlinecolor->setRGB(255,255,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);
}
//-------------------------------------------------------
// add the first point again to close the polygon ------
//-------------------------------------------------------
if (count($polygon_coordinates) > 2){
$point = ms_newPointObj();
$x = $polygon_coordinates[0][0];
$y = $polygon_coordinates[0][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();
}
//===============================================================
Selon Matt Brown <mbrown at al1call.com>:
> Julien,
>
> try adding the first point again(to the end), to close the polygon. so for
> a 4 point polygon, you will have five pairs of coordinates in your array.
>
> Matt
>
>
>
> -----Original Message-----
> From: UMN MapServer Users List [mailto:MAPSERVER-USERS at LISTS.UMN.EDU]On
> Behalf Of Julien Bessiere
> Sent: Wednesday, July 12, 2006 2:47 PM
> To: MAPSERVER-USERS at LISTS.UMN.EDU
> Subject: [UMN_MAPSERVER-USERS] Problems drawing polygons
>
>
> 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