php/mapscript and client-side imagemaps

Matt Pettis matt.pettis at THOMSON.COM
Wed Apr 4 13:41:48 PDT 2007


Hi All,

I've tried again, and got closer... Below are the PHP code and the
mapfile code, along with the output.  I'm rendering MN counties, so I
want to output 87 polygons worth of image coordinates defining the
counties.  I know that, as opposed to the html template approach, that I
haven't defined any way via PHP to specify the coords (like using the
[shpXY ...] parts of the html template).  Can anyone help me add code to
output a line with the correct coordinates (one record per query result)
to process each polygon imagemap output and output customized lines into
the <map> file?  That would be code similar to the template example on
the mapserver website that substitutes values into the template for
[...] once for each query result and appends to the output like in the
following:

<area shape="poly" coords="[shpxy precision=0 proj=image]"
href="http://my.url/mypage.cfm?ID=[SITE_ID]" title="[NAME]"
alt="[NAME]">

(this template example is at
http://mapserver.gis.umn.edu/docs/howto/imagemaps).

Tia,
Matt

<=== php file code snippet ===>
$imgmap = ms_newMapObj(
"C:\\ms4w\\Apache\\htdocs\\postgis\\US-Senate-prct-imgmap.map" );
$imgmap->setExtent($myrow['xmin'],$myrow['ymin'],$myrow['xmax'],$myrow['
ymax']);
$imgmap->selectOutputFormat("imagemap");
$imgmapimg = $imgmap->draw();
$imgmapurl = $imgmapimg->saveWebImage();
<=====================>

<=== Mapfile US-Senate-prct-imgmap.map ===>
MAP
	IMAGETYPE	PNG
#	EXTENT	189783.546875 4810309 761653.5625 5472346.5
	SIZE	680 510
	IMAGECOLOR	255 255 255
	FONTSET	"C:\ms4w\Apache\htdocs\fonts\fonts.list"

	WEB
		IMAGEPATH	"C:\ms4w\Apache\htdocs\tmp\"
		IMAGEURL	"/tmp/"
	END

	LAYER
		NAME	"county"
		CONNECTIONTYPE	postgis
		CONNECTION	"user=postgres dbname=postgis
password=4theluv"
		DATA	"the_geom from (select distinct the_geom from
shp_counties) as foo using unique the_geom using SRID=-1"
		STATUS	DEFAULT
		TYPE	POLYGON
		TRANSPARENCY	0
		
		CLASS
			NAME	"county"
			STYLE
				OUTLINECOLOR	0 0 0
			END
		END
	END

END # End MAP def
<=====================>

<=== Mapfile output (46140b8f_dec_0.html) ===>
<map name="map1" width="680" height="510">
</map>
<=====================>


 

-----Original Message-----
From: Daniel Morissette [mailto:dmorissette at mapgears.com] 
Sent: Wednesday, April 04, 2007 12:30 PM
To: Pettis, Matthew (Thomson)
Cc: MAPSERVER-USERS at LISTS.UMN.EDU
Subject: Re: [UMN_MAPSERVER-USERS] php/mapscript and client-side
imagemaps

Matt Pettis wrote:
> Hi,
> 
> I'm trying to get generate a client side imagemap (the <map>...</map>)
coordinates and inserting the text using just php/mapscript (avoiding
using the templating methods found at
http://mapserver.gis.umn.edu/docs/howto/imagemaps because I want as pure
a php solution as i can get).  I found the wiki entry for this
(http://mapserver.gis.umn.edu/cgi-bin/wiki.pl?ImageMap), and followed
its instructions.  In particular, the following lines did not generate
what I thought:
> 
> $imgmap = ms_newMapObj( 
> "C:\\ms4w\\Apache\\htdocs\\postgis\\imgmap.map" ); $imgmapimg = 
> $imgmap->draw(); $imgmapurl = 
> $imgmapimg->saveWebImage(MS_IMAGEMAP,1,1,0);
> 
> I couldn't find documentation on saveWebImage, but I thought it would
generate the text i would need to include in a <map> section for my
webpage.  Instead, what was generated was a .png file.  Should this be
usable as an image map, or did I get this in error (the page rendered
just fine).
> 

The PHP MapScript saveWebImage doc is at:
http://mapserver.gis.umn.edu/docs/reference/phpmapscript-class/classes/i
mageobj

The Wiki page that you were looking at needs comes from the old/frozen
wiki so it's out of date and will never be updated. The saveWebImage
method doesn't take any arguments any more. Instead, you have to pick
your output format using selectOutputFormat() before the draw() call.

Something like this might work:

$imgmap = ms_newMapObj( "C:\\ms4w\\Apache\\htdocs\\postgis\\imgmap.map"
);

$imgmap->selectOutputFormat("imagemap");
$imgmapimg = $imgmap->draw();
$imgmapurl = $imgmapimg->saveWebImage();


Daniel
--
Daniel Morissette
http://www.mapgears.com/



More information about the MapServer-users mailing list