HERE Maps API - How to add an HTML InfoBubble on the map
m (Jasfox - Add category) |
hamishwillee
(Talk | contribs) m (Hamishwillee - Remove redundant categories) |
||
| Line 1: | Line 1: | ||
| − | + | [[Category:Nokia Maps]][[Category:Code Snippet]][[Category:JavaScript]] | |
{{Abstract|This article explains how to add an info bubble on the map. The info bubble can contain any HTML content.}} | {{Abstract|This article explains how to add an info bubble on the map. The info bubble can contain any HTML content.}} | ||
Revision as of 07:57, 25 January 2012
This article explains how to add an info bubble on the map. The info bubble can contain any HTML content.
Article Metadata
Compatibility
Article
Contents |
Introduction
An infoBubble must have a nokia.maps.geo.Coordinate and content which can be either provided as a string or as a nokia.maps.search.Location object.
API defines:
Extends nokia.maps.map.component.Component.
new nokia.maps.map.component.InfoBubbles ()
Options Interface defining the info bubbles' options (keys)
Prerequisites
Nokia Maps API supported web browser (basically any modern web browser)
Important about Maps credentials
Nokia provides several services options within the Maps API offering. The service is free to use, but if you complete the free registration process and obtain authentication and authorization credentials, your application will have priority access to the service and will thus avoid a potential performance penalty. Please read the Location API Business Models and Usage Restrictions page to decide which business model best fits your needs. Authentication requires unique Maps API credentials, namely an AppId and a token. You can get these credentials from the Nokia Developer API Registration page.
Adding an Infobubble directly onto the Map
In this example we will create one infoBubble with video content from YouTube. Location is mumbai, where a info bubble would be shown with out youtube video.
<html>
<head>
<script type="text/javascript"
src="http://api.maps.nokia.com/2.0.0/jsl.js" charset="utf-8">
</script>
<link rel="stylesheet" href="style.css" />
</head>
<body style = "width:100%; height:100%;">
<div id="map" style="width:100%; height:100%;"></div>
</body>
<script type="text/javascript">
var myInfoBubbles = new nokia.maps.map.component.InfoBubbles();
var myHTMLcontent = "<div class=\"myHtmlContent\">"+"<iframe width='425' height='349' src='http://www.youtube.com/embed/Nr41eRzUnrg' frameborder='0' allowfullscreen></iframe>"+"</div>";
var map = new nokia.maps.map.Display(document.getElementById("map"), // new instance of Nokia maps
{
components: [
myInfoBubbles,
new nokia.maps.map.component.Behavior(),
new nokia.maps.map.component.ZoomBar(),
new nokia.maps.map.component.Overview(),
new nokia.maps.map.component.TypeSelector(),
new nokia.maps.map.component.ScaleBar()
],
'zoomLevel': 10,
'center':[19.119, 72.8957]
});
map.set("baseMapType", map.SATELLITE);
myInfoBubbles.addBubble(myHTMLcontent, new nokia.maps.geo.Coordinate(19.119, 72.8957)) ;
</script>
</body>
</html>
Screenshot
Adding an InfoBubble to a map marker
Assuming we already have a map, the first thing to do is to create an info bubble and add it as a map component.
var infoBubbles = new nokia.maps.map.component.InfoBubbles();
map.addComponent( infoBubbles);
The function described below, will add an onclick event to a marker and display the associated HTML content.
function addInfoBubble(infoBubbles, marker, html) {
marker.html = html;
marker.addListener("click" , function(evt) {
infoBubbles.addBubble(evt.target.html, evt.target.coordinate);
}, false);
}
Finally the markers themselves must be added. Clicking on the marker brings up the embedded HTML.
var marker;
var markers = new Array();
marker = new nokia.maps.map.StandardMarker(new nokia.maps.geo.Coordinate(53.4393381986981,-2.2211828827858));
addInfoBubble( infoBubbles, marker, "<div><a href='http://www.mcfc.co.uk' >Manchester City</a></div><div >City of Manchester Stadium<br>Capacity: 48,000</div>");
markers.push(marker);
marker = new nokia.maps.map.StandardMarker(new nokia.maps.geo.Coordinate(53.4308166986509,-2.96082615852356));
addInfoBubble( infoBubbles, marker, "<div ><a href='http://www.liverpoolfc.tv' >Liverpool</a></div><div >Anfield<br>Capacity: 45,362</div>");
markers.push(marker);
map.objects.addAll(markers);
Screenshot
For more on Nokia Maps API
Please check out the Nokia Maps API full documentation and API reference here:
You may also access the interactive Nokia Maps API playground,
Tested on
- Google Chrome 11.0x
- Mozilla Firefox 5.0b


