[mapserver-users] Gave it up. Niow looking for complete working example of dynamically drawing points (and Text) in php.

Jan Mantkowski jan.mantkowski at gmx.de
Sat Mar 23 04:06:15 EST 2002


Hi folks,

i´d like to thank Steve and Dan for their extensive help.
Unfortunately we have not been able to visualise Text on a map.

This is what i like to do:

I want to show a map with the names of users on it. To show where the users
of a website stay.
I never managed it to make the layer (hopefully with the users names on it)
to appear on screen.

Please, please, can anybody post a complete working example in php to me.

If anybody want to have another look at my code:
1) mysql dump
2) php code
3) europe.map

All i get ia a picture of europe, without any usernames.

Thanks,

Jan

1) mysql dump

# Table structure for table `nuke_map`

CREATE TABLE nuke_map (
  pn_name varchar(20) NOT NULL default '',
  pn_lat varchar(15) NOT NULL default '',
  pn_lon varchar(15) NOT NULL default '',
  PRIMARY KEY  (pn_name)
) TYPE=MyISAM;

# Dumping data for table `nuke_map`

INSERT INTO nuke_map VALUES ('Jan', '-4000000', '2500000');
INSERT INTO nuke_map VALUES ('Jose', '1000000', '8000000');
INSERT INTO nuke_map VALUES ('Madeleine', '3000000', '4000000');
INSERT INTO nuke_map VALUES ('Fritz', '4000000', '2000000');

2) php code

<?php
dl("php_mapscript_35.dll");

$map = ms_newMapObj("europe.map");
$layerName="users";

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
$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"]."&nbsp;&nbsp;&nbsp;&nbsp;".$show["pn_lat"]."&nbsp;&nbsp;&nbs
p;&nbsp;".$show["pn_name"]."<br>\n";
}

//drawPoints
$layer = $map->getLayerByName( $layerName );
$image = $map->draw();

// 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);
}
$map->drawLabelCache($image);
//$url = $image->saveWebImage(MS_PNG, 0, 0, 0);
  $url = $image->saveWebImage($image, 0, 0, -1);
//$UrlHighLight = $ImgHighLight->saveWebImage($ImgHighLight, 0, 0, -1);
printf("<IMG border=1 SRC=%s WIDTH=%d HEIGHT=%d>\n", $url, $image->width,
$image->height);
?>

3) europe.map

NAME FIRSTMAP
SIZE 400 400
STATUS ON
EXTENT -5696501 1923039 5696501 11022882
UNITS METERS

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 "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




More information about the mapserver-users mailing list