×
Namespaces

Variants
Actions
(Difference between revisions)

HERE Maps API - Map UI components

From Nokia Developer Wiki
Jump to: navigation, search
jasfox (Talk | contribs)
m (Jasfox - update to 2.2.4)
jasfox (Talk | contribs)
m (Jasfox - - For more on the HERE Maps API)
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:Nokia Maps]][[Category:Code Snippet]][[Category:JavaScript]]
+
[[Category:HERE Maps]][[Category:JavaScript]][[Category:Code Examples]]
 
{{Abstract|This article shows how to use a static Nokia map and add interactive UI controls to it.}}
 
{{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:
+
{{Tip|The [http://developer.here.net/javascript_api HERE 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>
 
<code javascript>
 
<img id="gmapcanvas" src="http://m.nok.it/?c=0,0&w=600&z=1&nord&nodot"  
 
<img id="gmapcanvas" src="http://m.nok.it/?c=0,0&w=600&z=1&nord&nodot"  
Line 9: Line 9:
 
}}
 
}}
  
{{ArticleMetaData
+
{{ArticleMetaData <!-- v1.2 -->
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
+
|sourcecode=  [https://github.com/heremaps/examples/blob/master/maps_api_for_javascript/simple-examples/map-components.html map-components.html]
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|devices= Internet Explorer, Google Chrome, Firefox, Opera
 
|devices= Internet Explorer, Google Chrome, Firefox, Opera
Line 16: Line 16:
 
|platform= Web
 
|platform= Web
 
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
|dependencies=Nokia Maps 2.2.4
+
|dependencies= HERE Maps 2.5.3
|signing=<!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
+
|signing= <!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
 
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
|keywords= Nokia Maps, JavaScript, UI, components
+
|keywords= HERE Maps, JavaScript, UI, components
|id= <!-- Article Id (Knowledge base articles only) -->
+
 
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 
|translated-by= <!-- [[User:XXXX]] -->
 
|translated-by= <!-- [[User:XXXX]] -->
|translated-from-title= <!-- Title only -->  
+
|translated-from-title= <!-- Title only -->
 
|translated-from-id= <!-- Id of translated revision -->
 
|translated-from-id= <!-- Id of translated revision -->
|review-by=<!-- After re-review: [[User:username]] -->
+
|review-by= <!-- After re-review: [[User:username]] -->
 
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 
|update-by= <!-- After significant update: [[User:username]]-->
 
|update-by= <!-- After significant update: [[User:username]]-->
 
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 
|update-timestamp= <!-- After significant update: YYYYMMDD -->
|creationdate=20110621
+
|creationdate= 20110621
|author=[[User:Maveric]]
+
|author= [[User:Maveric]]
 
}}
 
}}
 
{{SeeAlso|
 
{{SeeAlso|
 
* [http://developer.here.net/rest_api RESTful Map API]
 
* [http://developer.here.net/rest_api RESTful Map API]
* [http://developer.here.net/javascript_api Nokia Maps API]
+
* [http://developer.here.net/javascript_api HERE 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-with-components.html Map with components]
 
* [http://developer.here.net/apiexplorer/examples/api-for-js/getting-started/basic-map.html Basic Map]
 
* [http://developer.here.net/apiexplorer/examples/api-for-js/getting-started/basic-map.html Basic Map]
Line 46: Line 45:
 
==Prerequisites==
 
==Prerequisites==
  
Nokia Maps API supported device and browser (basically any modern browser)
+
HERE Maps API supported device and browser (basically any modern browser)
  
 
==Implementation==
 
==Implementation==
Line 67: Line 66:
 
==Example Static non-interactive map example code==
 
==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).
+
The code below taken from the {{Icode|&lt;body&gt;}} of a working example 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| As from Nokia Maps API 2.2 The authorization token is now required }}
+
{{Note| As from HERE Maps API 2.2 The authorization token is now required }}
  
 
<code javascript>
 
<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>
 
  
        <div id="mapContainer" style="z-index: -1; left:0px; top:0px; width: 100%; height: 80%; position: absolute;"></div>
+
<div id="mapContainer" style="width:540px; height:334px;"></div>
        <script type="text/javascript">
+
<script type="text/javascript">
 
/////////////////////////////////////////////////////////////////////////////////////
 
/////////////////////////////////////////////////////////////////////////////////////
 
// Don't forget to set your API credentials
 
// Don't forget to set your API credentials
Line 91: Line 80:
 
// register on http://api.developer.nokia.com/  
 
// register on http://api.developer.nokia.com/  
 
//
 
//
nokia.Settings.set( "appId", "YOUR APP ID GOES HERE");  
+
          nokia.Settings.set("app_id", "YOUR APP ID");  
nokia.Settings.set( "authenticationToken", "YOUR AUTHENTICATION TOKEN GOES HERE");
+
          nokia.Settings.set("app_code", "YOUR TOKEN");
  
 
//
 
//
Line 98: Line 87:
 
var map = new nokia.maps.map.Display(document.getElementById("mapContainer"));
 
var map = new nokia.maps.map.Display(document.getElementById("mapContainer"));
 
</script>
 
</script>
</body>
+
 
</html>
+
 
</code>
 
</code>
  
Example: Dynamic, interactive map with a predefined zoom level, map center point and map type
+
==Example: Dynamic, interactive map with scale bar, overview and map type selector==
  
The example code contains HTML code and embedded JavaScript.
+
To add the map components, the set-up of the map in the example is altered as follows:
  
 
<code javascript>
 
<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>
 
 
        <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"), {
 
var map = new nokia.maps.map.Display(document.getElementById("mapContainer"), {
 
components: [
 
components: [
Line 141: Line 105:
 
center: [19.119, 72.8957]
 
center: [19.119, 72.8957]
 
});
 
});
 
</script>
 
</body>
 
</html>
 
 
</code>
 
</code>
  
==For more on the Nokia Maps API==
+
To see an example in action, try the following link:
  
Please check out the Nokia Maps API full documentation and API reference here:
+
http://rawgithub.com/heremaps/examples/master/maps_api_for_javascript/simple-examples/map-components.html
* [http://developer.here.net/javascript_api Nokia Maps API]
+
 
 +
==For more on the HERE Maps API==
 +
 
 +
Please check out the HERE Maps API full documentation and API reference here:
 +
* [http://developer.here.com/javascript_api HERE Maps API]
  
 
You may also access the interactive API explorer
 
You may also access the interactive API explorer
* [http://developer.here.net/javascript_api_explorer API explorer]
+
* [http://developer.here.com/javascript_api_explorer API explorer]
 +
 
 +
And additional examples on GitHub
 +
* [http://heremaps.github.io/examples/ HERE Maps on Github]
  
 
==Tested on==
 
==Tested on==

Latest revision as of 17:28, 12 March 2014

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

Tip.pngTip: The HERE 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
Code Example
Source file: map-components.html
Tested with
Devices(s): Internet Explorer, Google Chrome, Firefox, Opera
Compatibility
Platform(s): Web
Dependencies: HERE Maps 2.5.3
Article
Keywords: HERE Maps, JavaScript, UI, components
Created: Maveric (21 Jun 2011)
Last edited: jasfox (12 Mar 2014)


Contents

[edit] 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.

[edit] Prerequisites

HERE Maps API supported device and browser (basically any modern browser)

[edit] 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.


[edit] Example Static non-interactive map example code

The code below taken from the <body> of a working example 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 HERE Maps API 2.2 The authorization token is now required

<div id="mapContainer" style="width:540px; height:334px;"></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("app_id", "YOUR APP ID");
nokia.Settings.set("app_code", "YOUR TOKEN");
 
//
/////////////////////////////////////////////////////////////////////////////////////
var map = new nokia.maps.map.Display(document.getElementById("mapContainer"));
</script>

[edit] Example: Dynamic, interactive map with scale bar, overview and map type selector

To add the map components, the set-up of the map in the example is altered as follows:

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]
});

To see an example in action, try the following link:

http://rawgithub.com/heremaps/examples/master/maps_api_for_javascript/simple-examples/map-components.html

[edit] 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

And additional examples on GitHub

[edit] Tested on

  • Google Chrome 20.0x
  • Mozilla Firefox 13.0x
This page was last modified on 12 March 2014, at 17:28.
249 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.

×