Feature Object and text
Eric Bridger
eric at GOMOOS.ORG
Mon Aug 16 10:56:00 PDT 2004
On Mon, 2004-08-16 at 13:44, Sean Gillies wrote:
> On Aug 16, 2004, at 11:17 AM, Stefanie Weykam wrote:
>
> > Hi all,
> > I have an annotation layer, it contains a point (feature) and a string
> > to
> > label this point.
> > Actually, the string is the title of the map and I want to change it
> > according to the currently displayed theme.
> > Is there any feature object which can be set by MapScript? The Class
> > Reference doesn't mention any. And, how do I change the color of the
> > label?
> > I always get error messages saying that the property (both color and
> > text)
> > don't exist or that the function setRGB() is undefined....???
> > Which objects do have these properties - do I nedd colorObjects?
> > styleObjects?? How do I create them?
> > Thanks,
> > Stefanie
> >
> > LAYER
> > NAME "subtit"
> > STATUS ON
> > TRANSFORM FALSE
> > TYPE ANNOTATION
> > FEATURE
> > POINTS 635 10 END
> > TEXT "Species Richness" # "a species name"
> > END
> > CLASS
> > LABEL
> > TYPE TRUETYPE
> > FONT verdana # verdana-italic
> > SIZE 12
> > POSITION LL
> > COLOR 80 130 0 # 160 90 0
> > END
> > END
> > END
> >
> >
>
> Stephanie,
>
> Support for inline features is currently limited. You cannot
> access a feature once it is in the feature "set".
>
> The thing to do is to leave out the FEATURE block in your map
> file, and insert a new feature as needed:
>
> p = mapscript.pointObj(635, 10) # the point
> s = mapscript.shapeObj(layer.type) # new shape to hold point
> l = mapscript.lineObj() # point must be in a line
> l.add(p) # add point to line
> s.add(l) # add line to shape
>
> s.text = 'Species Richness' # label for point
> layer.addFeature(s)
>
> layer.draw(map, image)
>
To continue Sean's excellent and concise (Python) example (in Perl/PHP):
I've found that even though the FEATURE is at the layer level, it will
use the LABLE COLOR from the first CLASS. So before your layer.draw()
$class = $layer->getClass(0);
$class->{label}->{color}->setRGB(255,0,0);
Alternatively:
$red = new mapscript::colorObj(255,0,0);
$class->{label}->{color} = $red;
Eric
More information about the MapServer-users
mailing list