HERE Maps API - Map UI components
This article shows how to use a static Nokia map and add interactive UI controls to it.
<img id="gmapcanvas" src="http://m.nok.it/?c=0,0&w=600&z=1&nord&nodot"
alt="Hello World" />
Article Metadata
Tested with
Compatibility
Article
Contents |
Introduction
In this article we will make a static map interactive by adding some UI control components. By default, when the map is initiated without parameters or components, it will set the coordinates to 0,0 and zoom level to zero (0). We would be adding controls like zoom bar, scale bar and map type selector.
Prerequisites
Nokia Maps API supported device and browser (basically any modern browser)
Implementation
To make the map 'intelligent', to be able to zoom it and move within the map, we need to add some components to it.
ZoomBar This will add a slider UI component, which enables the user to increase or decrease the map zoom level. The four zoom level bookmark buttons that also will appear, allow for setting predefined zoom levels.
Overview Defines a panel showing an overview of the map of the currently visible viewport.
TypeSelector Provides a user interface to change the current base map type (Satellite, Terrain, Map)
ScaleBar Defines a panel providing a scalebar. The scalebar is a ruler displaying distance measurements at different zoom levels of the map. By default, the scalebar is collapsed showing only one ruler section. When expanded, the scalebar shows more ruler sections. The measurement type can be changed from metric to imperial, which will be reflected in the distance measurements.
Example Static non-interactive map example code
The code below would show us a map which has no presets defined, so it will default to the map origin 0,0 and zoom level minimum (0) with no possibility for the user to interact with the map: it does not respond to the user mouse click and all the UI components are removed (Zoom Bar, Scale Bar, Map Type Selector).
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Static map</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript"
src="http://api.maps.nokia.com/2.2.1/jsl.js" charset="utf-8">
</script>
</head>
<body>
<div id="mapContainer" style="z-index: -1; left:0px; top:0px; width: 100%; height: 80%; position: absolute;"></div>
<script type="text/javascript">
/////////////////////////////////////////////////////////////////////////////////////
// Don't forget to set your API credentials
//
// Replace with your appId and token which you can obtain when you
// register on http://api.developer.nokia.com/
//
nokia.Settings.set( "appId", "YOUR APP ID GOES HERE");
nokia.Settings.set( "authenticationToken", "YOUR AUTHENTICATION TOKEN GOES HERE");
//
/////////////////////////////////////////////////////////////////////////////////////
var map = new nokia.maps.map.Display(document.getElementById("mapContainer"));
</script>
</body>
</html>
Example: Dynamic, interactive map with a predefined zoom level, map center point and map type
The example code contains HTML code and embedded JavaScript.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Dynamic, interactive map</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript"
src="http://api.maps.nokia.com/2.2.1/jsl.js" charset="utf-8">
</script>
</head>
<body>
<div id="mapContainer" style="z-index: -1; left:0px; top:0px; width: 100%; height: 80%; position: absolute;"></div>
<script type="text/javascript">
/////////////////////////////////////////////////////////////////////////////////////
// Don't forget to set your API credentials
//
// Replace with your appId and token which you can obtain when you
// register on http://api.developer.nokia.com/
//
nokia.Settings.set( "appId", "YOUR APP ID GOES HERE");
nokia.Settings.set( "authenticationToken", "YOUR AUTHENTICATION TOKEN GOES HERE");
//
/////////////////////////////////////////////////////////////////////////////////////
var map = new nokia.maps.map.Display(document.getElementById("mapContainer"), {
components: [
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: 8,
center: [19.119, 72.8957]
});
</script>
</body>
</html>
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 20.0x
- Mozilla Firefox 13.0x

