[Mapserver-users] drawing labels dynamically

John Deck jdeck at socrates.Berkeley.EDU
Tue Mar 4 07:35:25 PST 2003


This was somewhere on the list awhile back I think... 

Here is what I did though:
Make a point layer called dynamic_point in the map file and added points
to the layer in PHP, sending label attributes with the point object draw
command.

The PHP is something like:
 
$l_pointLabel = ms_newPointObj();
$l_pointLabel->setXY($x-coord,$y-coord);
$l_layerPoint = $l_map->getLayerByName("dynamic_point");
$l_image=$l_map->draw();
$l_pointLabel->draw($l_map,$l_layerPoint,$l_image,0,"some value you want
to label the point with");
$l_map->drawLabelCache($l_image);

You can loop this or pull whatever values you want for labels from an
external database.

Here is what the layer looks like:

LAYER
    NAME dynamic_points
    TYPE point
    STATUS OFF

    CLASS
        EXPRESSION /./
        SYMBOL 3
        SIZE 7
        NAME dynamic_points
        COLOR 255 255 255
        LABEL
                TYPE TRUETYPE
                FONT ARIALBI
                COLOR 0 0 0
                SIZE 8
                POSITION LC
                WRAP " "
         END
    END
END


John Deck

> -----Original Message-----
> From: mapserver-users-admin at lists.gis.umn.edu 
> [mailto:mapserver-users-admin at lists.gis.umn.edu] On Behalf Of 
> Frank Rittinger
> Sent: Tuesday, March 04, 2003 1:49 AM
> To: mapserver-users at lists.gis.umn.edu
> Subject: [Mapserver-users] drawing labels dynamically
> 
> 
> Hello mapserver users,
> 
> Is there a way to draw labels (using PHP/Mapscript) dynamically, i.e. 
> depending on a query of an external database?
> 
> I want to draw statistical data into maps, generated by 
> mapserver, which 
> is not available when the map files and the shape files 
> (actually *.tab 
> files) are generated.
> 
> I thought of creating shape files on-the-fly, but the Mapscript 
> documentation says that attributes of shapes are read-only 
> and cannot be 
> added.
> 
> Thanks, Frank
> 
> 
> 
> 
> _______________________________________________
> Mapserver-users mailing list
> Mapserver-users at lists.gis.umn.edu 
> http://lists.gis.umn.edu/mailman/listinfo/maps> erver-users
> 




More information about the MapServer-users mailing list