Doug.<br><br>Thanks. That&#39;s great and it was very clear. I think that
will be great if you put this in a how-to in mapserver site, cause as
you said, there are no enough information about the imagemap creation
with mapserver.
<br><br>Thanks again.<br><br><div><span class="gmail_quote">On 7/4/07, <b class="gmail_sendername">Doug Williams</b> &lt;<a href="mailto:williams@websawyer.com">williams@websawyer.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Rodrigo,<br><br>Here is what I did to make the imagemap work using phpmapscript.&nbsp;&nbsp;This is my first go round trying<br>to create an imagemap, so others may have more sensible methods or more extended methods, but I<br>never did get any specific information from anyone, nor could I find any complete information about
<br>FORMATOPTIONs which would be very helpful!!.&nbsp;&nbsp;I had to feel my way through trying to piece<br>together bits and pieces of scattered information,&nbsp;&nbsp;found luckily by google searching which turned<br>up one interesting old message from the list from someone that also did not have it working.&nbsp;&nbsp;I never
<br>did find any response to that person that showed a working example.&nbsp;&nbsp;Anyhow, I have also not ever<br>tried to describe this process so bear with my rambling, long-winded description.<br><br>First I added a OUTPUTFORMAT to my mapfile.&nbsp;&nbsp;I already had one OUTPUTFORMAT in my mapfile to
<br>improve the quality of images generated by mapserver.&nbsp;&nbsp;Whichever OUTPUTFORMAT comes first in<br>the map file is used when generating images, unless the script resets this, which has to be done in<br>order to generate both the imagemap (which is not an actual image, but just some html code) and
<br>the map (which is the actual visual image that is displayed).&nbsp;&nbsp;It would be possible to use more than<br>one mapfile rather than resetting the outputformat used, but it is not necessary.&nbsp;&nbsp;More on<br>outputformats in a minute.&nbsp;&nbsp;Also it is necessary to define a CLASSITEM for the layer that you want to
<br>use to define your imagemap.&nbsp;&nbsp;The classitem is the attribute that is stuffed into the html and<br>displayed when the mouse is held over map polygons (in this example, a simple one layer example).<br>The other important connection between the map file and the script is that the image shown in the
<br>html output has to be the same dimensions as the IMAGESIZE defined in the map file.&nbsp;&nbsp;The other<br>necessary steps take place in the php script.&nbsp;&nbsp;So hear is the mapfile stuff:<br><br> OUTPUTFORMAT<br>&nbsp;&nbsp;&nbsp;&nbsp; NAME imagemap
<br>&nbsp;&nbsp;&nbsp;&nbsp; DRIVER imagemap<br>&nbsp;&nbsp;&nbsp;&nbsp; FORMATOPTION &quot;MAPNAME=map_test&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp; FORMATOPTION &quot;TITLE=&#39;&#39;&nbsp;&nbsp;# this gets stuffed properly, you do not need to reference anything<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # on the right side of the = sign
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # in fact, you do not need this option at all.&nbsp;&nbsp;But maybe<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # someday you will?<br>&nbsp;&nbsp;&nbsp;&nbsp; MIMETYPE &quot;text/html&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# this option is also not needed!
<br>&nbsp;&nbsp;END<br><br>OUTPUTFORMAT<br>&nbsp;&nbsp;NAME jpeg<br>&nbsp;&nbsp;DRIVER &quot;GD/JPEG&quot;<br>&nbsp;&nbsp;MIMETYPE &quot;image/jpeg&quot;<br>&nbsp;&nbsp;IMAGEMODE RGB<br>&nbsp;&nbsp;EXTENSION &quot;jpg&quot;<br>&nbsp;&nbsp;FORMATOPTION &quot;QUALITY=100&quot;<br>END<br><br>The first output format is used to generate the imagemap, the second is used to generate the actual
<br>map.&nbsp;&nbsp;The script resets the format that is used.&nbsp;&nbsp;Show you that in a second.&nbsp;&nbsp;I don&#39;t really think the<br>mimetype statement is necessary, but I have seen it used so I include it here.&nbsp;&nbsp;I myself will actually<br>end up using the FORMATOPTIONs for mouseover and mouseout shown in my earlier message, but I
<br>am not going to go into how I am going to take good advantage of them here because it will<br>apparently be necessary for me to do some additional coding to get the effect I want, which I find<br>works much better (immediate response on the web page with more inclusive attribute data detail),
<br>but is more complicated programmatically... more scripting on the server side and a script on the<br>client side as well which is not needed with this method.&nbsp;&nbsp;I won&#39;t describe the second output format,<br>but the first defines a reference name for the outputformat; the driver which tells mapserver what to
<br>generate in terms of output, in this case the html code defining the areas of the imagemap with the<br>coords; the name of the generated &lt;map&gt;, you use this name when declaring the usemap; and the<br>formatoption to add a title for each defined area of the imagemap which is stuffed with the attribute
<br>data from the shapefile specified by the layer classitem (not really needed).&nbsp;&nbsp;(Don&#39;t formatoption<br>suppress=&quot;yes&quot;, or you will not get the areas in your &lt;map&gt;.)<br><br>So hear is my layer definition in my map file:
<br><br>&nbsp;&nbsp;&nbsp;&nbsp;LAYER<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NAME &quot;lakes&quot;&nbsp;&nbsp; # this is a bad layer example because the polygons are small and so<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# the imagemap driver generates some bad &lt;map&gt; areas.&nbsp;&nbsp;I&#39;ll process these
<br>out.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Typically one would likely be using this with maps that produce<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# larger features than a few worldwide lakes that are being squished to mere
<br>dots<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# in an image the size and way I am doing here.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DATA esri/world/lakes<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;STATUS on<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TYPE polygon<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CLASSITEM &quot;NAME&quot;&nbsp;&nbsp;# this is the attribute field to list in the &#39;title&#39; for each &lt;map&gt; area
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CLASS<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NAME &quot;Lakes&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;COLOR -1 -1 -1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OUTLINECOLOR 200 200 50<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;END<br>&nbsp;&nbsp;&nbsp;&nbsp;END<br><br>Well, it is something like that anyway, but the important part is the CLASSITEM line, which tells the
<br>imagemap driver what information you want stuffed in the map area title.&nbsp;&nbsp;Again, the title<br>formatoption above is not even needed, the imagemap driver just stuffs the classitem values into the<br>title for each area.&nbsp;&nbsp;It would be much nicer if all the attributes were made available with a reference
<br>mechanism so that one would have to declare something like formatoption &quot;TITLE=[NAME]&quot; with a<br>way to escape characters like quotes ... maybe that is coming in the future.<br><br>The map file will also have the SIZE defined, such as:
<br>&nbsp;&nbsp;SIZE 600 300<br>which we will use in the script to define the width and height of the image returned to the browser.<br><br>So those are the mapfile necessities.&nbsp;&nbsp;Easy enough.<br><br>The php script is not so bad either.
<br><br>If you have created and displayed a map, then you know how to create your map object for creating<br>the actual map:<br> $map_path=&quot;/path/to/mapfile/directory&quot;;<br> $map_file=&quot;mapfile.map&quot;;<br>
 $map = ms_newMapObj($map_path.$map_file);<br><br>You may want to create another map object to deal with the imagemap, though you could just use<br>the same object.<br> $imagemap = ms_newMapObj($map_path.$map_file);<br><br>
I draw the imagemap first, and the imagemap driver is set first in my map file, so draw() is using that<br>driver.&nbsp;&nbsp;It will be necessary to change this to the jpeg outputformat before drawing the other map (or<br>png or gif or whatever you may be doing):
<br> $htmlmap = $imagemap-&gt;draw();<br> $htmlmap-&gt;saveImage(&quot;/path/to/someplace/the/script/can/write/test.html&quot;, $imagemap);<br><br>This will generate a text file on the server.<br>test.html will be the:<br>
 &lt;map name=&quot;map_test&quot;&gt;<br>&nbsp;&nbsp;with areas and coords and titles<br> &lt;/map&gt;<br><br>I use the php require() command to write this into the html that I return to the browser.<br><br>To change the ouputdriver use the phpmapscript command:
<br>$map-&gt;selectOutputFormat(&quot;jpeg&quot;);<br>and draw as before:<br> $image=$map-&gt;draw();<br> $image_url=$image-&gt;saveWebImage(MS_PNG,1,1,0);<br>I have mixed jpeg and png here ... probably not what you want, png is better for vector/line type
<br>stuff, jpeg is better for more real world type images (in my understanding).<br><br>So now you have an image of your map as before, and you have the imagemap information in a file<br>that was written to the server.&nbsp;&nbsp;I add the imagemap to the html output like this:
<br> &lt;body&gt;<br>&lt;? require &quot;/path/to/somplace/the/script/can/write/test.html&quot; ?&gt;<br><br>I just plop it in right after I send the html &lt;body&gt; tag. Then you need to display the image in an<br>&lt;img&gt; tag.&nbsp;&nbsp;The standard mapserver way is to place the image in a form &lt;input&gt; tag, but I have not
<br>tried this as I read stuff stating that imagemaps do not work in form &lt;input type=image&gt; elements<br>(makes sense since there is no place to associate the needed usemap).&nbsp;&nbsp;Fortunately I had already<br>moved away from displaying my images in those elements because I wanted to be able to click on
<br>the map without sending the form automatically.&nbsp;&nbsp;Not using the form element means you will have to<br>send the img.x and img.y coordinates that get sent automatically when using the form element by<br>some other method, but that goes beyond the scope of this discussion.
<br><br>So display the image like this:<br>&lt;img src=&lt;? echo $image_url; ?&gt; usemap=&quot;#map_test&quot; width=&lt;? echo $map-&gt;width; ?&gt; height=&lt;?<br>echo $map-&gt;height; ?&gt; border=0&gt;<br><br>or however you like to code.&nbsp;&nbsp;If things turn out correctly, when you place the cursor over a polygon
<br>and leave it still for a couple of seconds, the title will appear by the cursor showing you the attribute<br>data.&nbsp;&nbsp;View the page source to see if the &lt;map&gt; looks like what you expect it to look like.<br><br>Those are the basic pieces.&nbsp;&nbsp;Sorry it is not a very well laid out description.&nbsp;&nbsp;If you have any questions,
<br>feel free to ask.&nbsp;&nbsp;I am using a slightly more recent version of mapserver, but believe this has been<br>around a while.&nbsp;&nbsp;If the mapserver folks would like, I would be willing to produce something more in<br>line with some of the howtos.
<br><br>Best,<br>Doug<br></blockquote></div><br>