php/mapscript and client-side imagemaps

Matt Pettis matt.pettis at THOMSON.COM
Mon Apr 16 14:19:30 EDT 2007


I'm resubmitting this with the hopes that someone may yet have some
insight... However, there is one change to the .map file, but the result
is the same... I've added a TEMPLATE statement in the LAYER object...
Below is the new .map object:

<=== 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
        TEMPLATE "co-imgmap-template.htm"

        CLASS
            NAME    "county"
            STYLE
                OUTLINECOLOR    0 0 0
            END
        END
    END

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

The template looks like this:

<=== Mapfile US-Senate-prct-imgmap.map ===>
<area shape="poly" coords="[shpxy precision=0 proj=image]"
href="http://www.google.com">
<=====================>

And the .php snippet looks like this:

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

The map output file looks the same:

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



Tia,
matt

-----Original Message-----
From: UMN MapServer Users List [mailto:MAPSERVER-USERS at LISTS.UMN.EDU] On
Behalf Of Pettis, Matthew (Thomson)
Sent: Wednesday, April 04, 2007 3:42 PM
To: MAPSERVER-USERS at LISTS.UMN.EDU
Subject: Re: [UMN_MAPSERVER-USERS] php/mapscript and client-side
imagemaps

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