Dynamic map title
Eric Bridger
eric at GOMOOS.ORG
Thu Aug 26 14:27:27 PDT 2004
On Thu, 2004-08-26 at 15:16, Stefanie Weykam wrote:
> I think I am getting closer (thanks to your help) but still don't get it.
> Let me resume - I have this annotation layer with a point feature and a
> text, which is the (sub)title of my map.
> With it's default values it is perfectly visible, including font and color
> specifications. Trouble starts when I try to change the text via code...
>
> LAYER
> NAME "subtitESP"
> STATUS ON
> TRANSFORM FALSE
> TYPE ANNOTATION
> FEATURE
> POINTS 435 10 END
> TEXT "Merops apiaster" # this is the text to be changed!!!!
> END
> CLASS
> LABEL
> TYPE TRUETYPE #BITMAP
> FONT verdana-italic
> SIZE 12
> POSITION LL
> COLOR 160 90 0
> END
> # TEXT "Steve's method"
> END
> END
>
> ..Steve suggested to use the class text property instead of the feature so I
> commented out the feature part, but no luck.....
>
> <?php
> $map_path="c:/web/";
> $map_file="test.map";
> $map=ms_newMapObj($map_path.$map_file);
> $img=$map->draw();
> $imgURL=$img->saveWebImage();
>
> $subtitESP=$map->getLayerByName('subtitESP');
>
> # Steve's suggestion: edit the TEXT property of the class:
> $clObj=$subtitESP->getClass(0);
> //$clObj->setText('Steve');
> .....here I get 'Wrong parameter count for settext()'
>
>
> # ..Sean and Eric suggested more or less the same: to remove the feature and
> add a new feature: This is the part where I get a bit lost - do I have to
> specify the line object? set the point coordinates to map or to image
> coordinates? I get no error message but the new text doesn't show either.
> $myshpObj=ms_NewShapeObj(MS_SHAPE_LINE);
> $p=ms_newPointObj();
> $l=ms_newLineObj(); # according to the MapScript Class Ref - this is the
> onlytype that can be added to a shape???
> //$p->setXY(1185001, 4879000); # (635,10) map or img coords????
> $p->setXY(635, 10);
> $l->add($p);
>
> $myshpObj->add($l);
> $myshpObj->set('text', 'Sean and Eric');
> //$subtitESP->addFeature($myshpObj, MS_SHAPE_LINE);
> $subtitESP->addFeature($myshpObj);
>
> $subtitESP->draw($img);
> $imgURL=$img->saveWebImage();
>
> ?>
> <html>
> <body>
> <form name="mapa" method="get" action=<?php echo
> $HTTP_SERVER_VARS['PHP_SELF']?>>
> <input type="image" name="image" src="<?php echo $imgURL ?>" ></br>
> </form>
>
> </body>
> </html>
>
Here is my layer definition:
LAYER
GROUP "Contaminants"
NAME "contaminant_label"
STATUS OFF
TRANSFORM FALSE
TYPE ANNOTATION
CLASS
STYLE
END
LABEL
TYPE TRUETYPE
FONT arial
SIZE 12
COLOR 0 0 0
ANTIALIAS TRUE
POSITION LR
PARTIALS FALSE
BUFFER 0
END
END
END
And the PHP Mapscript 4.2 code which displays a text label on the map.
$oLayer = $oMap->getLayerByName('contaminant_label');
$oLayer->set("status", MS_ON);
$pt = ms_newPointObj();
$ln = ms_newLineObj();
$shp = ms_newShapeObj(MS_SHAPE_POINT);
// these are pixel coordinates because TRANSFORM is FALSE
$pt->setXY(10,20);
$ln->add($pt);
$shp->add($ln);
$shp->set("text", "Median Concentrations");
$oLayer->addFeature($shp);
Did you remember to turn the layer ON?
More information about the MapServer-users
mailing list