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.

2015.0

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. The query can take any form as long as it can be correctly interpreted 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))
    }
    }
    }

    For a REST store: returns a query object that instructs the store to download features with a specific minimum population. As the map zooms in, cities with smaller population are also 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 dictate when a 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).

    This method is required only if there's at least one scale break.

    Parameters

    • Optionallayer: FeatureLayer

      the layer for which the detail level scales are being requested

    • Optionalmap: Map

      the map for which the detail level scales are being requested

    Returns number[]

    Array of switch scales for each level of detail.

      getQueryLevelScales() {
    return [1 / 200000, 1 / 10000, 1 / 100];
    };
  • Invalidates the query provider. Use this method when you need to ensure that a FeatureLayer re-queries the model.

      myFeatureLayer.loadingStrategy.queryProvider.invalidate();
    

    Returns void