×
Namespaces

Variants
Actions
(Difference between revisions)

HERE Maps API - Short introduction to observable lists

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 - - Important note about maps credentials)
(19 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]]
==Introduction==
+
{{Abstract|The OList class in Nokia Maps API is used to provide an observable list. In this article we show how to create the list and how to perform some operations on it.}}
 
+
The OList class in Ovi Maps API is used to provide an observable list. In this article we will check on how to create one and how to perform some operations on it.
+
 
+
 
<code java>
 
<code java>
new ovi.mapsapi.util.OList ([elements])  
+
new nokia.maps.util.OList ([elements])  
 
</code>
 
</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, Firefox, Opera, Google Chrome
 +
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
 +
|platform= Web browser
 +
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 +
|dependencies=Nokia Maps 2.2.3
 +
|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, observable lists
 +
|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=[[User:avnee.nathani]]
 +
|update-timestamp=20111231
 +
|creationdate=20110621
 +
|author=[[User:Maveric]]
 +
}}
 +
{{SeeAlso|
 +
* [http://developer.here.net/javascript_api Nokia Maps API]
 +
*  [[Nokia Maps API - How to cluster map markers|How to cluster map markers]] }}
  
 
==Prerequisites==
 
==Prerequisites==
  
Ovi Maps API supported web browser (basically any modern web browser)
+
Nokia Maps API supported web browser (basically any modern web browser)
 
+
The example assumes you have already added the Ovi Maps to your web page as explained in the previous article "Ovi Maps - add the map to any web page"
+
 
+
==Important about Maps credentials==
+
  
With Ovi Maps API you can start without having any credentials given, but you might face a performance gap. In order to get the full potential out of the
+
==Important note about maps credentials==
offering, you must get the credentials that authenticate your application against the Services. Please read through the Location API.
+
  
For more information on how to obtain the credentials, please start with the  Ovi Maps API Developers Guide section "Acquiring API 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
 +
[http://developer.here.net/terms_conditions Terms and Conditions] and check the [http://developer.here.net/web/guest/plans 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  [http://developer.here.net/docs/maps_js/topics/credentials.html#acquiring-credentials here]
  
 
==Implementation==
 
==Implementation==
  
The list can be manipulated by adding and removing items on it, and perform queries for e.g. the length of the list.
+
The list can be manipulated by adding and removing items on it, and queries can be performed for e.g. the length of the list.
  
 
To create a new list:
 
To create a new list:
  
 
<code java>
 
<code java>
  mylist = new ovi.mapsapi.util.OList();
+
  mylist = new nokia.maps.util.OList();
 
</code>
 
</code>
  
Line 38: Line 57:
 
</code>
 
</code>
  
Query the lenght of list:
+
Query the length of a list:
  
 
<code java>
 
<code java>
Line 44: Line 63:
 
</code>
 
</code>
  
This would return amount of "3" items as result.
+
This would return amount of "3" items as its result.
  
 
To clear the list from items:
 
To clear the list from items:
Line 58: Line 77:
  
 
The list can be enabled with an Observer.
 
The list can be enabled with an Observer.
 
+
<code javascript>
 
addObserver (callback, [context])
 
addObserver (callback, [context])
 +
</code>
  
 
To register a new observer.
 
To register a new observer.
Line 79: Line 99:
 
==Example code==
 
==Example code==
  
<code java>
+
<code javascript>
<html>
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
+
<html xmlns="http://www.w3.org/1999/xhtml">
<title>Olist test</title>
+
    <head>
<script src="http://api.maps.ovi.com/jsl.js" type="text/javascript" charset="utf-8"></script>
+
      <title>Observable Lists</title>
</head>
+
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<body>
+
      <script type="text/javascript"
<div id="map" style="width: 100%; height: 100%; position: absolute;"></div>
+
            src="http://api.maps.nokia.com/2.2.3/jsl.js" charset="utf-8">
<script type="text/javascript">
+
        </script>
ovi.mapsapi.util.ApplicationContext.set("authenticationToken", "<Token>");
+
    </head>
 +
    <body>
  
var map = new ovi.mapsapi.map.Display(document.getElementById("map"), {
+
        <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: [
 
components: [
 
//behavior collection
 
//behavior collection
new ovi.mapsapi.map.component.Behavior(),
+
new nokia.maps.map.component.Behavior(),
new ovi.mapsapi.map.component.ZoomBar(),
+
new nokia.maps.map.component.ZoomBar(),
new ovi.mapsapi.map.component.Overview(),
+
new nokia.maps.map.component.Overview(),
new ovi.mapsapi.map.component.TypeSelector(),
+
new nokia.maps.map.component.TypeSelector(),
new ovi.mapsapi.map.component.ScaleBar() ],
+
new nokia.maps.map.component.ScaleBar() ],
 
zoomLevel: 10,
 
zoomLevel: 10,
 
center: [52.51, 13.4]
 
center: [52.51, 13.4]
 
});
 
});
 
