Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MemoryStore<TFeature>

A non-persistent Store that keeps Feature instances in memory.

The store can be created with spatial capabilities by setting MemoryStoreConstructorOptions.spatialIndex property to true. LuciadRIA will choose a default loading strategy for a layer with this store depending if the store supports spatial capabilities or not.

Please note that MemoryStoreConstructorOptions.reference should be defined in order to store features in an optimized spatial cache.

As the Features are stored in memory, there is no need to convert them to a "server-specific format". As such, this Store does not use a Codec.

Type parameters

  • TFeature: Feature

    Represents the type of Feature instances that are handled by the store. The default type is inferred from features passed in MemoryStoreConstructorOptions.data, if the field is provided, otherwise the type is Feature without restrictions on shape and properties.

    // Creates a new MemoryStore that type-guards its feature instances.
    // Here the store will accept features that have a polyline or a polygon shape only.
    const store1 = new MemoryStore<Feature<Polyline | Polygon>>();
    
    // Here the feature type is inferred from the initial data.
    const store2 = new MemoryStore({ data: [featureWithPolyline, featureWithPolygon] });
    
    // In both cases TypeScript will complain if you try to insert a feature that has a shape different than a polyline or a polygon.
    
    // You can still relax the type
    // Here the store will accept features with all kind of shapes.
    const store3 = new MemoryStore<Feature>({ data: [featureWithPolyline, featureWithPolygon] });
    

Hierarchy

  • MemoryStore

Implements

Overview

Constructors

Events

Accessors

Methods

Constructors

constructor

Events

on

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

    Parameters

    • event: "StoreChanged"

      the "StoreChanged" event.

    • callback: (eventType: string, feature: TFeature, 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: TFeature, id: string | number): any
        • Parameters

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

          Returns any

    • Optional context: any

      value to use as this when executing callback

    • Optional options: { query?: any }

      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?: any

    Returns Handle

Accessors

spatialIndex

  • get spatialIndex(): boolean
  • States if this store instance supports spatial capabilities. If the returned value is true then MemoryStore.spatialQuery method is available.

    since

    2021.0

    Returns boolean

Methods

add

  • (feature: TFeature, options?: object): number | string
  • Add a new Feature to the store. If an id is present on the feature, the Store may not yet contain a Feature with that same ID.

    Parameters

    • feature: TFeature

      the Feature to add.

    • Optional options: object

      Object literal containing options for the add method. The current implementation does not support any options.

    Returns number | string

    The identifier of the newly added Feature. An "add" event is triggered if adding is successful.

clear

  • (): boolean
  • Removes all Features from the store

    since

    2018.0

    Returns boolean

    True. A "remove" event is also triggered for every successful removal

get

  • (id: string | number): TFeature | undefined
  • Retrieve a Feature from this store by id.

    Parameters

    • id: string | number

      The identifier of the Feature.

    Returns TFeature | undefined

    The Feature with the specified id. Undefined if it does not exist.

put

  • (feature: TFeature, options?: object): string | number
  • Update an existing Feature in the store. If an object with the same identifier does not exist yet, the object will be added to the store. A corresponding StoreChanged will be fired.

    Parameters

    • feature: TFeature

      the Feature to update.

    • Optional options: object

      Object literal containing options for the put method. The current implementation does not support any options.

    Returns string | number

    The identifier of the Feature. An "update" or "add" event is triggered, depending on whether the id already exists in the Store.

query

  • Query the store for objects. The current implementation returns all Features contained in this Store.

    Parameters

    • Optional query: (feature: Feature) => boolean

      An optional function that is used to filter the results of the query. The supplied function will receive an individual feature as parameter and should return a truthy value to indicate that that feature should be included in the cursor. If the function returns a falsy value then the feature will be excluded from the cursor. If no function is specified, then all features will be returned.

        • Parameters

          Returns boolean

    Returns Cursor<TFeature>

    A cursor for the result set.

reload

  • (features: TFeature[]): boolean
  • Clears the Features in the store and loads a new set of features

    since

    2018.0

    Parameters

    • features: TFeature[]

      The new data to load.

    Returns boolean

    True. A "remove" event is triggered for every successful removal and an "add" event is triggered for every successful addition.

remove

  • (id: number | string): boolean
  • Removes a Feature from the store by id.

    Parameters

    • id: number | string

      The identifier of the Feature.

    Returns boolean

    True if removal was successful. If successful, a "remove" event is also triggered.

spatialQuery

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