After you have the coordinates written down, you're ready to create an HTML imagemap. The following HTML code is required to start any imagemap: <map >
Keep in mind that you can use whatever name you want for the id of the <map> tag, although it helps if you make it as descriptive as possible. If skateparkmap doesn't describe the image you're using very well, feel free to change it. Next on the agenda is an <area /> tag for each region of the image. Following is an example of a single <area> tag that is used in the skatepark imagemap example: <area shape="rect" coords="536, 24, 610, 89" href="skatepark_spikepipe.jpg" alt="Spike Pipe" /> This <area /> tag has four attributes, which you will use with every area you describe in an imagemap:
Every distinct clickable region in an imagemap must be described as a single area, which means a typical imagemap consists of a list of areas. After coding the <area /> tags, you are done defining the imagemap, so wrap things up with a closing </map> tag. The last step in creating an imagemap is wiring it to the actual map image. The map image is placed on the page using an ordinary <img /> tag. However, there is an extra usemap attribute that is coded like this: <img src="/books/4/158/1/html/2/skatepark.png" alt="Nashville Public Skatepark" title="Nashville Public Skatepark" usemap="#skateparkmap" style="border:none" /> When specifying the value of the usemap attribute, use the name you put in the id of the <map> tag (and don't forget the # symbol). In the listing I also included the style attribute to turn off the border around the imagemap, which you may or may not elect to keep in imagemaps of your own.
Listing 10.3 shows the complete code for the skatepark imagemap sample web page, including the imagemap and all of its areas. Listing 10.3. The <map> and <area /> Tags Define the Regions of an Imagemap<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>Nashville Public Skatepark (Concrete Wave Country)</title> </head> <body> <h1>Nashville Public Skatepark (Concrete Wave Country)</h1> <p> Below is a map of Nashville's public skatepark, also known as Concrete Wave Country. Drag the mouse over the map and click to learn more about each area and obstacle. </p> <p style="text-align:center"> <map > <area shape="rect" coords="536, 24, 610, 89" href="skatepark_spikepipe.jpg" alt="Spike Pipe" /> <area shape="rect" coords="461, 43, 535, 78" href="skatepark_coachscorner.jpg" alt="Coach's Corner" /> <area shape="rect" coords="342, 170, 422, 218" href="skatepark_barnstormer.jpg" alt="Barnstormer" /> <area shape="rect" coords="392, 69, 460, 114" href="skatepark_mitchellsmeadow.jpg" alt="Mitchell's Meadow" /> <area shape="rect" coords="311, 87, 391, 118" href="skatepark_miabowl.jpg" alt="MIA Bowl" /> <area shape="circle" coords="510, 94, 30" href="skatepark_bubbabowl.jpg" alt="Bubba Bowl" /> <area shape="circle" coords="499, 135, 25" href="skatepark_flumezoom.jpg" alt="Flume Zoom" /> <area shape="circle" coords="98, 243, 28" href="skatepark_orangepeel.jpg" alt="Orange Peel" /> <area shape="poly" coords="323, 134, 309, 154, 343, 166, 358, 139, 345, 119, 311, 116" href="skatepark_horseyhip.jpg" alt="Horsey Hip" /> <area shape="poly" coords="227, 229, 254, 243, 273, 267, 247, 281, 206, 278, 203, 244" href="skatepark_devansdivide.jpg" alt="Devan's Divide" /> </map> <img src="/books/4/158/1/html/2/skatepark.png" alt="Nashville Public Skatepark" alt="Nashville Public Skatepark" usemap="#skateparkmap" style="border:none" /> </p> </body> </html>
Figure 10.8 shows the imagemap in action. Notice that Microsoft Internet Explorer displays the link address for whatever area the mouse is moving over at the bottom of the window, just as it does for "normal" links. Additionally, the alt text for an area is displayed on the imagemap if you pause with the mouse over the area. Figure 10.8. The imagemap defined in Listing 10.3 as it appears on the web page.
If you click where the alt text is shown in Figure 10.8, the image named skatepark_flumezoom.jpg opens in the browser. In fact, Figure 10.9 shows an image of my friend Paul Sexton riding the Flume Zoom that appears after the Flume Zoom obstacle is clicked on the imagemap. Figure 10.9. Each area on the skatepark imagemap links to a photo of that particular skateboard obstacle. |