Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

HERE Maps API - How to add an HTML InfoBubble on the map

From Wiki
Jump to: navigation, search

This article explains how to add an info bubble on the map. The info bubble can contain any HTML content.

Article Metadata
Code ExampleTested with
Devices(s): Internet Explorer, Google Chrome, Firefox, Opera
Compatibility
Platform(s): Web browser
Dependencies: HERE Maps 2.5.3 or higher
Article
Created: Maveric (21 Jun 2011)
Updated: avnee.nathani (31 Dec 2011)
Last edited: jasfox (20 Dec 2013)

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

HERE Maps API supported web browser (basically any modern web browser)

Important note about maps credentials

Nokia provides several services options within the Maps API offering. The service is free to use, but you must obtain and use authentication and authorization credentials to use the services. Please read the Terms and Conditions and check the Pricing Plans 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 free for free following the instructions here

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. Remember to add in your own AppId and Token.

function addInfoBubble(map){
map.set("baseMapType", map.SATELLITE);
map.set("center", new nokia.maps.geo.Coordinate(19.119, 72.8957));
map.setZoomLevel(10);
 
var infoBubbles = new nokia.maps.map.component.InfoBubbles();
map.components.add(infoBubbles);
 
var myHTMLcontent = "<div class=\"myHtmlContent\">"+"<iframe width='425' height='349' " +
" src='http://www.youtube.com/embed/Nr41eRzUnrg' frameborder='0' allowfullscreen>" +
"</iframe></div>";
 
infoBubbles.openBubble(myHTMLcontent,
new nokia.maps.geo.Coordinate(19.119, 72.8957)) ;
}


NokiaMapsInfoPopup.png

A fully working example can be found at:

http://heremaps.github.io/examples/examples.html#infobubble

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, and a container with an onclick event

var infoBubbles = new nokia.maps.map.component.InfoBubbles();
map.components.add(infoBubbles);
container = new nokia.maps.map.Container();
container.addListener("click" , function(evt) {
infoBubbles.openBubble(evt.target.html, evt.target.coordinate);
}, false);
map.objects.add(container);

The function described below, will add a marker and HTML content to the container

function addMarkerToContainer(container, coordinate , html) {
var marker = new nokia.maps.map.StandardMarker(
coordinate, {html: html});
container.objects.add(marker);
}

Finally the markers themselves must be added. Clicking on the marker brings up the embedded HTML.

addMarkerToContainer(container, [53.439,-2.221], 
"<div><a href='http://www.mcfc.co.uk' >Manchester City</a>" +
"</div><div >City of Manchester Stadium<br>Capacity: 48,000</div>");
 
addMarkerToContainer(container, [53.430,-2.961],
"<div ><a href='http://www.liverpoolfc.tv' >Liverpool</a>" +
"</div><div >Anfield<br>Capacity: 45,362</div>");

Screenshot

MarkersWithInfoBubble.png

Working Example:

http://heremaps.github.io/examples/examples.html#infobubble-on-marker-click

Pre-opening an InfoBubble

It is possible to use the dispatch() method, to fire an onclick event, which causes the infobubble to be opened when the page is loaded. Image a URL of the form ../open-infobubble-with-id.html?id=2 - the query string of this url can be read to determine which infobubble should be opened.

First create a helper function to obtain the query string parameters:

function getParameterByName(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

The call the function below to open the relevant id

function openInfoBubble(){
var param = getParameterByName('id');
if (param == ""){
return; // Don't open a bubble.
}
// Iterate through the markers to find the correct id.
for (var i = 0; i < container.objects.getLength(); i++){
if (param === container.objects.get(i).id){
// fire an event to open the bubble.
container.dispatch(
new nokia.maps.dom.Event(
{type: "click",
target: container.objects.get(i)}));
map.zoomTo(container.objects.get(i).getBoundingBox())
break;
}
}
}

The markers must be assigned a unique id when instantiated as shown:

var marker = new nokia.maps.map.StandardMarker(
new nokia.maps.geo.Coordinate(52.516237, 13.377686),
{html: "Brandenburger Tor",
id : "1" }
);
var fernsehturmMarker = new nokia.maps.map.StandardMarker(
new nokia.maps.geo.Coordinate(52.520816, 13.409417),
{html: Fernsehturm,
id : "2" }
);

Working Example - click on the links:

For more on the HERE Maps API

Please check out the HERE Maps API full documentation and API reference here:

You may also access the interactive API explorer

This page was last modified on 20 December 2013, at 15:43.
1757 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×