[Mapserver-users] why can't I draw a point on my map?

Dylan Keon keon at nacse.org
Mon Feb 17 17:06:49 EST 2003


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);


HTH,
--Dylan


-- 
************************************************
  Dylan Keon
  GIS/Database Research Specialist
  Northwest Alliance for Computational
  Science and Engineering (NACSE)
  Oregon State University
  Corvallis, OR 97331
  keon at nacse.org        (541) 737-6608
************************************************



Chris Black wrote:
> Thanks fr your suggestions, Attila.  Unfortunately, my code's still not 
> working -- I don't see a dot and, if I give a non-empty label, I don't 
> see the label either.  Has anyone got anything more to offer?
> 
> makedot.pho:
> --------- 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);
> $dot_class = ms_newClassObj($crab_layer);
> $dot_class->set("status", MS_ON);
> $image=$map->draw();
> $crab_here = ms_newpointobj();
> $crab_here->setXY(233, 340, 0);
> $crab_here->draw($map, $crab_layer, $image, 0, "");
> $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 ---------------
> 
> zoomableizg.map:
> ------------------ cut here ----------------
> # Note: Comments in a map file are preceeded by the pound (#) sign.
> # When MapServer encounters the pound sign, it will ignore the
> # rest of the line.  Unfortunately, you can't comment a whole block
> # of code or text in MapServer.  So, you're stuck with adding pound
> # signs for every line you wish to comment out.
> 
> 
> NAME CALCTYEX1
> EXTENT 509945 4236585 629120 4135472
> SIZE 709 606
> UNITS METERS
> SHAPEPATH "C:\inetpub\wwwroot\MapServerApps\IZG\data\"
> 
> WEB
>     TEMPLATE ZoomableIZG.html
>     IMAGEPATH "C:\inetpub\wwwroot\MapServerApps\data\tmp\"
>     IMAGEURL "/MapServerApps/data/tmp/"
>     LOG "c:\inetpub\wwwroot\mapserverapps\izg\mapserverlog.txt"
> END # WEB
> REFERENCE
>     STATUS ON
>     SIZE 144 123
>     IMAGE "C:\inetpub\wwwroot\mapserverapps\izg\images\REFIMG.gif"
>     EXTENT 509945 4236585 629120 4135472
>     COLOR -1 -1 -1
>     OUTLINECOLOR 255 0 0
> END # REFERENCE
> 
> 
> #LAYER
>     #data "raster\relief.jpg"
>     #NAME "bayraster"
>     #STATUS DEFAULT
>     #TYPE RASTER
> #END # LAYER
> LAYER # start of the "calcounties" layer object
>   NAME "calcounties"
>   DATA "vector\bayctys"
>   STATUS DEFAULT
>   TYPE POLYGON
>   LABELITEM "Name"
>   CLASS
>     OUTLINECOLOR 204 0 0
>   END # CLASS
> END # LAYER
> END # FILE
> 
> --------- cut here -------------------
> 
> Attila Csipa wrote:
> 
>>On Friday 14 February 2003 21:49, you wrote:
>>  
>>
>>>up an early prototype, just trying to draw a one-layer map and then put
>>>a dot on it at a particular location.  I don't see the dot or its label.
>>> Am I missing a step?  I wasn't sure whether the x & y coordinates
>>>    
>>>
>>
>>I had a similar problem and it turned out that the order of commands is 
>>relevant, even at places where it might seem it is not. So I would try 
>>something like:
>>
>>  
>>
>>>$map = ms_newMapObj($map_path.$map_file);
>>>$crab_layer = ms_newlayerObj($map);
>>>$crab_layer->set("status", MS_ON);
>>>$dot_class = ms_newClassObj($crab_layer);
>>>$dot_class->set("status", MS_ON);
>>>$image=$map->draw();
>>>$crab_here = ms_newpointobj();
>>>$crab_here->setXY(233, 340, 0);
>>>$crab_here->draw($map, $crab_layer, $image, 0, "");
>>>$image_url=$image->saveWebImage(MS_GIF,1,1,0);
>>>    
>>>
>>
>>Note that if you use a point and put text over right over it you might not 
>>see the point (maybe this was intended ?).
>>
>>
>>Regards,
>>Attila
>>  
>>
> 





More information about the mapserver-users mailing list