UNPKG

@terrestris/ol-util

Version:

A set of helper classes for working with openLayers

61 lines (60 loc) 3.08 kB
import OlFeature from 'ol/Feature'; import OlGeometry from 'ol/geom/Geometry'; /** * Helper class for working with OpenLayers features. * * @class FeatureUtil */ declare class FeatureUtil { /** * Returns the featureType name out of a given feature. It assumes that * the feature has an ID in the following structure FEATURETYPE.FEATUREID. * * @param {import("ol/Feature").default} feature The feature to obtain the featureType * name from. * @return {string|undefined} The (unqualified) name of the featureType or undefined if * the name could not be picked. */ static getFeatureTypeName(feature: OlFeature<OlGeometry>): string | undefined; /** * Extracts the featureType name from given GetFeatureInfo URL. * This method is mostly useful for raster layers which features could have * no ID set. * * @param {string} url GetFeatureInfo URL possibly containing featureType name. * @param {boolean} qualified Whether the qualified featureType name should be * returned or not. Default is true. * * @return {string|undefined} Obtained featureType name as string. */ static getFeatureTypeNameFromGetFeatureInfoUrl(url: string, qualified?: boolean): string | undefined; /** * Resolves the given template string with the given feature attributes, e.g. * the template "Size of area is {{AREA_SIZE}} km²" would be to resolved * to "Size of area is 1909 km²" (assuming the feature's attribute AREA_SIZE * really exists). * * @param {import("ol/Feature").default} feature The feature to get the attributes from. * @param {string} template The template string to resolve. * @param {string} [noValueFoundText] The text to apply, if the templated value * could not be found, default is to 'n.v.'. * @param {(key: string, val: string) => string} [valueAdjust] A method that will be called with each * key/value match, we'll use what this function returns for the actual * replacement. Optional, defaults to a function which will return the raw * value it received. This can be used for last minute adjustments before * replacing happens, e.g. to filter out falsy values or to do number * formatting and such. * @param {boolean} leaveAsUrl If set to true, template won't be wrapped into * <a>-tag and will be returned as URL. Default is false. * @return {string} The resolved template string. */ static resolveAttributeTemplate(feature: OlFeature<OlGeometry>, template: string, noValueFoundText?: string, valueAdjust?: (key: string, val: any) => any, leaveAsUrl?: boolean): string; /** * Maps an array of features to an array of geometries. * * @param {import("ol/Feature").default[]} features * @return {import("ol/Geometry").default[]} The geometries of the features */ static mapFeaturesToGeometries(features: OlFeature<OlGeometry>[]): OlGeometry[]; } export default FeatureUtil;