ZoomToFeaturesRequest RPC
Moves map to show referenced vector features on the viewport.
Use cases
- Zoom to features on a map
Description
This request is used to zoom/move the map so requested features are visible on the map viewport. Requested features can be selected by referencing a vector layer and/or referencing attribute data values. If selection is not made the map is zoomed out to show all vector features that have been programmatically added to the map (features added directly from services/map layers providing vector features are not included).
Parameters
All of the parameters for this request are optional.
Name | Type | Description | Default value |
---|---|---|---|
options | Object | Can be used to select layers to include or max zoom level | See below |
feature filter | Object | Features to zoom to can be selected by defining filters with this parameter. If not provided the features are not filtered. | No filter/all features on the specified layers are shown. |
Param: options
Name | Type | Description | Default value |
---|---|---|---|
layer | Array | Features to show are only included from layers matching ids referenced in the array | All layers that were created for programmatically added features (by VectorLayerPlugin) |
maxZoomLevel | Number | Can be used to restrict how "close" we want to zoom if the features are very close to each other or a single point. | No restriction |
Param: feature filter
The feature filter is an object where keys are feature attribute names. The value for specific key is an array listing the accepted values for that attribute. If a feature has that attribute with any of the listed values it will be included in the set.
For example:
{
"name": ["F1","F2"]
}
The above filter would only include features where the name attribute has a value of "F1" or "F2".
Examples
Zoom to extent of the features with id=='F1' or id=='F2' on the layer with layerId == 'layer1' or layerId == 'layer2':
var sb = Oskari.getSandbox();
sb.postRequestByName('MapModulePlugin.ZoomToFeaturesRequest', [
{layer: ['layer1','layer2']},
{'id': ['F1','F2']}
]);
After the zooming is completed a 'FeatureEvent' is triggered with operation 'zoom' and array of the features that was zoomed to.
Zoom to all features on the layer, where layerId == 'testlayer':
var sb = Oskari.getSandbox();
sb.postRequestByName('MapModulePlugin.ZoomToFeaturesRequest', [
{layer: ['testlayer']},
{}
]);
After the zooming is completed a 'FeatureEvent' is triggered with operation 'zoom' and array of the features that was zoomed to.
Zoom to all features on the layers, that are handling by the VectorLayerPlugin
var sb = Oskari.getSandbox();
sb.postRequestByName('MapModulePlugin.ZoomToFeaturesRequest', []);
After the zooming is completed a 'FeatureEvent' is triggered with operation 'zoom' and array of the features that was zoomed to.
Related api
- AddFeaturesToMapRequest
- RemoveFeaturesFromMapRequest