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. Ignore any 'point' shapes
  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)^2 + (centerY - circumferenceY)^2)
  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.connpad.com/toolbox.htm 

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.connpad.com/toolbox.htm" />
</map>

Written by Chris Ridpath
Jan. 18, 2001