+
     mylist = new ovi.mapsapi.util.OList();
+
     mylist = new nokia.maps.util.OList();
 
+
 
     mylist.add([53.1]);
 
     mylist.add([53.1]);
 
     mylist.add([13.1]);
 
     mylist.add([13.1]);
 
     mylist.add([23.1]);
 
     mylist.add([23.1]);
 
+
 
     alert("Length of the list: "+mylist.getLength());
 
     alert("Length of the list: "+mylist.getLength());
 
     mylist.addObserver (listModified);
 
     mylist.addObserver (listModified);
 
+
     //mylist.add([53.1]);   
+
     mylist.add([53.1]);   
 
     //Comment this out to test the listener  
 
     //Comment this out to test the listener  
 
+
 
function listModified()
 
function listModified()
 
{
 
{
 
     alert("List was modified!");
 
     alert("List was modified!");
}
+
    alert("Length of the list: "+mylist.getLength());
 +
}
 
</script>
 
</script>
 
 
</body>
 
</body>
 
</html>
 
</html>
</code>
+
</code>
 
+
 
+
==For more on Ovi Maps API==
+
 
+
Please check out the Ovi Maps API full documentation and API reference here:
+
 
+
http://api.maps.ovi.com
+
  
==Tested on==
+
==For more on the Nokia Maps API==
  
Google Chrome 11.0x
+
Please check out the Nokia Maps API full documentation and API reference here:
 +
* [http://developer.here.net/javascript_api Nokia Maps API]
  
Mozilla Firefox 5.0
+
You may also access the interactive API explorer
 +
* [http://developer.here.net/javascript_api_explorer API explorer]

Revision as of 14:06, 4 January 2013

The OList class in Nokia Maps API is used to provide an observable list. In this article we show how to create the list and how to perform some operations on it.

new nokia.maps.util.OList ([elements])
Article Metadata
Tested with
Devices(s): Internet Explorer, Firefox, Opera, Google Chrome
Compatibility
Platform(s): Web browser
Dependencies: Nokia Maps 2.2.3
Article
Keywords: Nokia Maps, JavaScript, observable lists
Created: Maveric (21 Jun 2011)
Updated: avnee.nathani (31 Dec 2011)
Last edited: jasfox (04 Jan 2013)

Contents

Prerequisites

Nokia 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

Implementation

The list can be manipulated by adding and removing items on it, and queries can be performed for e.g. the length of the list.

To create a new list:

 mylist = new nokia.maps.util.OList();

To add to the list (e.g. three coordinates)

    mylist.add([53.1]);
mylist.add([13.1]);
mylist.add([23.1]);

Query the length of a list:

    mylist.getLength();

This would return amount of "3" items as its result.

To clear the list from items:

    mylist.clear()

The result of getLength() for the list would return zero/no items:

    mylist.getLength();

The list can be enabled with an Observer.

addObserver (callback, [context])

To register a new observer.

API Reference definition:

Parameters: {Function} callback The callback which will be invoked after the list was modified with following arguments: (OList) oList - the OList instance itself (String) method - the name of the method which caused the triggering (Variant) element - the element which was added or deleted (Number) idx - the index of the concerned element

The callback can signalize that a rollback has occurred by returning true.

{Object} [context]: The context to use when the callback will be invoked.


Example code

<!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>Observable Lists</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript"
src="http://api.maps.nokia.com/2.2.3/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: [
//behavior collection
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: [52.51, 13.4]
});
 
mylist = new nokia.maps.util.OList();
 
mylist.add([53.1]);
mylist.add([13.1]);
mylist.add([23.1]);
 
alert("Length of the list: "+mylist.getLength());
mylist.addObserver (listModified);
 
mylist.add([53.1]);
//Comment this out to test the listener
 
function listModified()
{
alert("List was modified!");
alert("Length of the list: "+mylist.getLength());
}
</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

187 page views in the last 30 days.
×