HTML
  Home arrow HTML arrow Page 2 - Clickable Geographical Map Regions
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
HTML

Clickable Geographical Map Regions
By: Chrysanthus Forcha
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-06-03

    Table of Contents:
  • Clickable Geographical Map Regions
  • Relationship between Geographical Regions and Image-Maps
  • Code Explained
  • Caution, Animation, Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Clickable Geographical Map Regions - Relationship between Geographical Regions and Image-Maps


    (Page 2 of 4 )

    Realize that the outline of a geographical map looks like an irregular polygon. So to make a region of a geographical map clickable, think of its outline as an irregular polygon, then look for the coordinates of the vertices of this outline. In the HTML document, these coordinates will form the coordinates of an AREA element with a polygon shape. The AREA element is, of course, part of the image-map. To make all the geographical regions of the map clickable, the MAP element will consist of AREA elements with polygon shapes and each AREA element will have the coordinates of the region.

    Creating coordinates

    If you look at the map of any country, you will notice that the number of vertices and, hence, the number of coordinate pairs are many. In this section, I show you how you can get the coordinates using JavaScript. We shall use the map of Western Europe below to illustrate this.




    We shall make the regions of Portugal, Spain and France clickable.

    In terms of tools for this project, you need a text editor (notepad) and a browser.

    Using your text editor, copy and paste the following and save the file with the name "coords.htm" in a directory. In this same directory, save the image of the map of Western Europe with the name europeMap.jpg (beware of the image type).


    <html>


    <head>

    <style type="text/css">

    body {margin:0px; padding:0px}

    </style>

    <script type="text/javascript">

    var coordStr = ""

    function createCoords(event)

    {

    x=event.clientX;

    y=event.clientY;


    if (coordStr == "")

    {//the first time we start without a comma

    coordStr = coordStr + x + "," +y ;

    }

    else

    {

    coordStr = coordStr + "," + x + "," +y ;

    }

    }

     

    function showCoords(event)

    {

    if (event.button==2)

    {

    myWindow=window.open();

    myWindow.document.write(coordStr);

     

    //reset the string

    coordStr = "";

    myWindow.focus();

    }

    }

    </script>

    </head>


    <body onclick="createCoords(event)" onmousedown="showCoords(event)">

    <img src="europeMap.jpg">

    </body>


    </html>

    More HTML Articles
    More By Chrysanthus Forcha


       · A secret to make irregular image shapes clickable.A secret to give links to...
       · Excellent article! I'm new at this; can anyone add how to highlight the clickable...
     

    HTML ARTICLES

    - Comparing Browser Response to Active Client ...
    - Testing Browser Response to Active Client Pa...
    - Active Client Pages: Completing the Code for...
    - ACP and Browsers: Setting up an Example
    - How Browsers Respond to Active Client Pages
    - Completing a Tree with Active Client Pages
    - HTML Form Verification and ACP
    - Building an ACP Tree
    - Completing an ACP 3D HTML Table Image Gallery
    - Building an ACP 3D HTML Table Image Gallery
    - A Multiple Page Image Gallery with Active Cl...
    - Building an Image Gallery with Active Client...
    - Concluding a Menu for All Browsers
    - A Vertical Menu for All Browsers
    - Downloading Long HTML Pages with ACP







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek