Options
All
  • Public
  • Public/Protected
  • All
Menu

The store object provides the link between the FeatureModel and the data provider. The function of the store is to query the server for data, convert the response of the server to LuciadRIA Feature instances, and to perform optional CRUD operations: get, create, update and delete.

Most of the Store implementations separate the communication with a data provider (e.g. a WFS service) from the actual parsing of the server response. The conversion of the server response to LuciadRIA Feature instances is left to a Codec. For example, the WFSFeatureStore can be configured with a dedicated Codec if your WFS server, which the WFSFeatureStore connects to, does not support GeoJson as an output format.

A typical sequence of method calls on a set of a FeatureModel - Store - Codec is the following (without considering the asynchronous nature of those methods):

  1. FeatureModel#query gets called to perform the query on the server side.
  2. The FeatureModel passes the query parameters to the Store#query method.
  3. The Store performs the query and passes the response value to the Codec for decoding.
  4. The Codec returns the Feature instances to the Store, which passes them back to the FeatureModel.

Note: Most of the methods in the Store API are optional. The presence of such an optional method indicates that the store can perform a specific action on a feature. For instance, a Store can implement the query and get methods but omit the add, put and remove methods. That also affects the functionality of the FeatureModel paired with the Store, as explained in the documentation of the FeatureModel class.

Users of this class should always check whether an optional method is available before calling the method, as illustrated below:

  var store = ...; // a custom store that implements the Store interface
  if (typeof store.add === "function") {
    // the "add" method is available and can be called
    store.add( ... );
  }

In order to create a custom store that implements the event system, the custom store should implement Evented.

export class CustomStore implements Store, Evented {

  private _eventedSupport: EventedSupport;

  constructor() {
    this._eventedSupport = new EventedSupport()
  }

  on(event: "StoreChanged", callback: (eventType: string, feature: Feature, id: (string | number)) => any,
     context?: any): Handle {
    return this._eventedSupport.on(event, callback, context);
  }

  add(feature: Feature, options?: any): number | string | Promise<number | string> {
    //Add the logic to actually store the feature

    //Trigger a change event for the Store
    this._eventedSupport.emit("StoreChanged", "add", feature, feature.id);
    return feature.id;
  }

  query(query?: any, options?: any): Cursor | Promise<Cursor> {
    //Create a Cursor with the correct results.
    let cursor: Cursor = new CursorImplementation();
    return cursor;
  }
}

Hierarchy

  • Store

Implemented by

Overview

Events

Methods

Events

Optional on

  • (event: "StoreChanged", callback: (eventType: string, feature: Feature, id: string | number) => any, context?: object, options?: { query?: object }): Handle
  • (event: string, callback: (...args: any[]) => any, context?: object, options?: { query?: object }): Handle
  • An event that is emitted when the contents of the store changes.

    Parameters

    • event: "StoreChanged"

      the "StoreChanged" event.

    • callback: (eventType: string, feature: Feature, id: string | number) => any

      the callback to be invoked when the contents of the store changes. The callback has 3 parameters:

      • eventType: "add", "update" or "remove"
      • feature: the Feature that was added, updated or removed. In case of the "remove" event type, it may be undefined.
      • id: the identifier of the Feature.
        • (eventType: string, feature: Feature, id: string | number): any
        • Parameters

          • eventType: string
          • feature: Feature
          • id: string | number

          Returns any

    • Optional context: object

      value to use as this when executing callback

    • Optional options: { query?: object }

      An option object which has a 'query' propertyr, which represents a query which may be understood and satisfied by the store. The structure of this object is dependent on the specific store. If specified, the listener function must only be invoked for features that match the query.

      • Optional query?: object

    Returns Handle

  • Registers an event listener on this store. This method is optional if Store does not emit events.

    Note: although this method is optional, it is strongly recommended to provide support for attaching listeners to the Store. The FeatureModel needs those events to generate ModelChanged events. So if your Store does not emit events, the visual representation of the model (e.g. the layer) will not be automatically updated when a feature is changed in the Store.

    Parameters

    • event: string

      the event

    • callback: (...args: any[]) => any

      the event listener

        • (...args: any[]): any
        • Parameters

          • Rest ...args: any[]

          Returns any

    • Optional context: object
    • Optional options: { query?: object }

      An option object which has a 'query' property, which represents a query which may be understood and satisfied by the store. The structure of this object is dependent on the specific store. If specified, the listener function must only be invoked for features that match the query.

      • Optional query?: object

    Returns Handle

    An object containing a single function named 'remove'. This can be used to unregister the listener from this store.

