[mapserver-users] changing the color of a line

Andy Colson andy at squeakycode.net
Thu Feb 18 11:52:38 PST 2010


On 2/18/2010 1:35 PM, ahmet temiz wrote:
> hello
>
> how can I change the color of a line programmatically in mapscript environment
> (preferably in java)
>
> regards

I think we need a little more info.  Is this line inside a layer... of 
type LINE?  Is the layer type POLYGON and you want to change one line of 
one polygon?  Is the line the only thing in the layer?  If there are 
lots of lines in the layer, do you know how to find the one you want?

As an example, which may not be helpful... I have perl mapscript that 
highlights a polygon.

In my mapfile I created a new, empty layer named annotate_pin, with 
coloring defined (green in my case).  I do sql on my PostGIS database to 
find the polygon I want to "highlight".  I copy the polygon from the 
"parcels" layer into the "annotate_pin" layer.

my $layer = $map->getLayerByName('parcels');
$layer->open();

#newlayer is misnamed... it does exist in the .map file
my $newlayer = $map->getLayerByName('annotate_pin');
$newlayer->{status} = $mapscript::MS_ON;

# sid here is set to the shape I want to copy/highlight
$db->pg_result();
($sid) = $q->fetchrow_array;

# get the shape
my $shp = $layer->getFeature($sid);
$layer->close();
if (!$shp)
{
	print STDERR "---- cannot getFeature($sid) ----\n";
}

#copy it to a new shape
my $shape = $shp->clone();

#add new shape into the annotate_pin layer
$newlayer->addFeature($shape);

... later we draw with $map, which has one polygon in the annotate_pin 
layer.

Note that this is one way, there is the new styling options, but it's 
all xml and I cant stand xml, so I never even looked at it.  Not sure if 
this is at all what you were looking for, but hope it helps.

-Andy



More information about the MapServer-users mailing list