phpmapscript imagemap attributes

Doug Williams williams at WEBSAWYER.COM
Wed Jun 27 16:50:37 PDT 2007


Hi All, Jeff, Assefa, 

I have made a phpmapscript to generate an imagemap for my drawn map so when mousing over the 
map information about the shp below the mouse cursor is displayed beside the cursor.  I like the way 
it works,

  http://www.wildweb.org/imagemap/

except for a couple of questions!  I am using version 4.8 on linux.

1) Some of the polygon coords for the map areas begin with a comma, such as

<map name="map_test" width="600" height="300">
<area onMouseOver="handleClick(event,'boxinfo','show it',' NAME '); return false;" 
onMouseOut="handleClick(event,'boxinfo','hide it',''); return false;" title="" shape="poly" coords=" 
96,70, 96,69, 95,68, 105,68, 105,73, 101,73, 101,74, 95,74, 95,73, 93,73, 94,72, 93,72, 93,70, 
92,70, 92,69, 93,70, 95,70, 96,70, 96,71, 95,71, 95,72, 96,71, 96,70" />
<area onMouseOver="handleClick(event,'boxinfo','show it',' NAME '); return false;" 
onMouseOut="handleClick(event,'boxinfo','hide it',''); return false;" title="" shape="poly" coords=", 
95,69" />
......
</map>

Notice how the coords for the second area begin with a comma.  Does that mean I have a bad shape 
file?  Those commas seem problematic for some browsers when using the imagemap.  If I delete the 
commas by brute force and then display the edited html file, the imagemap works properly in all the 
browsers I have checked, although I guess that the areas with just two coords are not good...


2) I cannot figure how to get the attribute data for the shape.  The cgi version of mapserver describes 
using a template, but where the cgi version describes the use of templates for other tasks, I have not 
found them useful for phpmapscript version, nor am I using, for this script, the header and footer 
templates as described in the cgi version imagemap creation tutorial, as setting the OUTPUTFORMAT 
driver to imagemap along with the correct FORMATOPTIONs generates everything as described in the 
cgi version tutorial, except I am not understanding how to get the attribute data other than the shp 
coords.

The cgi version says the the mode would need to be set to nquery.  I think this means that 
phpmapscript does a drawQuery().  Attempting this results in:

Warning: [MapServer Error]: msDrawQueryMap(): Unable to initialize image. in /.../index.php on line 
184
Fatal error: Call to a member function on a non-object in /.../index.php on line 185

It does not seem necessary to use drawQuery().  draw() provides the coords as desired (w/ the 
question about the commas above).

 My belief is that I would grab the attribute data in the FORMATOPTION statement.  Am I on the right 
track?  Does this capability exist as part of the OUTPUTFORMAT imagemap driver in phpmapscript?

This is my OUTPUTFORMAT to create the imagemap:
 OUTPUTFORMAT
     NAME imagemap
     DRIVER imagemap
     FORMATOPTION "MAPNAME=map_test"
     FORMATOPTION "POLYHREF="
     FORMATOPTION "POLYMOUSEOUT=handleClick(event,'boxinfo','hide it',''); return false;"
     FORMATOPTION "POLYMOUSEOVER=handleClick(event,'boxinfo','show it','%NAME%'); return false;"
     FORMATOPTION "TITLE="
     MIMETYPE "text/html"
  END

The %NAME% was based on the sections discussing cookie variables and such, and NAME just ends 
up displayed without the % chars.  [NAME] as shown in the cgi version doc produces [NAME] as 
output.  I have tried escaping the ' char with \, but that results in an error.  Is there a code to put in 
the FORMATOPTION statement to obtain attribute data?

Does the layer definition matter?  Here is my layer definition:
    LAYER
      NAME "lakes"
      DATA esri/world/lakes
      STATUS on
      PROJECTION
          "proj=latlong"
      END #projection
      TYPE POLYGON
      METADATA
        "DESCRIPTION" "Lakes"
        "RESULT_FIELDS" "NAME SURF_ELEV DEPTH"
      END
#      HEADER "lakes_header.html"
#      FOOTER "lakes_footer.html"
      TEMPLATE ""
      CLASS
        NAME "States"
        OUTLINECOLOR 0 0 0
      END
    END

I have tried this with a couple of different layers and like the imagemap result (aside from not 
understanding why some area coords begin with a comma), but without the attribute data I am not 
sure what to do with it!

All ideas would be much appreciated,

Doug



More information about the MapServer-users mailing list