Pushpin tooltips

Just recently it was brought to my attention that when you hover over a pushpin in Multimap a tooltip appears. For those who are migrating to Bing Maps V7 you may notice this does not happen but want this functionality. There are two ways to go about this. The first is unsupported and requires accessing undocumented properties of Bing Maps and has so far proven to cause bugs. A second approach uses Bing Maps in a somewhat more supported manner and makes use of jQuery to help it out. The general idea is to first assign each pushpin a unique typeName property. The typeName property can be used to set class names on pushpins. Once each of your pushpins have a unique name you can use jQuery to get each pushpin by typeName and then assign a title property to the image. Here is some sample code that does just this:

<html>
   <head>
      <title></title>
      <meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″/>

      <script type=”text/javascript” src=”http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0″></script>
                  <script type=”text/javascript” src=”http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.2.min.js”></script>
                 
      <script type=”text/javascript”>
         var map = null;        

         function GetMap()
         {
            // Initialize the map
            map = new Microsoft.Maps.Map(document.getElementById(“myMap”),
                         {credentials:”Your Bing Maps Key”});

            // Retrieve the location of the map center
            var center = map.getCenter();
           
            // Add a pin to the center of the map
            var pin = new Microsoft.Maps.Pushpin(center, {typeName: “pin1”});
            map.entities.push(pin);
           
            //Set the title property of the image of the pushpin
            $(‘.pin1’).children(‘img’).attr(‘title’,’This is pin 1.’);
         }
      </script>
   </head>
   <body onload=”GetMap();”>
      <div id=’myMap’ style=”position:relative; width:400px; height:400px;”></div>   
   </body>
</html>

Advertisements

5 thoughts on “Pushpin tooltips

  1. Cool. Do you know if its possible to show a tooltip with polylines also?
    Couldnt find a solution because there is no typeName attribute.. Thank you!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s