Blue Theme Orange Theme Green Theme Red Theme
 
Home | Forums | ASP.NET 2.0 Tutorials | Web Services | How Do I...? | Class Browser | WPF Quick Starts | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Team Foundation Server Hosting
Search :       Advanced Search »
Home » JavaScript » Image mapping in JavaScript

Image mapping in JavaScript

Through this article you will learn how to map multiple images in JavaScript.

Author Rank :
Page Views : 6974
Downloads : 0
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
Nevron Gauge for SharePoint
Become a Sponsor
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 

Introduction:

 

In this article I'll explain how image maps work, how they are created and what they're used for.

 

What is image map?

 

An image map is one image with multiple clickable areas.

 

How to map multiple images?

 

First of all we load an image on which we want to map multiple images and also set the height and width of the image.

 

<img src ="Water-lilies1.jpg" width ="150" height ="130" alt="waterlilies" usemap="#waterlilies"/>

 

To map the image use the following stetement within the <map> and </map> tag like this:

 

<map id ="waterlilies" name="waterlilies">

     <area shape ="rect" coords ="0,0,10,10"onMouseOver="writeText('Hi !')"

     href ="Blue hills.jpg" target ="_default" alt="blue" />

</map>

 

There are three different shape used in image map:

 

  • Rect
  • Circ
  • poly

rect: It is short for retangle. You'll need two different co-ordinates (Top right and bottom left).

 

For example: shape ="rect" coords ="0,0,10,10"

 

Circ: It is the easiest of all. All you need is the centre co-ordinate (the point in the centre of your shape) and it's radius size.

 

For example: shape ="circ" coords ="30,100,10"

 

Poly: It is used for the polygon. So if you going to have a pentagon, then you list all five co-ordinates. All co-ordinates should have listed in order.

 

For example: shape ="poly" coords ="40,50,55,60,70,80,85,90,145,126"

 

Example: In this example we have to take three images for mapping and one image for clip board. We set the co-ordinates and shape of every image within the <area> tag. See the following example.

 

<html>

  <head><title>Image map</title>

      <script type="text/javascript">

      function writeText(txt)

      {

      document.getElementById("desc").innerHTML=txt

      }

      </script>

  </head>

  <body>

  <img src ="Water-lilies1.jpg" width ="150" height ="130" alt="waterlilies" usemap="#waterlilies"/>

    <map id ="waterlilies" name="waterlilies">

       <area shape ="rect" coords ="0,0,10,10"onMouseOver="writeText('Hi !')"

       href ="Blue hills.jpg" target ="_default" alt="blue" />

       <area shape ="circ" coords ="120,20,10"onMouseOver="writeText('Hello! Puru')"

       href =Sunset.jpg target ="_blank" alt="sunset" />

       <area shape ="poly" coords ="40,50,55,60,70,80,85,90,145,126"

       onMouseOver="writeText('Bye !!!!')"

       href =Winter.jpg target ="_blank" alt="winter" />

    </map>

0    <p id="desc"></p>

  </body>

</html>

 

Output: You will see the output like this:

 

 

 

Figure 1: Mapped image.

 

Move the cursor at another place you will see something as:

 

 

 

Figure 2: At this point one image is mapped.

 

See both figure (figure 1 and 2). When you put mouse over the image then you will see the different message (only on mapped area) and if click over them then you see the different images like as:

 

 

 

Figure 3:

 

Move the cursor at another place you will see different message like this:

 

 

 

Figure 4: Another image is map.

 

When you click on this co-ordinate you will see the following image.

 

 

 

Figure 5:

 

Conclusion:

 

Image mapping is very easy to create and very professional looking when used with a good graphics.

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Purushottam Rathore

I am working as a Software Developer and has 4 years of experience on Microsoft Technology and having a Master Degree in Computer Application. I really like to work in the .NET platform. and working with ASP.NET 2.0/3.5, Web Services, WPF, WCF, Silverlight, AJAX, JavaScript, JQuery, Ado.net, MsAccess, SQL Server 2005/2008.

Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Nevron Gauge for SharePoint
Become a Sponsor
 Comments
Proportional Image Mapping? by Eliyahu On February 28, 2010
Hi. I am trying to integrate image mapping with a panning and zooming script (shiftzoom.js). Obviously, hostpots defined by absolute x,y coordinates will not work on a dynamically resizable image - the only thing that would work is some kind of proportional percentage-based coordinate mapping (i.e., X% from the left, Y% from the top). The HTML coords property doesn't support this. Do you know if it is possible to implement this in javascript?
Thanks
Reply | Email | Modify 
6 Months Free & No Setup Fees ASP.NET Hosting!
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.