Methods

Optional add

  • (feature: Feature, options?: object): number | string | Promise<number | string>
  • Adds a Feature to the store. This method is optional.

    When the adding action is successful, the Store should:

    • Update the ID of the Feature, which has just been added, to match the ID on the server side. That ID should also be returned by the method.
    • Emit the "add" event, which contains the Feature with updated ID, and the ID itself.

    Note:: If the Store does not emit the event, a map will not update the visualization of the feature if another entity than the map performs updates a feature on the Store.

    Parameters

    • feature: Feature

      The Feature to add. When successfully added, the ID of the Feature will be adjusted to match the ID in the Store.

    • Optional options: object

    Returns number | string | Promise<number | string>

    Returns the identifier of the Feature on success, or a promise for that identifier.

Optional get

  • Retrieves a Feature by id from the data provider. This method is optional.

    Parameters

    • id: number | string

      The identifier of the Feature.

    • Optional options: object

    Returns Feature | Promise<Feature> | undefined

    May return the Feature, or a promise for the Feature. When no feature with that id exists the returned value must be either undefined (the synchronous case), or a rejected promise (the asynchronous case).

Optional put

  • (feature: Feature, options?: object): number | string | Promise<number | string>
  • Updates an existing Feature in the store. This method is optional.

    When the update is successful, the Store should emit an event which contains the Feature and the ID of the Feature.

    Note:: If the Store does not emit the event, a map will not update the visualization of the feature if another entity than the map updates a feature on the Store.

    Put may be implemented with the put-semantics of an HTTP-put. This means that if the feature does not exist yet in the store, it may be added to the store instead. The corresponding StoreChanged must correctly reflect the operation: the eventType must be 'update' when an existing element is updated and 'add' when a new element is added.

    Parameters

    • feature: Feature

      The Feature to update.

    • Optional options: object

    Returns number | string | Promise<number | string>

    Returns the identifier of the Feature on success, or a promise for the identifier.

query

  • Queries the store for objects. This method is not optional.

    Parameters

    • Optional query: object
    • Optional options: object

    Returns Cursor | Promise<Cursor>

    A Cursor over a set of Feature instances or a promise for that Cursor.

Optional remove

  • (id: number | string): boolean | Promise<boolean>
  • Removes an object from the store by id. This method is optional.

    When the removal is successful, the Store should emit an event which contains the ID of the removed Feature.

    Note:: If the Store does not emit the event, a map will not update the visualization of the feature if another entity than the map removes a feature on the Store.

    Parameters

    • id: number | string

      The identifier of the Feature.

    Returns boolean | Promise<boolean>

    Returns true on successful removal, or a promise for that value.

Optional spatialQuery

  • Queries the store for objects within a spatial extent. This method is optional.

    Note: LuciadRIA determines the layer's default loading strategy based on existence of this method in the store. If this method is implemented by store then the default loading strategy is LoadSpatially, otherwise LoadEverything.

    Note: WFSFeatureStore implements this method by creating an OGC BBOX filter based on the bounds parameter.

    Parameters

    • Optional bounds: Bounds
    • Optional query: object
    • Optional options: object

    Returns Promise<Cursor> | Cursor

    A Cursor over a set of Feature instances or a promise for that Cursor.

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method