Bing Maps v7 Ajax Hacks: Pushpin Tooltips via Html Title Attribute

10. July 2011

The Bing Maps v7 Ajax control is still a bit lacking in functionality, and good for us it’s written in JavaScript so it’s easy to extent and hack. The following hack is an “unsupported” method of adding Tooltips to Pushpins by making use of the HTML Title attribute.

BingMaps7HackPushpinTooltip

The Google Maps API already has a “setTitle” method on Markers to add a Tooltip to the pins plotted. Now, thanks to this hack, the same can be done using the Bing Maps v7 Ajax control.

Here’s a full sample page that adds a map with pushpin and sets up the pushpin to have a Tooltip:

<!DOCTYPE html>
<html>
   <head>
      <title></title>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <script src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
      <script type="text/javascript">
         var map = null;

         function initMap()
         {
            // Initialize the map
            map = new Microsoft.Maps.Map(document.getElementById("myMap"), {credentials:"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);


            // Add the pushpin to the map
            map.entities.push(pin);



            // Now that the Pushpin has been added to the Map,
            // we can implement the hack to add the Tooltip
            
            // Set the Pushpin's Tooltip via setting its HTML Dom
            // Title Attribute.
            pin.cm1001_er_etr.dom.setAttribute('title', 'Pushpin Title');
         }
      </script>
   </head>
   <body onload="initMap();">
      <div id='myMap' style="position:relative; width:500px; height:500px;"></div>
   </body>      
</html>

Warning: Like I said, this is a hack and it relies on accessing part of a “non-public” API within the control. If the Bing Maps team decides to rename “cm1001_er_etr.dom” in a future update/release of Bing Maps v7 then this code will stop working.

Bing Maps ,

Comments

7/11/2011 6:04:37 AM #
This is the right blog for anyone who wants to find out about this topic. You realize so much its almost hard to argue with you
7/11/2011 1:36:54 PM #
Bedankt voor dit  artikel. Ik vond het erg interressant!
7/11/2011 4:08:30 PM #
Interesting topic, regards
7/11/2011 4:58:02 PM #
All I need to say is, yes! Yes! Yes! Youre so correct. I desire to get behind this so significantly. You speak with so a lot authority, so significantly spirit, I feel as though youve undoubtedly hit the nail on the head. Great job with this. Please maintain brining us more due to the fact we require much more of your sort of blogger.
7/12/2011 8:00:38 AM #
Nice blog! This is a terrific thread, im ecstatic I stumbled upon it. Ill be back down the track to check out other posts that you have on your blog. Thank u!
7/12/2011 2:34:36 PM #
Keep 'em coming... you all do such a great job at such Concepts... can't tell you how much I, for one appreciate all you do!
7/12/2011 3:43:34 PM #
I have read up to the end of the super-
7/12/2011 4:26:56 PM #
I have read up to the end of the super-
7/12/2011 4:49:33 PM #
much like the literature
7/12/2011 4:55:28 PM #
was read to the end of the super
7/12/2011 6:44:28 PM #
much like the literature
7/12/2011 6:49:16 PM #
much like the literature
7/12/2011 7:10:56 PM #
much like the literature
7/12/2011 10:48:54 PM #
You should be a part of a contest for one of the best sites on the web. We would entirely advocate this website! In addition, I brought up yourself on my very own Bebo webpage, ideally this is cool.
7/12/2011 11:16:31 PM #
Hello There. I found your blog using msn. This is an extremely well written article. I will make sure to bookmark it and return to read more of your useful information. Thanks for the post. I will definitely comeback.