Mapper.js 2.4 allows you to add automatic area highlighting to image maps on your webpages (inc. export to SVG). It uses unobtrusive javascript to keep your code clean. It works in all the major browsers - Mozilla Firefox 1.5+, Opera 9+, Safari and IE6+. On older browsers, it can use "jsgraphics" from Walter Zorn (if installed), else it'll degrade and your visitors won't notice a thing. |
Download "mapper.js" and include it into your webpage.
<script src="wz_jsgraphics.js"></script>
<script src="mapper.js"></script>
"wz_jsgraphics.js" is copyright by Walter Zorn and not part of the distribution!
To get the highlighting just add a class="mapper" to an div surrounded image.
<div>
<img src="..." class="mapper" usemap="..." alt="...">
</div>
To get individual area highlightings add one or more classes to the area.
<map>
...
<area shape="poly" class="noborder icolor00ff00" href="#" coords="...">
...
</map>
To get multiple area selections add one or more id's to the areas rel attribute.
<map>
...
<area shape="poly" id="blue" rel="green,red" href="#" coords="...">
<area shape="poly" id="green" rel="red,blue" href="#" coords="...">
<area shape="poly" id="red" rel="green,blue" href="#" coords="...">
...
</map>
To force a group of areas using the attributes of the initial area.
<map>
...
<area shape="rect" id="black" class="icolor000000 forcegroup" rel="green,red,blue" href="#" coords="...">
...
</map>
* These classes work also in conjunction with <area> objects!
** This class works only in conjunction with <area> objects!
If you want flexibility, use "cvi_map_lib.js" instead of "mapper.js". You can make your maps respond to user actions.
cvi_map.defaultRadius = 0; //INT 0-100 (px radius)
cvi_map.defaultOpacity = 33; //INT 0-100 (% opacity)
cvi_map.defaultBordercolor = '#0000ff'; //STR '#000000'-'#ffffff'
cvi_map.defaultAreacolor = '#000000'; //STR '#000000'-'#ffffff'
cvi_map.defaultNoborder = false; //BOOLEAN
cvi_map.defaultNofade = false; //BOOLEAN
cvi_map.defaultShowcoords = false; //BOOLEAN
cvi_map.defaultDelayed = false; //BOOLEAN
cvi_map.defaultImgsrc = ''; //STR (path&file)
cvi_map.defaultMapid = ''; //STR (id)
cvi_map.add(image, options);
cvi_map.add(document.getElementById("myimg"), { opacity: 25, areacolor: 'ff0000' });
cvi_map.modify(image, options);
cvi_map.modify(document.getElementById("myimg"), { imgsrc: "images/replace.jpg", mapid: "replace_map" });
cvi_map.remove(image);
extAreaOver(image_id, area_id);
extAreaOut(image_id, area_id);
If you need utility functions, use "maputil.js". You can generate SVG files out of Image maps.
makeSVGfromMap(map, options);
<a href="#" onClick="makeSVGfromMap(document.getElementsByName("myimg")[0],false,502,482);">Generate SVG</a>
makeSVGfromMap()
parses the style attribute of <area /> tags for fill and stroke styles to complete the SVG!
scaleMapAreaCoords(map, nw, nh, sw, sh, options);
scaleMapAreaCoords()
opens a window with the source!
Image with class "mapper showcoords noborder iopacity50 icolorff0000" (Coordinates output example).
Image reference (public source): http://flatplanet.sourceforge.net/maps/
This SVG was generated from map data via "maputil.js" (part of distribution).
Generate SVG from map data via "maputil.js".
Image with class "mapper" only.
The colored circles uses multiple area selections through rel="id_11,id_21,id_9...".
The blue and red squares forces the corresponding groups to use their attributes by "forcegroup".
This SVG was generated from map data via "maputil.js" (part of distribution).
Generate SVG from map data via "maputil.js".
Image with class "mapper iborder00aa00 icolor00ff00".
All not blue colored country areas with class "noborder icolor808080".
This SVG was generated from map data via "maputil.js" (part of distribution).
Generate SVG from map data via "maputil.js".
Image with class "mapper noborder iradius16 iopacity50 icolorff0000".
Images used are copyrighted and are used for demonstration only (use the shape data).
In older browsers, the script degrades and your visitors won't notice a thing.
No visible borders with "wz_jsgraphics.js" and Safari < 3.0.
The inspiration for the script came from Dmitry Khudorozhkovs Lightmapper.
Mapper.js and MapUtils.js are distributed under this LICENSE. License permits free of charge use on non-commercial and private web sites only under special conditions (as described in the license). This license equals neither "open source" nor "public domain". There are also Commercial Software Licenses available.
Images used are copyrighted and are used for demonstration only.
cvi.netzgesta.de also visit CVI-lab, S5 Reloaded and AJAX-FilmDB