This week's tutorial explains the syntax for the ImageMap extension of the MediaWiki software, which allows images and sections thereof, of any shape and size, to link to any type of page link that can be linked to via text (any valid wikilink, interwiki link, or external link).
A basic understanding of image syntax is assumed.
An ImageMap does not behave the way a normal image does, where clicking anywhere on an image opens its image description page. Instead, with an ImageMap, clicking on the image is the equivalent of clicking on a link; different sections of the image may link to different pages, including external links. ImageMap should generally only be used with free images (that is, those that do not fall under the non-free content criteria), because creating an ImageMap can be regarded as a substantial modification of an image.
ImageMaps are generally used within templates, where it is desirable to have images or icons link to particular pages or sections of a page, and in portals, where it links icons for related portals to that portal and links the logos of various projects in the interwiki section to their respective projects. If ImageMap does not add to the presentation of a template, portal, or article, it should probably not be used, since the ideal behaviour—for transparency with image licensing—is to have the image link to the description page.
To summarize:
To create an ImageMap, one can use either the tags <imagemap>
and </imagemap>
, or the magic word (and ParserFunction) {{#tag:imagemap| }}
. The <tag> format is generally preferable (a good practice) for simple ImageMaps, but does not (currently) function properly with template parameters, magic words, or ParserFunctions. In this case, the {{#tag}} format is a simple and effective workaround, which replaced older, usability-troublesome CSS workarounds for templates that created images linked to alternate pages, such as {{click}}.
To summarize:
<imagemap>
and </imagemap>
, or {{#tag:imagemap|
and }}
.The first line of any ImageMap must be a line specifying the image being used. If no image is specified, or the image that is specified does not exist, then the ImageMap will produce the following error message:
Error: Image is invalid or non-existent.
Note, however, that there must be a linebreak after the imagemap tag (of either form) and before this line. This image code is identical in syntax to normal image syntax, albeit without the surrounding square brackets ([[ ]]
). All of the basic image syntax and extended image syntax applies, though options such as thumb
may not be fully supported by ImageMap. The text provided as a comment in the image syntax on this line is not visible except as alternative text when the image is unavailable, except for options such as thumb
which might use it.
[[Image:WikipediaSignpostHead.svg|100px]]
, the ImageMap code for the first line would beImage:WikipediaSignpostHead.svg|100px
To summarize:
[[
and ]]
from around the image syntaxAfter the first line, any valid lines are acceptable. Usually the second line, and perhaps more following it, contain the area or areas which the ImageMap uses to map to the image. An ImageMap must have at least one area, or default target, specified, or it outputs an error message like the following:
Each line that describes an area can be subdivided into three parts: the type of area, numerical parameters for that area as necessary, and a valid wikilink or external link. These parts are separated on the line by spaces. When hovering over an area, the link destination, or the alternate text (if provided), is displayed as the tooltip when applicable.
Numerical parameters often take the form of coordinates; these coordinates are the number of pixels from the upper-left-hand corner given the default size of the image. When a 150px-wide image is scaled to 50px, the upper-right-hand corner will be designated 150 0
despite the image as rendered only being 50px wide.
When two or more areas overlap, the area specified first in the code takes precedence.
There are four types of area that can be used. For the more complex areas, it is easiest to use the visual ImageMap editor on the toolserver:
default
and the link. It specifies a default target for the image where no areas are specified which overrides the default behaviour of no link for otherwise unlinked areas. Most simple ImageMaps with a single target should use only this type for simplicity. This type should only be specified once, and should be the last type specified by order.default [[Wikilink|Tooltip text]]
rect
should be specified, and then two points are specified using four numbers separated only by spaces. The first two numbers correspond to the top-left corner of the rectangle, and the second pair correspond to its bottom-right corner. The number pairs are distances, in pixels, first horizontally and then vertically from the top-left pixel of the image, relative to its default size. For example, the top-left pixel of the image has the coordinates 0 0
, while the pixel two to the right and one downwards from it would be 2 1
. After these coordinates are specified, any valid link, in normal wiki syntax, is used.rect 0 0 150 150 [[Wikilink|Tooltip text]]
circle
. After specifying the coordinates for the centre of the circle as for the corner of a rectangle, a third single number specifies the radius of the circle, in pixels. After this is specified, any valid link, as for the rectangle, is used.circle 100 100 50 [[Wikilink|Tooltip text]]
poly
allows one to specify a polygon as an area by specifying the coordinates for each point of the polygon in turn, using the same method used to define points for the rectangle. Irregular shapes may therefore be properly mapped. When polygons are defined, they must be placed before any other shapes in the code. The number of points used should be kept to a minimum, especially as polygons with many points sometimes do not work. Polygons with fewer than 20 points should always work. For more complex shapes, using multiple overlapping polygons is an effective workaround and helps simplify each shape. After the last point, any valid link can be used.poly 0 0 0 150 150 0 [[Wikilink|Tooltip text]]
Since images should, as a good practice, include a link to the image description page, ImageMap includes, by default, an information icon on the image linking to the image description page. This by default displays on the bottom-right of an image, but can be changed by using desc
and a location: any of top-right
, bottom-right
, bottom-left
, top-left
, or none
to disable it completely.
desc
parameter allows you to change the location of the information icon, or disable it.
desc none
Once all of the elements have been determined, they can be placed within the container of choice, separated by linebreaks. The following ImageMap demonstrates valid syntax:
<imagemap> File:Bad Title Example.png|275px|border|This is used as alternate text. #Note that in the above line, the border style is invoked. # Polygons appear first in the code, always. poly 14 186 25 219 52 219 63 186 [http://www.wikipedia.org This link is polygon-shaped, and uses an external link.] rect 107 32 256 182 [[Earth|This rectangle links to the Earth article.]] circle 85 135 12 [[Circle|This area is a circle.]] desc none </imagemap>
The code produces the following:
The following are helpful tools related to ImageMap:
Discuss this story