[Mapserver-users] [PHP/MS 3.7-dev]: setRGB() conflicts with createLegendIcon() ?
Vinko Vrsalovic
vinko at cprsig.cl
Fri Feb 21 00:29:44 PST 2003
Hi, I was just testing the latest CVS for 3.7 with PHP/Mapscript, PHP
4.2.3, Apache 1.3.X, and found the following weirdness.
When using setRGB, and then createLegendIcon(), the color drawn is not the
one I set, but another (apparently random) one. But, if I use
map->save() and create a mapObj from the saved one, and draw an image using
the saved mapfile, it shows the correct color.
As a side note, when i save the legend icons created (savewebimage()),
the color of them is ok, but the colors of the features themselves is
just as wrong.
Nevertheless, the weird behaviour occurs whether i save the legend icons or not.
Below are the two snippets of code showing the error (it's PostGIS based,
because I don't have shapefiles handy, and the error doesn't seem to be PostGIS
related).
If this is not reproducible with this data, please let me know
to prepare another example (for instance, shapefile based or without
the defines).
This code works fine in 3.6.4. The MAP_FILE define points to an empty map
file:
---------------------------------MAP_FILE------------------------------
MAP
END
-----------------------------------------------------------------------
The code that generates the error:
-------------------------------------------------EXAMPLE 1----------------
<?php
include ("setup.inc");
$map = ms_newMapObj(MAP_FILE,INSTALL_DIR);
$map->set("width",300);
$map->set("height",300);
$map->set("units",MS_METERS);
$map->setSymbolSet(SYMBOL_FILE);
$map->setFontSet(FONT_FILE);
$map->web->set("imageurl","/tmp/");
$map->web->set("imagepath",IMAGES_DIR);
$map->web->set("template","VOID");
$lyr_chi = ms_newLayerObj($map);
$lyr_chi->set("type",MS_LAYER_POLYGON);
$lyr_chi->set("data","the_geom from chilegeo");
$lyr_chi->set("connection",STR_CON);
$lyr_chi->set("status",MS_ON);
$lyr_chi->set("connectiontype",MS_POSTGIS);
$lyr_chi->set("name","Chile");
$lyr_chi->set("template","VOID");
$cla_chi = ms_newClassObj($lyr_chi);
$sty_chi = ms_newStyleObj($cla_chi);
/** If you take out the createLegendIcon(), the color drawn is the set in setRGB(), else it is
a 'random' color **/
$sty_chi->color->setRGB(0,200,0);
$mg = $cla_chi->createLegendIcon(20,10);
/** Everthing else I've tested works fine **/
$rspu = $pgsql->Execute("SELECT xmin(extent(the_geom)) as minx,xmax(extent(the_geom)) as maxx,".
"ymin(extent(the_geom)) as miny,ymax(extent(the_geom)) as maxy from chilegeo");
$xmin = $rspu->fields['minx'];
$ymin = $rspu->fields['miny'];
$xmax = $rspu->fields['maxx'];
$ymax = $rspu->fields['maxy'];
$map->setextent($xmin,$ymin,$xmax,$ymax);
$map->selectOutputFormat('png');
$img = $map->draw();
$url_img = $img->SaveWebImage();
$map->save("/tmp/seia37.map");
echo "<img src=".$url_img.">";
?>
------------------------------------END EXAMPLE------------------------------
The code, using '/tmp/seia37.map' (which works fine) is:
-------------------------------------------------EXAMPLE 2----------------
<?php
include ("setup.inc");
$map = ms_newMapObj("/tmp/seia37.map");
$map->selectOutputFormat('png');
$img = $map->draw();
$url = $img->SaveWebImage();
echo "<img src=".$url.">";
?>
------------------------------------END EXAMPLE-------------------------------
--
Vinko Vrsalovic <el[|- at -|]vinko.cl>
http://www.cprsig.cl
More information about the MapServer-users
mailing list