|
|||||
11. Image mapsIntroduction (click any heading to come here)You have already learned about image markup, but not yet about image maps. These are maps to locations or regions on images that can be treated as buttons or hyperlinks. For example, to locate colleges in Texas, a map of Texas is shown and the user is told to click on the city for a list of colleges there. Line drawings are also popular site navigation elements controlled by image maps because they look less technical and more designed than buttons. ![]() The other half of image map markup is the graphic art itself. We will postpone an in-depth treatment of graphic editors, and their helpful built-ins for image maps, until the Graphics module. Here we will introduce image map markup and how you can determine map coordinates without a graphics editor. Area map for tabsAmazon.com popularized the tabs and now you can expect to see them on most Web shopping sites. There is more to Amazon's use of the tabs than their image maps, but for the present, we will look at how to code image maps by inspecting how these particular tabs were coded. ![]() First the graphic is shown and a new attribute is used for the
<img src="images/tabs.gif"
width="438" height="26"
alt="Tabs" border="0"
usemap="#tabs_nav_map" />
The usemap attribute indicates another location within the HTML page called ![]() The tab graphic and image tag are repeated here to help this example of image map markup stay in context. You can see the entire tabs application on this page.
<img src="images/tabs.gif"
width="438" height="26"
alt="Tabs" border="0"
usemap="#tabs_nav_map" />
The
<map name="tabs_nav_map">
<area shape="rect" href="http://etc" coords="0,1,61,26" />
<area shape="rect" href="http://etc" coords="62,1,126,26" />
<area shape="rect" href="http://etc" coords="127,1,170,26" />
<area shape="rect" href="http://etc" coords="171,1,212,26" />
<area shape="rect" href="http://etc" coords="213,1,253,26" />
<area shape="rect" href="http://etc" coords="254,1,332,26" />
<area shape="rect" href="http://etc" coords="333,1,384,25" />
<area shape="rect" href="http://etc" coords="385,1,437,26" />
</map>
A Shape optionsThe tabs can be defined as hot spots easily by providing coordinates for rectangles. Two additional shapes are possible: circles and polygons. Polygons have at least three sides and up to an unknown number of sides.
<map name="??">
<area shape="rect" coords="11,12,21,22" .... />
<area shape="circle" coords="1,2,3" .... />
<area shape="poly" coords="11,12,21,22,31,32,...." />
</map>
|
![]() |
Look at the status bar below after you have placed the mouse cursor in the approximate center of the red stop light at the left. Center of red light = 38,52 (approx.) Next move your mouse to the right edge of the red circle and note the X (first number) coordinate. Subtract the center point X to get the radius. In our exercise this is approximately a 20 pixel radius. Repeat for the yellow and green circles. | ![]() |
Polygons can have three or more sides. Examples are triangles, stars, outlines of states, and rectangles set at an angle. You may be surprised to read that rectangles are in this list, but when the axes are not 0 or 180 degrees, just code the tilted rectangle as a four corner polygon.
Polygons can have any number of sides and they have the same number of coordinate points that they have sides. Start at any one coordinate and enter the point coordinates in sequence. Think of this as connecting the dots, or outlining the shape. Polygons can be any shape and have any number of points greater than two.
Here are three of the five points in a pentagon already coded. Use your mouse to find the remaining two points. |
![]() |
<img src="images/ImageMapPoly.gif" alt="Poly"
width="112" height="110" border="0"
usemap="#poly"/>
<map name="poly">
<area shape="poly" href="#"
onclick='alert("Poly wants a cracker")'
coords="8,43,55,8,103,43,84,100,26,100" />
</map>
How do you use the browser to locate coordinate points for your image? Besides adding a new attribute, what must you do to find the coordinates using the browser? What are the coordinates needed to map a circle? Describe how you can find the coordinates to create circular area maps.
Image maps are efficient and easily coded, but it is not the only way for you to have images as buttons, or hot spots within images. We will review images as buttons then introduce a style sheet method of mapping.
Single images, and several images organized in a table can be used within a hyperlink <a></a> container. You may remember this example and the markup it required.
<a href="#top"> <img src="images/top.gif" border="0" height="8" width="18" /> top of page </a>Resize your window and try it out.
You will learn the details of absolute positioning when we study style sheets, but the general technique will be introduced here briefly. Images can be positioned exactly on the page, even overlapping other images or text. And because images can be hyperlinks (like top of page), you have sufficient control to do the work of image maps with individual areas as single graphics that are positioned using styling.
Here are the style sheet topics related to image positioning: