×
Namespaces

Variants
Actions
(Difference between revisions)

HERE Maps API - Map UI components

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Automated change of category from Ovi Maps to Nokia Maps)
jasfox (Talk | contribs)
m (Jasfox - update to 2.2.4)
(26 intermediate revisions by 5 users not shown)
Line 1: Line 1:
[[Category:Web]][[Category:Browser]][[Category:Nokia Maps]]
+
[[Category:Nokia Maps]][[Category:Code Snippet]][[Category:JavaScript]]
 +
{{Abstract|This article shows how to use a static Nokia map and add interactive UI controls to it.}}
 +
 
 +
{{Tip|The [http://developer.here.net/javascript_api Nokia Maps API for JavaScript] is generally used to display an interactive map on screen. i.e. a map which is  pannable, zoomable  or clickable for further information. If you don't need any UI components, a simpler  solution for displaying a non-interactive '''static map''' would be to use the [http://developer.here.net/rest_api RESTful Map API]  where the location of the map is encoded into the URL of the image. For example, the following URL will display a static map without using any JavaScript:
 +
<code javascript>
 +
<img id="gmapcanvas" src="http://m.nok.it/?c=0,0&w=600&z=1&nord&nodot"
 +
alt="Hello World" />
 +
</code>
 +
}}
 +
 
 +
{{ArticleMetaData
 +
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
 +
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 +
|devices= Internet Explorer, Google Chrome, Firefox, Opera
 +
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
 +
|platform= Web
 +
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 +
|dependencies=Nokia Maps 2.2.4
 +
|signing=<!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= Nokia Maps, JavaScript, UI, components
 +
|id= <!-- Article Id (Knowledge base articles only) -->
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by=<!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate=20110621
 +
|author=[[User:Maveric]]
 +
}}
 +
{{SeeAlso|
 +
* [http://developer.here.net/rest_api RESTful Map API]
 +
* [http://developer.here.net/javascript_api Nokia Maps API]
 +
* [http://developer.here.net/apiexplorer/examples/api-for-js/getting-started/basic-map-with-components.html Map with components]
 +
* [http://developer.here.net/apiexplorer/examples/api-for-js/getting-started/basic-map.html Basic Map]
 +
}}
 +
 
 +
 
 
==Introduction==
 
==Introduction==
  
In this article we will go thru on making a static map interactive by adding some UI control components. By default, when the map is initiated empty without no parameters or components, it will default to coordinates 0,0 and zoom level of zero (0).
+
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.
Also there will be none of the usual UI controls, like zoom bar, scale bar and map type selector.
+
  
 
==Prerequisites==
 
==Prerequisites==
  
Ovi Maps API supported device and browser (basically any modern browser)
+
Nokia Maps API supported device and browser (basically any modern browser)
  
 
==Implementation==
 
==Implementation==
Line 28: Line 67:
 
==Example Static non-interactive map example code==
 
==Example Static non-interactive map example code==
  
This would show us a map which has no presets defined, so it will default to the map origo 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).
+
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).
  
Note: The authorization token is not in use in the time of writing. Please follow the Announcements section on the Ovi Maps API discussions at the project discussion board. We will be announcing when the authorisation is enabled.
+
{{Note| As from Nokia Maps API 2.2 The authorization token is now required }}
  
<code java>
+
<code 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>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.4/jsl.js" charset="utf-8">
 +
        </script>
 +
    </head>
 +
    <body>
  
<html>
+
        <div id="mapContainer" style="z-index: -1; left:0px; top:0px; width: 100%; height: 80%; position: absolute;"></div>
<head>
+
        <script type="text/javascript">
<title>Static map</title>
+
/////////////////////////////////////////////////////////////////////////////////////
<script src="http://api.maps.ovi.com/jsl.js" type="text/javascript" charset="utf-8"></script>
+
// Don't forget to set your API credentials
</head>
+
//
<body>
+
// Replace with your appId and token which you can obtain when you
<div id="map" style="width: 100%; height: 100%; position: absolute;"></div>
+
// register on http://api.developer.nokia.com/
<script type="text/javascript">
+
//
ovi.mapsapi.util.ApplicationContext.set("authenticationToken", "<Token>");
+
nokia.Settings.set( "appId", "YOUR APP ID GOES HERE");
 +
nokia.Settings.set( "authenticationToken", "YOUR AUTHENTICATION TOKEN GOES HERE");
  
var map = new ovi.mapsapi.map.Display(document.getElementById("map"));  
+
//
 +
/////////////////////////////////////////////////////////////////////////////////////
 +
var map = new nokia.maps.map.Display(document.getElementById("mapContainer"));
 
</script>
 
</script>
 
</body>
 
</body>
 
</html>
 
</html>
 
 
</code>
 
</code>
  
Example: Dynamic, ineractive map with a predefined zoom level, map center point and map type
+
Example: Dynamic, interactive map with a predefined zoom level, map center point and map type
  
The example code is full with HTML and embedded JavaScript.
+
The example code contains HTML code and embedded JavaScript.
  
<code java>
+
<code 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.4/jsl.js" charset="utf-8">
 +
        </script>
 +
    </head>
 +
    <body>
  
<html>
+
        <div id="mapContainer" style="z-index: -1; left:0px; top:0px; width: 100%; height: 80%; position: absolute;"></div>
<head>
+
        <script type="text/javascript">
<title>Dynamic, interactive map</title>
+
/////////////////////////////////////////////////////////////////////////////////////
<script src="http://api.maps.ovi.com/jsl.js" type="text/javascript" charset="utf-8"></script>
+
// Don't forget to set your API credentials
</head>
+
//
<body>
+
// Replace with your appId and token which you can obtain when you
<div id="map" style="width: 100%; height: 100%; position: absolute;"></div>
+
// register on http://api.developer.nokia.com/
<script type="text/javascript">
+
//
ovi.mapsapi.util.ApplicationContext.set("authenticationToken", "<Token>");
+
nokia.Settings.set( "appId", "YOUR APP ID GOES HERE");
 +
nokia.Settings.set( "authenticationToken", "YOUR AUTHENTICATION TOKEN GOES HERE");
  
var map = new ovi.mapsapi.map.Display(document.getElementById("map"), {
+
//
components: [
+
/////////////////////////////////////////////////////////////////////////////////////
new ovi.mapsapi.map.component.Behavior(),
+
var map = new nokia.maps.map.Display(document.getElementById("mapContainer"), {
new ovi.mapsapi.map.component.ZoomBar(),
+
components: [
new ovi.mapsapi.map.component.Overview(),
+
new nokia.maps.map.component.Behavior(),
new ovi.mapsapi.map.component.TypeSelector(),
+
new nokia.maps.map.component.ZoomBar(),
new ovi.mapsapi.map.component.ScaleBar() ],
+
new nokia.maps.map.component.Overview(),
zoomLevel: 10,
+
new nokia.maps.map.component.TypeSelector(),
center: [52.51, 13.4]
+
new nokia.maps.map.component.ScaleBar() ],
 +
zoomLevel: 8,
 +
center: [19.119, 72.8957]
 
});
 
});
 +
 
</script>
 
</script>
 
</body>
 
</body>
Line 82: Line 147:
 
</code>
 
</code>
  
Note: Authentication setting is not mandatory at the time of writing, but should be enabled later. This will be informed separately.
+
==For more on the Nokia Maps API==
  
==For more on Ovi Maps API==
+
Please check out the Nokia Maps API full documentation and API reference here:
 +
* [http://developer.here.net/javascript_api Nokia Maps API]
  
Please check out the Ovi Maps API full documentation and API reference here:
+
You may also access the interactive API explorer
 
+
* [http://developer.here.net/javascript_api_explorer API explorer]
http://api.maps.ovi.com
+
  
 
==Tested on==
 
==Tested on==
  
Google Chrome 11.0x
+
* Google Chrome 20.0x
 
+
* Mozilla Firefox 13.0x
Mozilla Firefox 5.0
+

Revision as of 14:32, 14 March 2013

This article shows how to use a static Nokia map and add interactive UI controls to it.

Tip.pngTip: The Nokia Maps API for JavaScript is generally used to display an interactive map on screen. i.e. a map which is pannable, zoomable or clickable for further information. If you don't need any UI components, a simpler solution for displaying a non-interactive static map would be to use the RESTful Map API where the location of the map is encoded into the URL of the image. For example, the following URL will display a static map without using any JavaScript:

<img id="gmapcanvas" src="http://m.nok.it/?c=0,0&w=600&z=1&nord&nodot" 
alt="Hello World" />

Article Metadata
Tested with
Devices(s): Internet Explorer, Google Chrome, Firefox, Opera
Compatibility
Platform(s): Web
Dependencies: Nokia Maps 2.2.4
Article
Keywords: Nokia Maps, JavaScript, UI, components
Created: Maveric (21 Jun 2011)
Last edited: jasfox (14 Mar 2013)


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).

Note.pngNote: As from Nokia Maps API 2.2 The authorization token is now required

<!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.4/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.4/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 the Nokia Maps API

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

You may also access the interactive API explorer

Tested on

  • Google Chrome 20.0x
  • Mozilla Firefox 13.0x
339 page views in the last 30 days.
×