HERE Maps API - Short introduction to observable lists
hamishwillee
(Talk | contribs) m (Hamishwillee - Automated change of category from Ovi Maps to Nokia Maps) |
(Avnee.nathani - Updated article for Nokia Maps Javascript API v2.0. (Released in Dec 2011)) |
||
| Line 2: | Line 2: | ||
==Introduction== | ==Introduction== | ||
| − | The OList class in | + | The OList class in Nokia 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 | + | new nokia.maps.util.OList ([elements]) |
</code> | </code> | ||
==Prerequisites== | ==Prerequisites== | ||
| − | + | Nokia Maps API supported web browser (basically any modern web browser) | |
| − | + | ||
| − | + | ||
==Important about Maps credentials== | ==Important about Maps credentials== | ||
| − | + | Nokia provides several services options within the Maps API offering. The service is free to use, but if you complete the free registration process and obtain authentication and authorization credentials, your application will have priority access to the service and will thus avoid a potential performance penalty. Please read the [http://www.developer.nokia.com/Develop/Maps/Quota/ 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 from the [https://api.developer.nokia.com/ovi-api Nokia Developer API Registration page]. | |
| − | + | ||
| − | + | ||
| − | + | ||
==Implementation== | ==Implementation== | ||
| Line 28: | Line 23: | ||
<code java> | <code java> | ||
| − | mylist = new | + | mylist = new nokia.maps.util.OList(); |
</code> | </code> | ||
| Line 83: | Line 78: | ||
<head> | <head> | ||
<title>Olist test</title> | <title>Olist test</title> | ||
| − | <script src="http://api.maps. | + | <script type="text/javascript" |
| + | src="http://api.maps.nokia.com/2.0.0/jsl.js" charset="utf-8"> | ||
| + | </script> | ||
</head> | </head> | ||
<body> | <body> | ||
<div id="map" style="width: 100%; height: 100%; position: absolute;"></div> | <div id="map" style="width: 100%; height: 100%; position: absolute;"></div> | ||
<script type="text/javascript"> | <script type="text/javascript"> | ||
| − | |||
| − | var map = new | + | var map = new nokia.maps.map.Display(document.getElementById("map"), { |
components: [ | components: [ | ||
//behavior collection | //behavior collection | ||
| − | new | + | new nokia.maps.map.component.Behavior(), |
| − | new | + | new nokia.maps.map.component.ZoomBar(), |
| − | new | + | new nokia.maps.map.component.Overview(), |
| − | new | + | new nokia.maps.map.component.TypeSelector(), |
| − | new | + | new nokia.maps.map.component.ScaleBar() ], |
zoomLevel: 10, | zoomLevel: 10, | ||
center: [52.51, 13.4] | center: [52.51, 13.4] | ||
}); | }); | ||
| − | mylist = new | + | mylist = new nokia.maps.util.OList(); |
mylist.add([53.1]); | mylist.add([53.1]); | ||
| Line 124: | Line 120: | ||
</code> | </code> | ||
| + | ==For more on Nokia Maps API== | ||
| − | + | Please check out the Nokia Maps API full documentation and API reference here: | |
| + | * http://api.maps.nokia.com/ | ||
| − | + | You may also access the interactive Nokia Maps API playground, | |
| − | + | * http://api.maps.nokia.com/2.1.0/playground/index.html | |
| − | http://api.maps. | + | |
==Tested on== | ==Tested on== | ||
| − | Google Chrome 11.0x | + | * Google Chrome 11.0x |
| − | + | * Mozilla Firefox 5.0 | |
| − | Mozilla Firefox 5.0 | + | |
Revision as of 13:59, 31 December 2011
Contents |
Introduction
The OList class in Nokia 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 nokia.maps.util.OList ([elements])
Prerequisites
Nokia Maps API supported web browser (basically any modern web browser)
Important about Maps credentials
Nokia provides several services options within the Maps API offering. The service is free to use, but if you complete the free registration process and obtain authentication and authorization credentials, your application will have priority access to the service and will thus avoid a potential performance penalty. 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 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 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 type="text/javascript"
src="http://api.maps.nokia.com/2.0.0/jsl.js" charset="utf-8">
</script>
</head>
<body>
<div id="map" style="width: 100%; height: 100%; position: absolute;"></div>
<script type="text/javascript">
var map = new nokia.maps.map.Display(document.getElementById("map"), {
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!");
}
</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,
Tested on
- Google Chrome 11.0x
- Mozilla Firefox 5.0

