A QueryProvider allows you to define what Feature instances must be shown at different map scales. A QueryProvider must be configured on a data loading strategy. A LoadingStrategy is configured on a FeatureLayer and allows you to control when and what data is downloaded from the server to be visualized in that layer.

When the map scale changes, for example because a user zooms in or out, a FeatureLayer's LoadingStrategy will consult its QueryProvider if the data that must be shown at the new scale level is different from the data shown at the previous scale level. The QueryProvider can then return a value (called a query object) that expresses the filter conditions that the data at that level must satisfy. The value returned by the QueryProvider will be passed to the FeatureModel's query() method in the query parameter. The Store can then interpret that value to send a request to the server to download the desired data.

A QueryProvider works as follows:

  • getQueryLevelScales must return an array of map scale thresholds. If no thresholds are defined, the same query object will be used at every map scale.
  • Subsequently, an index in this array is passed to getQueryForLevel to retrieve the corresponding query object.

This mechanism is similar to level-of-detail in FeaturePainter.

Since

2015.0

Hierarchy

  • QueryProvider

Constructors

Properties

QUERY_NONE: Record<string, never>

Indicates that no data should be queried from the backing store.

Methods

  • Returns the query to use on the backing Store for the given level scale. This query can be any value, provided it can be understood by the store. For a WFS store, this is a WFSQueryOptions object with an OGC filter, for a REST store, this can be an object that contains a number of key-value pairs that will be transmitted to the server as URL parameters. For a REST store, the meaning of the passed query object must be agreed with the underlying data provider.

    If no data should be downloaded from the server, return QUERY_NONE.

    Parameters

    • level: number

      the current level of detail as a non-negative integer value. The least precise detail For performance reasons, the function should return the same primitive value or same instance object, each time this function is invoked for the same level input. The loading strategy can skip querying the store if the query object strictly equals the one used in the last query request. That way unnecessary query calls can be avoided.

    Returns any

    The query to use on the backing Store.

    Example for a WFS store: request features with the scale_rank property equal to the level value.

    export class WFSQueryProvider extends QueryProvider {
    getQueryLevelScales() {
    return [1 / 200000, 1 / 10000, 1 / 100];
    };

    getQueryForLevel(level: number) {
    return {
    filter: eq(property('scale_rank'), literal(level))
    }
    }
    }

    The provider returns a query object that instructs the store to download features with a specific minimum population. As you zoom in on the map, also smaller cities will be loaded.

    export class RESTQueryProvider extends QueryProvider {
    level_queries = [
    QueryProvider.QUERY_NONE,
    {minimum_population: 1000000},
    {minimum_population: 500000},
    {minimum_population: 0}
    ];

    getQueryLevelScales() {
    return [1 / 200000, 1 / 10000, 1 / 100];
    };

    getQueryForLevel(level: number) {
    return this.level_queries[level];
    };
    }
  • Returns an array of map scales that determine when the layer should switch from one query to another. These scales must be ordered from the smallest scale (zoomed out) to the largest scale (zoomed in). The scale must be expressed in the same unit as th map scale.

    This method needs only to be implemented if there is at least a single scale break.

    Parameters

    • Optional layer: FeatureLayer

      the layer for which the detail level scales are being requested

    • Optional map: Map

      the map for which the detail level scales are being requested

    Returns number[]

    the switch scales for each level of detail.

      getQueryLevelScales() {
    return [1 / 200000, 1 / 10000, 1 / 100];
    };
  • Invalidates the query provider. Call this method to indicate that the query must be refreshed. You would use this to ensure a FeatureLayer queries the model again.

      myFeatureLayer.loadingStrategy.queryProvider.invalidate();

    Returns void