.. _imagemaps:
*****************************************************************************
HTML Imagemaps
*****************************************************************************
:Author: David Fawcett
:Contact: david.fawcett at gmail.com
:Last Updated: 2008-10-08
.. contents::
:depth: 2
:backlinks: top
Introduction
============
The shpxy method of creating imagemaps uses MapServer query functionality to
build a html imagemap. Just like a regular MapServer query, you send a query
request and MapServer uses the templates to build a block of html that it sends
back to the browser. The first example shows you how to build an imagemap
based on a point layer. An example template for a polygon layer is also
included.
**Components**
- MapServer mapfile
- query template file
- query header template
- query footer template
Mapfile Layer Definition
===========================
Here is a simple mapfile for our example
::
MAP
NAME "myMapFile
STATUS ON
SIZE 200 200
EXTENT 178784 4804000 772653 5483346
UNITS METERS
STATUS ON
SHAPEPATH "/web/maps/data"
IMAGECOLOR 255 255 255
WEB
IMAGEPATH "/web/maps/tmp/"
IMAGEURL "/maps/tmp/"
END
QUERYMAP
STATUS ON
STYLE NORMAL
END
LAYER
NAME "sites"
STATUS DEFAULT
TYPE point
DATA 'aqiAreas'
TEMPLATE "bodytemplate.html"
HEADER "imapheader.html"
FOOTER "imapfooter.html"
END
END
You can see that we have a mapfile with one point layer, and that it
contains references to three query templates.
Templates
==============================
In MapServer, the query header and footers get processed only once. The
main query template, 'bodytemplate.html' in this example, gets processed
once for each record in the record set returned by the query.
Point Layers
-------------
Here is the query header, 'imapheader.html'. It creates the opening tag
for your html imagemap.
::
Polygon Layers
---------------
Here is a query template for a polygon layer
::
Request URL
==============================
To get the imagemap, you need to send a GET or POST request to MapServer
with several URL variables defined. The below URL tells MapServer where
the mapfile is located, what layer we are querying, and that we are
using nquery mode to return multiple results.
::
http://myurl/cgi-bin/mapserv?map=/web/maps/demoimap.map&qlayer=sites&mode=nquery&searchmap=true
Additional Notes
=================
If you use separate map files to generate your imagemap and your map
image, make sure that the EXTENT and SIZE specified in both mapfiles
are identical. If they are not, your features will not align properly.
More Information
=================
`Steve Lime's SHPXY Example`_
.. #### rST Link Section ####
.. _`Steve Lime's SHPXY Example`: http://maps.dnr.state.mn.us/cgi-bin/mapserv56?map=/usr/local/www/docs_maps/eco/rsg/search/search_example.map&qlayer=county&mode=nquery&searchmap=true