When your site has web pages with geographical maps, sometimes it is nice to make the regions of the map clickable. Imagine that you have a political map of Western Europe. It would be nice to make the countries clickable, so that when a user clicks a country, he would go to a page that has political information (e.g. history) about the country. We can use HTML image-maps to achieve this, but the shapes of countries are irregular. How can we turn an irregular shape into a clickable region? Keep reading.
Let me first briefly explain what an HTML image-map is.
An image-map is an image with clickable regions. Three HTML elements are used to create image maps. They are the IMG element, the MAP element, and the AREA element. Consider the following hypothetical example:
First you have the IMG tag. In this tag there has to be a usemap attribute, which provides the connection between the IMG tag and the MAP tag. Its value is the ID of the MAP element preceded by the # symbol. Next you have the MAP element, which has a start and end tag. This element must have an ID whose value must be the same as the usemap value, but without the # symbol. The content of the MAP element is the AREA elements. Each area has a shape attribute and a coordinates attribute.
The shape describes the clickable regions and it can be a rectangle, circle, or a polygon. If it is a rectangle then the first two coordinates are the coordinates of the left-top corner of the rectangle and the last two coordinates are the coordinates of the right-bottom corner of the rectangle. If it is a circle, then the first two coordinates are the coordinates of the center of the circle and the last coordinate (value) is the radius of the circle. If it is a polygon then the coordinates are in consecutive pairs, and each pair represents the coordinates of a vertex of the polygon.
These coordinates are measured with reference to the left-top corner of the image and not the left-top corner of the web page. If you want a region to result in a new web page after clicking, then you need to give the AREA element an href attribute. You can also give the AREA element an ALT attribute so that when the user's mouse pointer hovers over it, a tool tip appears, indicating what the user will see after clicking.