Runtime Shapes & Values

Abe Gillespie abe.gillespie at GMAIL.COM
Sun Jul 3 15:43:58 EDT 2005


I'd like to add layers, shapes, and values at runtime via PHP
MapScript.  I don't have any problems with the layers and shapes ...
but how do I set a value.  Ultimately what I'd like to do is set up
some classes for my layer so that the shapes I add at runtime will
obey the rendering of the different classes according to a CLASSITEM. 
Here's some code which should explain it better:

// Setup the layer.
$layer = ms_newLayerObj($map);
$layer->set("name", "my_label_layer");
$layer->set("type", MS_LAYER_ANNOTATION);
$layer->set("transform", MS_FALSE);
$layer->set("classitem", "the_class_item");

// Setup one class (though multiples would be setup in production).
$class = ms_newClassObj($layer);
$class->set("expression", "default");
$label = $class->label;
$label->set("type", MS_TRUETYPE);
$label->set("font", "vera");
$label->set("size", 10);
$label->set("position", MS_CR);
$label->set("force", MS_TRUE);
$label->color->setRGB(0, 0, 0);

// Now I add a label.
$pnt = ms_newPointObj();
$pnt->setXY($x, $y);
$line = ms_newLineObj();
$line->add($pnt);
$shp = ms_newShapeObj($layer->type);
$shp->add($line);
$shp->set("text", $text);

// But I can't set a value like I need to:
// $shp->values["the_class_item"] = "default";

$layer->addFeature($shp);

I guess I should say what I'm trying to do overall ... that's usually
better than just stating a piece of the puzzle when there are so many
smarter people than I out there.  :)  Basically I'm rolling my own
version of the MapNotes tool from Chameleon.  The existing version
just isn't what I want.  The items I need are as follows:

1. Arbitrary placement of notes.
2. Selectable colors.
3. Selectable fonts.
4. Selectable size.

Because of options 2-4 is the reason for me setting up various classes
and rendering on a classitem / value.

Any thoughts?  Any better ideas?

Thanks a ton.
-Abe



More information about the mapserver-users mailing list