Nokia Maps API Reference

Contents

Class nokia.maps.map.component.Component

Class Summary

Component is an abstract class that serves as basis for defining replaceable software modules that extend the basic map with additional functionality. Components allow API users to:

  • include new functionality
  • replace existing functionality with a different implementation
  • deactivate existing functionality.

A component may fire custom events.

The Component class is implemented in several packages outside the map package, for example in routing and search.

Reference counting

The fact that components are replaceable and that they can add or remove other components, creating and potentially disrupting inter-component dependencies, makes a reference counting mechanism necessary. The basic principle is that whenever a component is created its reference count is incremented to indicate that the creator requires it (and holds a reference to it). The count is also incremented when a component already exists, but a new attempt to create it is made - thus, the count goes up, but duplicate components with the same id are not created. An attempt to deleted/remove a component, causes its reference count to be decremented.

This mechanism prevents not only component duplication, but also the removal of components while other components dependent on them for as long as the dependencies exist. Caution when physically removing components is necessary, because on removal, a component's detach callback is called to delete its reference to the map Display. As a result, the component becomes unusable in an invalid state.

However, this mechanism remains transparent and you, as the API user simply need to call the methods addComponent() and removeComponent of the map Display class to add and remove components, respectively. Here is an example:

// If a Kinetic component already exists, addComponent()   
// returns it instead of creating a duplicate.
var component = display.addComponent(new nokia.maps.map.component.panning.Kinetic());

// If any other component or application part holds a reference 
// to the component, this call does not remove the component, but 
// decrements the reference counter by one, otherwise it removes
// the component (if the reference counter reached zero).
display.removeComponent(component);

// Another possibility to remove a component is:
display.removeComponent( display.getComponentById("panning.Kinetic") );

Method Summary
addObserver (key, callback, [context]) : nokia.maps.util.OObject This method registers an observer for the property named by the caller.
attach (mapDisplay) This method will be invoked when the component is attached to a map and is not meant to be called directly.
destroy () This method is called from Display when Display is destroyed.
detach (mapDisplay) This method will be invoked when the component is detached from a map and is not meant to be called directly
get (key) : Variant This method retrieves the value of the property with the name provided by the caller.
getId () : String This method retrieves the unique identifier of the component.
remove (key) : nokia.maps.util.OObject This method removes the property with the name provided by the caller.
removeObserver (key, callback, context) : nokia.maps.util.OObject This method removes the observer for the property named by the caller.
set (nameOrObject, [value, [force]]) : nokia.maps.util.OObject This method sets property values, using the property names and values supplied by the caller.
Field Summary
nokia.maps.map.Display mapDisplay This property holds a reference to the map.Display instance to which the given component belongs.
Direct Inheritance
Method Detail
attach (mapDisplay)
This method will be invoked when the component is attached to a map and is not meant to be called directly.

Note that a component must not be bound to two instances of map.Display at the same time!

Parameters:
{nokia.maps.map.Display} mapDisplay A reference to the map.Display instance to which the given component is bound.
destroy ()
This method is called from Display when Display is destroyed. It is also intended that you call it when you detach component from Display and do not want to use component instance anymore. It will free all allocated resources.
detach (mapDisplay)
This method will be invoked when the component is detached from a map and is not meant to be called directly
Parameters:
{nokia.maps.map.Display} mapDisplay A reference to the map.Display instance from which this component is to be removed.
getId () : String
This method retrieves the unique identifier of the component. The id is guaranteed to be unique, because it is not possible to add two components with the same id to the map.
Returns:
{String} The component identifier
Field Detail
This property holds a reference to the map.Display instance to which the given component belongs.
Documentation generated on Wed Jun 27 2012 16:54:34 GMT+0200 (CEST).