User Tools

Site Tools


tecnica:gps_cartografia_gis:php_mapscript_recipes

This is an old revision of the document!


PHP MapScript Recipes

Generate the legend image

We need a mapfile with all the necessary to display the legend.

We can return just the legend image via PHP code. The image can be served as an inline image or as a web image from the temporary directory.

<?php
// PHP MapScript example.
// Display a map legend as an inline image or embedded into an HTML page.
$inline = true;
$map_path='/var/www/mapfiles/';
$mapfile = $_REQUEST['mapfile'];
$map = ms_newMapObj($map_path . $mapfile);
$legend_image = $map->drawLegend();
if ($inline) {
    header('Content-Type: image/png');
    $legend_image->saveImage('');
    exit;
}
$image_url = $legend_image->saveWebImage();
?>
<HTML>
<HEAD>
<TITLE>PHP MapScript example: Display the legend</TITLE>
</HEAD>
<BODY>
<IMG SRC=<?php echo $image_url; ?> >
</BODY>
</HTML>

The mapfile requires all the relevant entries, among them: MAP.FONTSET, MAP.WEB.IMAGEPATH, MAP.WEB.IMAGEURL, MAP.LEGEND.

For inline images you can omit web paths, because no temporary images will be created.

tecnica/gps_cartografia_gis/php_mapscript_recipes.1253109142.txt.gz · Last modified: 2009/09/16 15:52 by niccolo