[Mapserver-users] Label TEXT Display Trouble PHP Mapscript
Mark Fennell
mfennell at markfennell.com
Tue Apr 6 16:26:20 PDT 2004
Hi. I Have sucessfully got PHPmapscript to extract a series of points from a
database, and then display the points on a map. (PHP code is below, it
should be relatively easy to follow and is made up from the various posts
around this mailing list)
The MAP code is also detailed below as well. I am setting the points to
display with SetXY, and then labelling them (I think) with the
$pointObj->draw($map, $layerObj, $image, 0, $show["Name"]); part.
I can display the points but Not the Text Label, whiich is What I really
want to do! Any help apppreciated.
Mark Fennell
-------8<----PHP File------------
<html>
<?php
dl("php_mapscript.so");
$map_path="/Users/markfennell/Existing/adventure/wwwroot/map/";
$map = ms_newMapObj($map_path."dynamic.map");
printf("Map name=%s, num lay=%d<br>\n", $map->name, $map->numlayers);
for ($i=0; $i<$map->numlayers; $i++) {
$myLayer = $map->getLayer($i);
printf("Layer num=%d, name=%s <br>\n", $i, $myLayer->name);
}
echo"<br>";
//mysql_q
// Dirty hack to make query
$db = mysql_connect("localhost", "root", "Slaine2k");
mysql_select_db("adventurelocations",$db);
$results = mysql_query("SELECT * FROM Location",$db);
if ($results === false) die("failed");
//drawPoints
$layerObj = $map->getLayerByName("points");
$image = $map->draw();
$pointObj = ms_newPointObj();
while ($show = mysql_fetch_array($results, MYSQL_ASSOC)) {
$pointObj->setXY($show["Longitude"], $show["Latitude"], 0);
// draw the point on the image, using the id attribute to label it
$pointObj->draw($map, $layerObj, $image, 0, $show["Name"]);
echo
$show["Latitude"]." ".$show["Longitude"]." ".$show["Name"]."<br>\n
";
}
$image_url=$image->saveWebImage(MS_PNG,1,1,0);
?>
<HTML>
<HEAD>
<TITLE>MYSQL sample</TITLE>
</HEAD>
<BODY>
<IMG SRC=<?php echo $image_url; ?> >
</BODY>
</HTML>
------8<------------MAP----------------
MAP
NAME "Australia"
SIZE 400 300
IMAGETYPE PNG
EXTENT 112.9211349 -43.65853882 153.63974 -9.984018326
SHAPEPATH "/Users/markfennell/Existing/adventure/wwwroot/map/data"
FONTSET
"/Users/markfennell/Existing/adventure/wwwroot/map/tutorial/fonts/fonts.list
"
WEB
IMAGEPATH "/Users/markfennell/Existing/adventure/wwwroot/map/tmp/"
IMAGEURL "/adventure/wwwroot/map/tmp/"
END
IMAGECOLOR 255 255 255
PROJECTION
"proj=merc"
"lat_0=0"
"lon_0=0"
END
SYMBOL
TYPE ELLIPSE
NAME "circle"
POINTS 1 1 END
FILLED TRUE
END
# Start of LAYER DEFINITIONS
---------------------------------------------
LAYER
NAME "au"
DATA "au_coast"
STATUS DEFAULT
TYPE POLYGON
PROJECTION
"proj=merc"
"lat_0=0"
"lon_0=0"
END
CLASS
COLOR 232 232 232
OUTLINECOLOR 32 32 32
END
END # End Australia Coast
LAYER
NAME "points"
TYPE POINT
PROJECTION
"proj=merc"
"lat_0=0"
"lon_0=0"
END
CLASS
SYMBOL "circle"
SIZE 6
COLOR 255 0 0
OUTLINECOLOR 0 0 0
LABEL
COLOR 132 31 31
SHADOWCOLOR 218 218 218
SHADOWSIZE 2 2
TYPE TRUETYPE
FONT arial-bold
SIZE 12
ANTIALIAS TRUE
POSITION CL
PARTIALS FALSE
MINDISTANCE 300
BUFFER 4
END # end of label
END
END
# End of LAYER DEFINITIONS -------------------------------
END # end of map file/object
More information about the MapServer-users
mailing list