Image Map Conversion

This document describes how to convert a server-side image map file into a client-side image map file.

Background

Server-side image maps are normally stored in a standard ASCII text file. There are 2 common formats for the map files, NCSA (Netscape) and CERN. Each format associates active areas of an image (hot spots) with a URL.

Client-side image maps are described in HTML code using the 'AREA' element. AREA elements have the 3 attributes, SHAPE, COORDS and HREF, that correspond to the shape, coordinates and URL parameters of the server-side image map. Example:

<area shape="POLY" coords="185,0,355,0,295" href="education.html" alt="Education" />

Conversion Algorithm

  1. Read in a shape/coordinate/URL line. Each line starts with a shape name and will end just prior another shape name.
  2. Ignore any comment lines (they start with a '#')
  3. Parse the shape name, coordinates and URL from the line
  4. Convert the 'point' shapes to rectangles with an area of 1 pixel.
  5. Convert the shape names 'polygon' to 'poly' and 'rectangle' to 'rect'
  6. Convert any CERN style circle coordinates to NCSA style circle coordinates using the formula: square root of ((centerX - circumferenceX)squared + (centerY - circumferenceY)squared)
  7. Write out a MAP start element to the client-side image map file
  8. Write out the AREA elements for the client-side image map with the SHAPE, COORDS and HREF attributes set to the shape, coordinates and URL values.
  9. Write out a MAP end element to the client-side image map file

Example

Server-side Image Map File

# testmap

rectangle (5,9) (110,43) http://www.yahoo.com/
polygon (111,9) (220,43) http://www.infoseek.com/
circle (415,77) 16 http://www.hello.com/
point (45,45) http://www.w3c.org/

Client-side Image Map File

<map name="testmap.map">
<area shape="rect" coords="5,9,110,43" href="http://www.yahoo.com/" />
<area shape="poly" coords="111,9,220,43" href="http://www.infoseek.com/" />
<area shape="circle" coords="415,77,16" href="http://www.hello.com/" />
<area shape="rect" coords="45,45,46,46" href="www.w3c.org" />
</map>

Written by Chris Ridpath
Feb. 2, 2001