Problems drawing polygons

Matt Brown mbrown at AL1CALL.COM
Wed Jul 12 15:39:36 EDT 2006


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