Doug.<br><br>Thanks. That'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> <<a href="mailto:williams@websawyer.com">williams@websawyer.com</a>> 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. 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!!. I had to feel my way through trying to piece<br>together bits and pieces of scattered information, 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. I never
<br>did find any response to that person that showed a working example. 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. I already had one OUTPUTFORMAT in my mapfile to
<br>improve the quality of images generated by mapserver. 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). It would be possible to use more than<br>one mapfile rather than resetting the outputformat used, but it is not necessary. More on<br>outputformats in a minute. Also it is necessary to define a CLASSITEM for the layer that you want to
<br>use to define your imagemap. 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. The other<br>necessary steps take place in the php script. So hear is the mapfile stuff:<br><br> OUTPUTFORMAT<br> NAME imagemap
<br> DRIVER imagemap<br> FORMATOPTION "MAPNAME=map_test"<br> FORMATOPTION "TITLE='' # this gets stuffed properly, you do not need to reference anything<br> # on the right side of the = sign
<br> # in fact, you do not need this option at all. But maybe<br> # someday you will?<br> MIMETYPE "text/html" # this option is also not needed!
<br> END<br><br>OUTPUTFORMAT<br> NAME jpeg<br> DRIVER "GD/JPEG"<br> MIMETYPE "image/jpeg"<br> IMAGEMODE RGB<br> EXTENSION "jpg"<br> FORMATOPTION "QUALITY=100"<br>END<br><br>The first output format is used to generate the imagemap, the second is used to generate the actual
<br>map. The script resets the format that is used. Show you that in a second. I don't really think the<br>mimetype statement is necessary, but I have seen it used so I include it here. 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. I won'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 <map>, 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). (Don't formatoption<br>suppress="yes", or you will not get the areas in your <map>.)<br><br>So hear is my layer definition in my map file:
<br><br> LAYER<br> NAME "lakes" # this is a bad layer example because the polygons are small and so<br> # the imagemap driver generates some bad <map> areas. I'll process these
<br>out.<br> # Typically one would likely be using this with maps that produce<br> # larger features than a few worldwide lakes that are being squished to mere
<br>dots<br> # in an image the size and way I am doing here.<br> DATA esri/world/lakes<br> STATUS on<br> TYPE polygon<br> CLASSITEM "NAME" # this is the attribute field to list in the 'title' for each <map> area
<br> CLASS<br> NAME "Lakes"<br> COLOR -1 -1 -1<br> OUTLINECOLOR 200 200 50<br> END<br> 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. 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. 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 "TITLE=[NAME]" 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> 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. 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="/path/to/mapfile/directory";<br> $map_file="mapfile.map";<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. 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->draw();<br> $htmlmap->saveImage("/path/to/someplace/the/script/can/write/test.html", $imagemap);<br><br>This will generate a text file on the server.<br>test.html will be the:<br>
<map name="map_test"><br> with areas and coords and titles<br> </map><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->selectOutputFormat("jpeg");<br>and draw as before:<br> $image=$map->draw();<br> $image_url=$image->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. I add the imagemap to the html output like this:
<br> <body><br><? require "/path/to/somplace/the/script/can/write/test.html" ?><br><br>I just plop it in right after I send the html <body> tag. Then you need to display the image in an<br><img> tag. The standard mapserver way is to place the image in a form <input> tag, but I have not
<br>tried this as I read stuff stating that imagemaps do not work in form <input type=image> elements<br>(makes sense since there is no place to associate the needed usemap). 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. 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><img src=<? echo $image_url; ?> usemap="#map_test" width=<? echo $map->width; ?> height=<?<br>echo $map->height; ?> border=0><br><br>or however you like to code. 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. View the page source to see if the <map> looks like what you expect it to look like.<br><br>Those are the basic pieces. Sorry it is not a very well laid out description. If you have any questions,
<br>feel free to ask. I am using a slightly more recent version of mapserver, but believe this has been<br>around a while. 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>