×
Namespaces

Variants
Actions
(Difference between revisions)

HERE Maps API - Short introduction to observable lists

From Nokia Developer Wiki
Jump to: navigation, search
jasfox (Talk | contribs)
m (Jasfox - Add link.)
jasfox (Talk | contribs)
m (Jasfox - Change link text.)
Line 29: Line 29:
 
{{SeeAlso|
 
{{SeeAlso|
 
*  [http://api.maps.nokia.com/en/maps/intro.html Nokia Maps API]  
 
*  [http://api.maps.nokia.com/en/maps/intro.html Nokia Maps API]  
* [[Nokia Maps API - How to cluster map markers]] }}
+
* [[Nokia Maps API - How to cluster map markers|How to cluster map markers]] }}
  
 
==Prerequisites==
 
==Prerequisites==

Revision as of 13:19, 12 July 2012

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.1
Article
Created: Maveric (21 Jun 2011)
Updated: avnee.nathani (31 Dec 2011)
Last edited: jasfox (12 Jul 2012)

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 Location API Business Models and Usage Restrictions 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 from the Nokia Developer API Registration page.

Implementation

The list can be manipulated by adding and removing items on it, and perform queries 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.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: [
//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 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,

217 page views in the last 30 days.
×