UNPKG

mobility-toolbox-js

Version:

Toolbox for JavaScript applications in the domains of mobility and logistics.

150 lines (149 loc) 5.87 kB
import { Layer } from 'ol/layer'; import MaplibreStyleLayerRenderer from '../renderers/MaplibreStyleLayerRenderer'; import type { FeatureState } from 'maplibre-gl'; import type { Feature, Map } from 'ol'; import type { EventsKey } from 'ol/events'; import type { ObjectEvent } from 'ol/Object'; import type { FilterFunction } from '../../common/typedefs'; import type { MobilityLayerOptions } from './Layer'; import type { MaplibreLayerOptions } from './MaplibreLayer'; import type MaplibreLayer from './MaplibreLayer'; export type MaplibreStyleLayerOptions = { beforeId?: string; layers?: maplibregl.AddLayerObject[]; layersFilter?: FilterFunction; maplibreLayer?: MaplibreLayer; queryRenderedLayersFilter?: FilterFunction; } & MaplibreLayerOptions & MobilityLayerOptions; /** * Layer that helps show/hide a specific subset of style layers of a [MaplibreLayer](./MaplibreLayer.js~MaplibreLayer.html). * * @example * import { MaplibreLayer, MocoLayer } from 'mobility-toolbox-js/ol'; * * const maplibreLayer = new MaplibreLayer({ * apiKey: 'yourApiKey', * }); * * const layer = new MocoLayer({ * maplibreLayer: maplibreLayer, * layersFilter: (layer) => { * // show/hide only style layers related to stations * return /station/.test(layer.id); * }, * }); * * @extends {ol/layer/Layer~Layer} * @public */ declare class MaplibreStyleLayer extends Layer { highlightedFeatures: Feature[]; olEventsKeys: EventsKey[]; selectedFeatures: Feature[]; get beforeId(): string | undefined; set beforeId(newValue: string | undefined); get layers(): maplibregl.AddLayerObject[]; set layers(newValue: maplibregl.AddLayerObject[]); get layersFilter(): (layer: maplibregl.LayerSpecification) => boolean; set layersFilter(newValue: (layer: maplibregl.LayerSpecification) => boolean); /** * @deprecated Use MaplibreStyleLayer.maplibreLayer instead. */ get mapboxLayer(): MaplibreLayer | undefined; get maplibreLayer(): MaplibreLayer | undefined; set maplibreLayer(newValue: MaplibreLayer | undefined); get queryRenderedLayersFilter(): (layer: maplibregl.LayerSpecification) => boolean; set queryRenderedLayersFilter(newValue: (layer: maplibregl.LayerSpecification) => boolean); get sources(): Record<string, maplibregl.SourceSpecification>; set sources(newValue: Record<string, maplibregl.SourceSpecification>); /** * @deprecated Use MaplibreStyleLayer.layer instead. */ get styleLayer(): maplibregl.AddLayerObject; /** * @deprecated */ set styleLayer(newValue: maplibregl.AddLayerObject); /** * Apply visibility to style layers that fits the styleLayersFilter function. */ /** * @deprecated */ get styleLayers(): maplibregl.AddLayerObject[]; /** * @deprecated */ set styleLayers(newValue: maplibregl.AddLayerObject[]); /** * Constructor. * * @param {Object} options * @param {string} [options.beforeId] The style layer id to use when the options.layers property is defined, unsused otherwise. * @param {maplibregl.AddLayerObject[]} [options.layers] The layers to add to the style on load. * @param {FilterFunction} [options.layersFilter] Filter function to decide which style layer to apply visiblity on. If not provided, the 'layers' property is used. * @param {MaplibreLayer} [options.maplibreLayer] The MaplibreLayer to use. * @param {FilterFunction} [options.queryRenderedLayersFilter] Filter function to decide which style layer are available for query. * @param {{[id: string]:maplibregl.SourceSpecification}} [options.sources] The sources to add to the style on load. * @public */ constructor(options?: MaplibreStyleLayerOptions); addLayers(): void; addSources(): void; applyLayoutVisibility(evt?: ObjectEvent): void; /** * Initialize the layer. * @param {ol/Map~Map} map the Maplibre map. * @override */ attachToMap(map: Map): void; /** * Create a copy of the MaplibreStyleLayer. * * @param {Object} newOptions Options to override. See constructor. * @return {MapboxStyleLayer} A MaplibreStyleLayer. * @public */ clone(newOptions: MaplibreStyleLayerOptions): MaplibreStyleLayer; createRenderer(): MaplibreStyleLayerRenderer; /** * Terminate the layer. * @override */ detachFromMap(): void; /** * Highlight a list of features. * @param {Array<ol/Feature~Feature>} [features=[]] Features to highlight. * @deprecated Use layer.setFeatureState(features, {hover: true|false}) instead. */ highlight(features?: Feature[]): void; /** * On Maplibre map load callback function. Add style layers and dynaimc filters. */ onLoad(): void; removeLayers(): void; removeSources(): void; /** * Select a list of features. * @param {Array<ol/Feature~Feature>} [features=[]] Features to select. * @deprecated Use layer.setFeatureState(features, {selected: true|false}) instead. */ select(features?: Feature[]): void; /** * Set the [feature state](https://maplibre.org/maplibre-style-spec/expressions/#feature-state) of the features. * * @param {ol/Feature~Feature[]} features * @param {{[key: string]: any}} state The feature state * @public */ setFeatureState(features: Feature[], state: FeatureState): void; /** * Set if features are hovered or not. * @param {Array<ol/Feature~Feature>} features * @param {boolean} state Is the feature hovered * @deprecated Use layer.setFeatureState(features, {hover: true|false}) instead. */ setHoverState(features: Feature[], state: boolean): void; setMapInternal(map: Map): void; } export default MaplibreStyleLayer;