@terrestris/ol-util
Version:
A set of helper classes for working with openLayers
218 lines (216 loc) • 9.46 kB
TypeScript
import { Coordinate as OlCoordinate } from 'ol/coordinate';
import { Extent as OlExtent } from 'ol/extent';
import OlFeature from 'ol/Feature';
import OlGeometry from 'ol/geom/Geometry';
import OlBaseLayer from 'ol/layer/Base';
import OlLayerGroup from 'ol/layer/Group';
import OlMap from 'ol/Map';
import { Units } from 'ol/proj/Units';
import { WmsLayer, WmtsLayer } from '../typeUtils/typeUtils';
export interface LayerPositionInfo {
position?: number;
groupLayer?: OlLayerGroup;
}
/**
* Helper class for the OpenLayers map.
*
* @class
*/
export declare class MapUtil {
/**
* Returns all interactions by the given name of a map.
*
* @param {OlMap} map The map to use for lookup.
* @param {string} name The name of the interaction to look for.
* @return The list of result interactions.
*/
static getInteractionsByName(map: OlMap, name: string): import("ol/interaction/Interaction").default[];
/**
* Calculates the appropriate map resolution for a given scale in the given
* units.
*
* See: https://gis.stackexchange.com/questions/158435/
* how-to-get-current-scale-in-openlayers-3
*
* @method
* @param {number|string} scale The input scale to calculate the appropriate
* resolution for.
* @param {Units} units The units to use for calculation (m or degrees).
* @return {number} The calculated resolution.
*/
static getResolutionForScale(scale: number | string, units: Units): number | undefined;
/**
* Returns the appropriate scale for the given resolution and units.
*
* @method
* @param {number|string} resolution The resolutions to calculate the scale for.
* @param {string} units The units the resolution is based on, typically
* either 'm' or 'degrees'.
* @return {number} The appropriate scale.
*/
static getScaleForResolution(resolution: number | string, units: Units): number | undefined;
/**
* Returns all layers of a collection. Even the hidden ones.
*
* @param {OlMap | OlLayerGroup} collection The collection to get the layers
* from. This can be an ol.layer.Group
* or an ol.Map.
* @param {(olLayer: OlBaseLayer) => boolean} [filter] A filter function that receives the layer.
* If it returns true it will be included in the
* returned layers.
* @return {OlBaseLayer} An array of all Layers.
*/
static getAllLayers(collection: OlMap | OlLayerGroup, filter?: (olLayer: OlBaseLayer) => boolean): OlBaseLayer[];
/**
* Get a layer by its key (ol_uid).
*
* @param {OlMap} map The map to use for lookup.
* @param olUid
* @return {OlBaseLayer|undefined} The layer.
*/
static getLayerByOlUid: (map: OlMap, olUid: string) => OlBaseLayer | undefined;
/**
* Returns the layer from the provided map by the given name.
*
* @param {OlMap} map The map to use for lookup.
* @param {string} name The name to get the layer by.
* @return {OlBaseLayer} The result layer or undefined if the layer could not
* be found.
*/
static getLayerByName(map: OlMap, name: string): OlBaseLayer;
/**
* Returns the layer from the provided map by the given name
* (parameter LAYERS).
*
* @param {OlMap} map The map to use for lookup.
* @param {string} name The name to get the layer by.
* @return {WmsLayer|undefined}
* The result layer or undefined if the layer could not be found.
*/
static getLayerByNameParam(map: OlMap, name: string): WmsLayer | undefined;
/**
* Returns the layer from the provided map by the given feature.
*
* @param {OlMap} map The map to use for lookup.
* @param {OlFeature<OlGeometry>} feature The feature to get the layer by.
* @param {string[]} namespaces list of supported GeoServer namespaces.
* @return {OlBaseLayer|undefined} The result layer or undefined if the layer could not
* be found.
*/
static getLayerByFeature(map: OlMap, feature: OlFeature<OlGeometry>, namespaces: string[]): OlBaseLayer | undefined;
/**
* Returns all layers of the specified layer group recursively.
*
* @param {OlMap} map The map to use for lookup.
* @param {OlLayerGroup} layerGroup The group to flatten.
* @return {OlBaseLayer} The (flattened) layers from the group
*/
static getLayersByGroup(map: OlMap, layerGroup: OlLayerGroup): OlBaseLayer[];
/**
* Returns the list of layers matching the given pair of properties.
*
* @param {OlMap} map The map to use for lookup.
* @param {string} key The property key.
* @param {any} value The property value.
*
* @return {OlBaseLayer[]} The array of matching layers.
*/
static getLayersByProperty(map: OlMap, key: string, value: any): OlBaseLayer[];
/**
* Get information about the LayerPosition in the tree.
*
* @param {OlBaseLayer} layer The layer to get the information.
* @param {OlLayerGroup|OlMap} groupLayerOrMap The groupLayer or map
* containing the layer.
* @return {{
* groupLayer: OlLayerGroup,
* position: number
* }} The groupLayer containing the layer and the position of the layer in the collection.
*/
static getLayerPositionInfo(layer: OlBaseLayer, groupLayerOrMap: OlMap | OlLayerGroup): LayerPositionInfo;
/**
* Get the getlegendGraphic url of a layer. Designed for geoserver.
* Currently supported Sources:
* - ol.source.TileWms (with url configured)
* - ol.source.ImageWms (with url configured)
* - ol.source.WMTS (with url configured)
*
* @param {WmsLayer | WmtsLayer} layer The layer that you want to have a legendUrl for.
* @param {Object} extraParams
* @return {string} The getLegendGraphicUrl.
*/
static getLegendGraphicUrl(layer: WmsLayer | WmtsLayer, extraParams?: Record<string, string | number>): string;
/**
* Checks whether the resolution of the passed map's view lies inside of the
* min- and max-resolution of the passed layer, e.g. whether the layer should
* be displayed at the current map view resolution.
*
* @param {OlBaseLayer} layer The layer to check.
* @param {OlMap} map The map to get the view resolution for comparison
* from.
* @return {boolean} Whether the resolution of the passed map's view lies
* inside of the min- and max-resolution of the passed layer, e.g. whether
* the layer should be displayed at the current map view resolution. Will
* be `false` when no `layer` or no `map` is passed or if the view of the
* map is falsy or does not have a resolution (yet).
*/
static layerInResolutionRange(layer?: OlBaseLayer, map?: OlMap): boolean;
/**
* Rounds a scale number depending on its size.
*
* @param {number} scale The exact scale
* @return {number} The roundedScale
*/
static roundScale(scale: number): number;
/**
* Returns the appropriate zoom level for the given scale and units.
* @method
* @param {number} scale Map scale to get the zoom for.
* @param {number[]} resolutions Resolutions array.
* @param {string} units The units the resolutions are based on, typically
* either 'm' or 'degrees'. Default is 'm'.
*
* @return {number} Determined zoom level for the given scale.
*/
static getZoomForScale(scale: number, resolutions: number[], units?: Units): number;
/**
* Fits the map's view to the extent of the passed features.
*
* @param {OlMap} map The map to get the view from.
* @param {OlFeature[]} features The features to zoom to.
*/
static zoomToFeatures(map: OlMap, features: OlFeature[]): void;
/**
* Checks if the given layer is visible for the given resolution.
*
* @param {OlBaseLayer} layer The layer.
* @param {number} resolution The resolution of the map
*/
static isInScaleRange(layer: OlBaseLayer, resolution: number): boolean;
/**
* Converts a given OpenLayers map to an inkmap spec. Only returns options which can be
* derived from a map (center, scale, projection, layers).
*
* @param {OlMap} olMap The ol map.
*
* @return {Promise<Partial<import("../types").InkmapPrintSpec>>} Promise of the inmkap print spec.
*/
static generatePrintConfig(olMap: OlMap): Promise<{
layers: any[];
center: OlCoordinate;
scale: number | undefined;
projection: string;
}>;
/**
* Set visibility for layer having names (if in map)
* @param {OlMap} olMap The OpenLayers map.
* @param {string[]} layerNames An array of layer names (feature type names can also be used)
* @param {boolean} visible if layer should be visible or not
*/
static setVisibilityForLayers(olMap: OlMap, layerNames: string[], visible: boolean): void;
static calculateScaleAndCenterForExtent(olMap: OlMap, extent: OlExtent): {
center: OlCoordinate;
scale: number;
} | undefined;
}
export default MapUtil;