Classdesc

Abstract base class; normally only used for creating subclasses and not instantiated in apps. Most non-trivial classes inherit from this.

This extends module:ol/Observable~Observable with observable properties, where each property is observable as well as the object as a whole.

Classes that inherit from this have pre-defined properties, to which you can add your owns. The pre-defined properties are listed in this documentation as 'Observable Properties', and have their own accessors; for example, module:ol/Map~Map has a target property, accessed with getTarget() and changed with setTarget(). Not all properties are however settable. There are also general-purpose accessors get() and set(). For example, get('target') is equivalent to getTarget().

The set accessors trigger a change event, and you can monitor this by registering a listener. For example, module:ol/View~View has a center property, so view.on('change:center', function(evt) {...}); would call the function whenever the value of the center property changes. Within the function, evt.target would be the view, so evt.target.getCenter() would return the new center.

You can add your own observable properties with object.set('prop', 'value'), and retrieve that with object.get('prop'). You can listen for changes on that property value with object.on('change:prop', listener). You can get a list of all properties with module:ol/Object~BaseObject#getProperties.

Note that the observable properties are separate from standard JS properties. You can, for example, give your map object a title with map.title='New title' and with map.set('title', 'Another title'). The first will be a hasOwnProperty; the second will appear in getProperties(). Only the second is observable.

Properties can be deleted by using the unset method. E.g. object.unset('foo').

Fires

ObjectEvent

Api

Hierarchy (view full)

Constructors

  • Parameters

    • Optional values: {
          [x: string]: any;
      }

      An object with key-value pairs.

      • [x: string]: any

    Returns Object

Properties

disposed: boolean

The object has already been disposed.

on: ObjectOnSignature<EventsKey>
once: ObjectOnSignature<EventsKey>
un: ObjectOnSignature<void>

Methods

  • Parameters

    • key: string

      Key name.

    • listener: Listener

      Listener.

    Returns void

  • Parameters

    • type: string

      Type.

    • listener: Listener

      Listener.

    Returns void

  • Protected

    Apply any properties from another object without triggering events.

    Parameters

    • source: Object

      The source object.

    Returns void

  • Increases the revision counter and dispatches a 'change' event.

    Returns void

    Api

  • Dispatches an event and calls all listeners listening for events of this type. The event parameter can either be a string or an Object with a type property.

    Parameters

    • event: string | BaseEvent

      Event object.

    Returns undefined | boolean

    false if anyone called preventDefault on the event object or if any of the listeners returned false.

    Api

  • Clean up.

    Returns void

  • Protected

    Extension point for disposable objects.

    Returns void

  • Gets a value.

    Parameters

    • key: string

      Key name.

    Returns any

    Value.

    Api

  • Get a list of object property names.

    Returns string[]

    List of property names.

    Api

  • Get the listeners for a specified event type. Listeners are returned in the order that they will be called in.

    Parameters

    • type: string

      Type.

    Returns undefined | Listener[]

    Listeners.

  • Get an object of all property names and values.

    Returns {
        [x: string]: any;
    }

    Object.

    • [x: string]: any

    Api

  • Get an object of all property names and values.

    Returns null | {
        [x: string]: any;
    }

    Object.

  • Get the version number for this object. Each time the object is modified, its version number will be incremented.

    Returns number

    Revision.

    Api

  • Parameters

    • Optional type: string

      Type. If not provided, true will be returned if this event target has any listeners.

    Returns boolean

    Has listeners.

  • Returns boolean

    The object has properties.

  • Parameters

    • key: string

      Key name.

    • oldValue: any

      Old value.

    Returns void

  • Protected

    Parameters

    • type: string | string[]

      Type.

    • listener: ((arg0) => unknown)

      Listener.

        • (arg0): unknown
        • Parameters

          • arg0: Event | BaseEvent

          Returns unknown

    Returns EventsKey | EventsKey[]

    Event key.

  • Protected

    Parameters

    • type: string | string[]

      Type.

    • listener: ((arg0) => unknown)

      Listener.

        • (arg0): unknown
        • Parameters

          • arg0: Event | BaseEvent

          Returns unknown

    Returns EventsKey | EventsKey[]

    Event key.

  • Parameters

    • key: string

      Key name.

    • listener: Listener

      Listener.

    Returns void

  • Parameters

    • type: string

      Type.

    • listener: Listener

      Listener.

    Returns void

  • Sets a value.

    Parameters

    • key: string

      Key name.

    • value: any

      Value.

    • Optional silent: boolean

      Update without triggering an event.

    Returns void

    Api

  • Sets a collection of key-value pairs. Note that this changes any existing properties and adds new ones (it does not remove any existing properties).

    Parameters

    • values: {
          [x: string]: any;
      }

      Values.

      • [x: string]: any
    • Optional silent: boolean

      Update without triggering an event.

    Returns void

    Api

  • Protected

    Unlisten for a certain type of event.

    Parameters

    • type: string | string[]

      Type.

    • listener: ((arg0) => unknown)

      Listener.

        • (arg0): unknown
        • Parameters

          • arg0: Event | BaseEvent

          Returns unknown

    Returns void

  • Unsets a property.

    Parameters

    • key: string

      Key name.

    • Optional silent: boolean

      Unset without triggering an event.

    Returns void

    Api