[mapserver-users] drawing layer with user names from mysql table
Jan Mantkowski
jan.mantkowski@gmx.de
Wed, 20 Mar 2002 08:24:19 -0000
This is a multi-part message in MIME format.
------=_NextPart_000_0000_01C1CFE8.A1B5E7E0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Hi all,
i have not been able to make my script run right now.
Please help me.
Jan
PS:
If someone has a complete working example of how to display data from mysql
table as a layer of a map please mail it to me.
I always get this error:
Fatal error: Call to a member function on a non-object in
c:\apache\htdocs\pn_71\html\modules\map\index-standalone3.php on line 28
line 28 is: $layer = $map->getLayerByName( $layerName );
This is my data in the mysql table:
-0.1271 51.5063 Jan London
-3.7057 40.4203 Jose Madrid
2.3453 48.8547 Madeleine Paris
9.9898 53.5548 Fritz Hamburg
This my php script:
<?php
// load .dll`s, so there is no need to edit the php.ini.
// but you need to put this files in your /php/extensions folder
dl("php_mapscript_35.dll");
dl("php_proj.dll");
dl("php_dbase.dll");
//variables
GLOBAL $map;
GLOBAL $image;
GLOBAL $layer;
$layerName="PNUsers";
//mysql_q
$db = mysql_connect("localhost", "root", "");
mysql_select_db("Rogue",$db);
$results = mysql_query("SELECT * FROM nuke_map",$db);
if ($results === false) die("failed");
//display result of mysql query on screen
while ($show = mysql_fetch_array($results, MYSQL_ASSOC)) {
echo
$show["pn_lon"]." ".$show["pn_lat"]." &nbs
p; ".$show["pn_name"]."<br>\n";
}
//drawPoints
$layer = $map->getLayerByName( $layerName );
// Loop through result of point query and:
while ($line = mysql_fetch_array($results, MYSQL_ASSOC)) {
$pt = ms_newPointObj();
$pt->setXY( $line["pn_lon"], $line["pn_lat"] );
$pt->draw($map, $layer, $image, 0, "TEST");
$layer->set('status', MS_ON);
$layer->draw($image);
}
//showmap
$map = ms_newMapObj("data/europe.map");
$image=$map->draw();
//$layer->draw($image);
$image_url=$image->saveWebImage(MS_PNG,1,1,0);
echo "<img src=\"".$image_url."\">";
?>
Thanks,
Jan
------=_NextPart_000_0000_01C1CFE8.A1B5E7E0
Content-Type: application/octet-stream;
name="europe.map"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="europe.map"
NAME FIRSTMAP
SIZE 400 400
STATUS ON
EXTENT -5696501 1923039 5696501 11022882
UNITS METERS
SHAPEPATH "data"
WEB
IMAGEPATH "c:\Apache\htdocs\tmp\"
IMAGEURL "/tmp/"
END
LAYER
NAME world
TYPE POLYGON
STATUS ON
DATA europa
CLASS
TEMPLATE void
COLOR 110 50 100
OUTLINECOLOR 200 200 200
#END
END
TOLERANCE 10
END
LAYER
NAME "Nations"
DATA europa
STATUS ON
TYPE ANNOTATION
CLASS
COLOR -1 -1 -1 # no marker will be drawn
LABEL
SIZE MEDIUM
COLOR 132 31 31
OUTLINECOLOR 255 255 255
BUFFER 4
END
END
END
END
LAYER
NAME "PNUsers"
DATA users
STATUS ON
TYPE ANNOTATION
LABELITEM "text"
CLASS
COLOR -1 -1 -1 # no marker will be drawn
LABEL
SIZE MEDIUM
COLOR 132 31 31
OUTLINECOLOR 255 255 255
BUFFER 4
END
END
END
END
------=_NextPart_000_0000_01C1CFE8.A1B5E7E0--