[Mapserver-users] Create a legend using PHPMapscript

Hal Mueller hal at mobilegeographics.com
Wed May 26 14:36:07 EDT 2004

At 15:24 +0200 5/26/04, Frank Broniewski wrote:
>   $legend = $map->legend();
>   $legend_url = $legend->saveWebImage();

I believe that if you check the value of $legend after that first 
line above, it will be 0 (echo $legend;).  (my PHP map scripts have 
"echo" statements running through them like chicken pox, so that I 
can check intermediate results).  And the saveWebImage function is 
not defined for legends.  Try instead:

$legendImage = $map->drawLegend();
$legend_url = $legendImage->saveWebImage();

I'm also assuming that you have a legend defined in your MAP file, 
and that you have class names defined in the MAP file.  You should 
probably post the MAP file and let us have a look at that.

The other thing that I don't see (maybe it's in code farther down) is 
some display of that URL.  Something like
echo "<img src=\"",$legend_url,"\">";

You also have the option of embedding the legend in the main map's 
web image.  http://www.mobilegeographics.com/mapserver/usa2.phtml 
demonstrates that approach.  I would recommend starting out that way 
just to get the thing working, and then later you can put it into a 
separate image.


More information about the mapserver-users mailing list