×
Namespaces

Variants
Actions
(Difference between revisions)

HERE Maps API - Short introduction to observable lists

From Nokia Developer Wiki
Jump to: navigation, search
Maveric (Talk | contribs)
m (Maveric - - For more on Ovi Maps API=)
hamishwillee (Talk | contribs)
m (Hamishwillee - Add Ovi Maps category)
Line 1: Line 1:
[[Category:Ovi]][[Category:Web]][[Category:Browser]]
+
[[Category:Web]][[Category:Browser]][[Category:Ovi Maps]]
 
==Introduction==
 
==Introduction==
  

Revision as of 03:51, 12 October 2011

Contents

Introduction

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.

new ovi.mapsapi.util.OList ([elements])

Prerequisites

Ovi 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 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"

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 ovi.mapsapi.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 lenght of list:

    mylist.getLength();

This would return amount of "3" items as 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

<html>
<head>
<title>Olist test</title>
<script src="http://api.maps.ovi.com/jsl.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div id="map" style="width: 100%; height: 100%; position: absolute;"></div>
<script type="text/javascript">
ovi.mapsapi.util.ApplicationContext.set("authenticationToken", "<Token>");
 
var map = new ovi.mapsapi.map.Display(document.getElementById("map"), {
components: [
//behavior collection
new ovi.mapsapi.map.component.Behavior(),
new ovi.mapsapi.map.component.ZoomBar(),
new ovi.mapsapi.map.component.Overview(),
new ovi.mapsapi.map.component.TypeSelector(),
new ovi.mapsapi.map.component.ScaleBar() ],
zoomLevel: 10,
center: [52.51, 13.4]
});
 
mylist = new ovi.mapsapi.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!");
}
</script>
 
</body>
</html>


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

Google Chrome 11.0x

Mozilla Firefox 5.0

106 page views in the last 30 days.
×