[Mapserver-users] got it working (Re: why can't I draw a point on my map?)
Chris Black
cblack at CalAcademy.Org
Mon Feb 24 16:24:33 PST 2003
Got it working, thanks to Dylan. Here's the code I finally used:
------ cut here ------------------
<?php
dl('php_mapscript_36.dll');
$map_path="c:\\inetpub\\wwwroot\\mapserverapps\\izg\\";
$map_file="zoomableizg.map";
// Default values and configuration
$map = ms_newMapObj($map_path.$map_file);
$crab_layer = ms_newlayerObj($map);
$crab_layer->set("status", MS_ON);
$crab_layer->set("type", MS_LAYER_POINT);
//$crab_layer->setProjection("proj=utm,datum=NAD27,zone=10");
$dot_class = ms_newClassObj($crab_layer);
$dot_class->set("symbol", 1);
$dot_class->set("size", 10);
$dot_class->set("color", $map->addColor(0,0,255));
$image=$map->draw();
$crab_here = ms_newpointobj();
$crab_here->setXY(-218367, -18823, 0);
$crab_here->draw($map, $crab_layer, $image, 0, "");
$map->drawLabelCache($image);
$image_url=$image->saveWebImage(MS_GIF,1,1,0);
?>
<HTML>
<HEAD>
<TITLE>Map</TITLE>
</HEAD>
<BODY>
<CENTER>
<img src="<?php echo $image_url?>" alt="bay map">
</CENTER>
</BODY>
</HMTL>
--------------- cut here -----------------------
Here's Dylan's message for reference:
Message: 11
Date: Mon, 17 Feb 2003 14:06:49 -0800
From: Dylan Keon <keon at nacse.org>
To: Chris Black <cblack at CalAcademy.Org>
CC: mapserver-users at lists.gis.umn.edu
Subject: Re: [Mapserver-users] why can't I draw a point on my map?
Chris,
A few things:
1) $crab_here->setXY() should be given geographic coordinates, not image
coordinates. From your EXTENT it looks like your data are projected in
UTM, so give setXY() an appropriate easting and northing.
2) You should assign a symbol to the new point layer. If you don't have
a symbol file, use the one from the Itasca demo. Note that you will
need to add a line at the top of your mapfile to indicate where the
symbol file can be found (e.g. SYMBOLSET
"\inetpub\wwwroot\symbols\symbols.sym")
3) Looks like there are a few things missing, such as setting the layer
type, point symbol, etc. Try this instead (note comments):
$map = ms_newMapObj($map_path.$map_file);
$crab_layer = ms_newLayerObj($map);
$crab_layer->set("status", MS_ON);
$crab_layer->set("type", MS_POINT); //point layer
$dot_class = ms_newClassObj($crab_layer);
$dot_class->set("symbol", "circle"); //from symbol file
$dot_class->set("size", 8); //assign symbol size
$dot_class->set("color", $map->addColor(255,0,0)); //red
//$dot_class->set("status", MS_ON); //don't need this
$image = $map->draw();
$crab_here = ms_newPointObj();
$crab_here->setXY(x,y); //use geographic coords here!!
$crab_here->draw($map, $crab_layer, $image, 0, "");
$image_url = $image->saveWebImage(MS_GIF,1,1,0);
--Dylan
More information about the MapServer-users
mailing list