import { Class } from 'utility-types'; import type { StyleSpecification, SourceSpecification, GeoJSONSourceSpecification, LayerSpecification, FilterSpecification, TransitionSpecification, RasterSourceSpecification, RasterDEMSourceSpecification, ImageSourceSpecification, VideoSourceSpecification } from '@mapbox/mapbox-gl-style-spec/types'; import type { GeoJSON } from 'geojson'; import type { ExpressionSpecification, Map as MapboxGLMap } from 'mapbox-gl'; import type { Popup, PopupOptions } from 'mapbox-gl'; type StyleImageMetadata = { pixelRatio: number; sdf: boolean; usvg: boolean; stretchX?: Array<[number, number]>; stretchY?: Array<[number, number]>; content?: [number, number, number, number]; }; export type UtilsMap = MapboxGLMap & { U: MapGlUtils; }; type MapboxGlLib = { Map: Class; Popup: Class; }; import type { UtilsFuncs } from './utilsGenerated'; import type { UtilsLayerDef as UtilsLayerDefBasic } from './layerTypeDefsGenerated'; type SourceBoundUtils = MapGlUtils; type UtilsLayerDef = UtilsLayerDefBasic | LayerSpecification; type SourceOrData = SourceSpecification | string | GeoJSON; export type LayerRef = string | Array | RegExp | ((arg0: LayerSpecification) => boolean); type SourceRef = LayerRef; type PropValue = string | ExpressionSpecification | null | number; type LayerRefFunc = (arg0: LayerRef, ...args: Array) => void; type LayerRefFunc0 = (arg0: LayerRef) => void; type LayerRefFunc1 = (arg0: LayerRef, arg1: T1) => void; type LayerRefFunc2 = (arg0: LayerRef, arg1: T1, arg2: T2) => void; type SourceRefFunc0 = (arg0: SourceRef) => void; type SourceRefFunc1 = (arg0: SourceRef, arg1: T1) => void; type OffHandler = () => void; type LayerCallback = (e: any) => void; declare class _MapGlUtils implements UtilsFuncs { _loaded: boolean; _mapgl: MapboxGlLib | null | undefined; map: UtilsMap; update: (sourceId: string, data?: GeoJSON) => void; /** Initialises Map-GL-Utils on existing map object. @param mapgl Mapbox-GL-JS or Maplibre-GL-JS library. Only needed for later use by `hoverPopup()` etc. @returns Initialised MapGlUtils object. */ static init(map: UtilsMap, mapgl?: MapboxGlLib): MapGlUtils; static newMap(mapboxgl: MapboxGlLib, params?: { style?: {}; }, //hrm should be MapOptions but that type seems incomplete? options?: { addLayers?: Array<{}>; addSources?: Array<{}>; transformStyle?: (arg0: StyleSpecification) => StyleSpecification; mixStyles?: {}; }): Promise; /** * Generates an ["interpolate", ["linear"], input, lowest, ...stops] expression. * @param stops Object of zoom: value pairs. */ static interpolateZoom(stops: number | { [s: string]: unknown; } | ArrayLike, ...moreStops: (number | undefined)[]): any[]; static zoom: typeof _MapGlUtils.interpolateZoom; /** * Generates a ["step", input, lowest, ...steps] expression. * @param expression Expression to use as input. * @param lowest Default value. * @param stops Object of zoom: value pairs. * @example step('size, 2, { 8: 3, }) */ static step(expression: ExpressionSpecification, lowest: number, stops: [number, ExpressionSpecification][] | { number: ExpressionSpecification; } | number, ...moreStops: (number | ExpressionSpecification)[]): any[]; /** * Generates a ["step", ["zoom"], lowest, ...steps] expression. * @param lowest Default value. * @param stops Object of zoom: value pairs. * * @example stepZoom(2, { 8: 3, }) */ static stepZoom(lowest: number, stops: [number, ExpressionSpecification][] | { number: ExpressionSpecification; } | number, ...moreStops: (number | ExpressionSpecification)[]): any[]; /** * Generates a ["interpolate", ["linear"], input, lowest, ...stops] expression. * @example interpolate('size', { 2: 15, 4: 30, }) */ static interpolate(expression: string | ExpressionSpecification, stops: number | { [s: string]: unknown; } | ArrayLike, ...moreStops: (number | undefined)[]): any[]; /** * Generates a ["match", input, output, default] expression. * @example MapGlUtils.match('type', { 'house': '🏠', 'tree': '🌲' }, '❓') * */ static match(expression: string, cases: { [s: string]: unknown; default?: any; }, fallback: number | undefined): unknown[]; /** Sets Map's cursor to 'pointer' whenever the mouse is over these layers. * @returns A function to remove the handler. * @example hoverPointer('poi-circle'); */ hoverPointer(layerOrLayers: LayerRef): () => void; /** * Updates feature-state of features in the connected source[s] whenever hovering over a feature in these layers. * @param layer Layer(s) to add handler to. * @param {string|Array} [source] Source whose features will be updated. If not provided, use the source defined for the layer. * @param {string} [sourceLayer] Source layer (if using vector source) * @param {function} [enterCb] Callback when entering feature. * @param {function} [leaveCb] Callback when leaving feature. * @returns A function to remove the handler. * @example hoverFeatureState('buildings-fill', 'composite', 'buildings', e => console.log(e.features[0].properties.Name), e => console.log('left')); */ hoverFeatureState: (layer: LayerRef, source?: string, sourceLayer?: string, enterCb?: (arg0: {}) => void, leaveCb?: (arg0: {}) => void) => () => void; /** Show a popup whenever hovering over a feature in these layers. @param {string|Array|RegExp|function} layers Layers to attach handler to. @param htmlFunc Function that receives feature and popup, returns HTML. @param {Object} popupOptions Options passed to `Popup()` to customise popup. @example hoverPopup('mylayer', f => `

${f.properties.Name}

${f.properties.Description}`, { anchor: 'left' }); */ hoverPopup(layers: LayerRef, htmlFunc: LayerCallback, popupOptions?: PopupOptions): OffHandler; /** Show a popup whenever a feature in these layers is clicked. * @param {string|Array|RegExp|function} layers Layers to attach handler to. * @param htmlFunc Function that receives feature and popup, returns HTML. * @param {Object} popupOptions Options passed to `Popup()` to customise popup. * @returns A function that removes the handler. * @example clickPopup('mylayer', f => `

${f.properties.Name}

${f.properties.Description}`, { maxWidth: 500 }); */ clickPopup(layers: LayerRef, htmlFunc: (arg0: {}) => void, popupOptions?: PopupOptions): OffHandler; /** Fire a callback whenever a feature in these layers is clicked. * @param {string|Array|RegExp|function} layers Layers to attach handler to. * @param {function} cb Callback that receives event with .features property * @returns A function that removes the handler. * @example clickLayer('mylayer', e => console.log(e.features[0].properties.Name)); */ clickLayer: (arg0: LayerRef, arg1: LayerCallback) => OffHandler; /** * Detects a click in the first of a series of layers given, and fires a callback. * @param {string|Array|RegExp|function} layers Layers to attach handler to. * @param cb Callback, receives `{ event, layer, feature, features }`. * @param noMatchCb Callback when a click happens that misses all these layers. Receives `{ event }`. * @returns A function to remove the handler. * @example clickOneLayer(['pois-label','region-label'], e => console.log(e.features[0].properties.Name), e => console.log('missed')); */ clickOneLayer(layerRef: LayerRef, cb: LayerCallback, noMatchCb: LayerCallback | null | undefined): OffHandler; /** * Fires a callback when mouse hovers over a feature in these layers. * @param {string|Array|RegExp|function} layers Layers to attach handler to. * @returns {function} A function to remove the handler. * @example hoverLayer('pois-symbol', e => console.log(e.features[0].properties.Name)); */ hoverLayer: (layers: LayerRef, cb: LayerCallback) => OffHandler; _mapAddLayerBefore(layerDef: LayerSpecification, beforeLayerId: string | null | undefined): void; /** * Adds a layer, given an id, source, type, and properties. * @param id ID of the new layer. * @param source ID of the source to use. * @param type Type of the layer. * @param [props] Properties defining the layer, per the style spec. Keys can be in camelCase, and paint and layout keys freely mixed. * @param [before] ID of the layer to insert before. */ addLayer(id: string, source: string, type: string, props: {}, before: string | null | undefined): SourceBoundUtils; /** * Adds a layer of any type. * @param id ID of the new layer. * @param source ID of the source to use. * @param type Type of the layer. * @param [props] Properties defining the layer, per the style spec. Keys can be in camelCase, and paint and layout keys freely mixed. * @param [before] ID of the layer to insert before. * @returns A SourceBoundUtils object for chaining. * @example add('mylayer', 'mysource', 'line', { lineColor:'red' }); * @deprecated Use addLineLayer, addFillLayer, etc. */ add(id: string, source: SourceOrData, type: string, props: {}, before?: string): SourceBoundUtils | null | undefined; setLayer(layerId: string, source: string, type: string, props: UtilsLayerDef, before?: string): SourceBoundUtils; /** * Removes one or more layers. * @param {string|Array|RegExp|function} layers Layers to remove. * @returns void * @example removeLayer(['tree-labels','building-labels']) */ removeLayer: LayerRefFunc; /** Adds a layer of type `line`.*/ addLineLayer(id: string, source: string, props: {}, before?: string): void; /** Adds a layer of type `fill`.*/ addFillLayer(id: string, source: string, props: {}, before?: string): void; /** Adds a layer of type `circle`.*/ addCircleLayer(id: string, source: string, props: {}, before?: string): void; /** Adds a layer of type `symbol`.*/ addSymbolLayer(id: string, source: string, props: {}, before?: string): void; /** Adds a layer of type `video`.*/ addVideoLayer(id: string, source: string, props: {}, before?: string): void; /** Adds a layer of type `raster`.*/ addRasterLayer(id: string, source: string, props: {}, before?: string): void; /** Adds a layer of type `fill-extrusion`.*/ addFillExtrusionLayer(id: string, source: string, props: {}, before?: string): void; /** Adds a layer of type `heatmap`.*/ addHeatmapLayer(id: string, source: string, props: {}, before?: string): void; /** Adds a layer of type `hillshade`.*/ addHillshadeLayer(id: string, source: string, props: {}, before?: string): void; /** Create a GeoJSON source or update properties if already present. * @param sourceId ID of the new source. * @param {GeoJSON} [geojson] Optional GeoJSON data. * @param {object} [props] Properties defining the source, per the style spec. */ addGeoJSONSource(sourceId: string, geojson?: GeoJSON | string | null | undefined, props?: GeoJSONSourceSpecification | null | undefined): SourceBoundUtils; /** Create a GeoJSON source or update properties if already present. * @param sourceId ID of the new source. * @param {GeoJSON} [geojson] Optional GeoJSON data. * @param {object} [props] Properties defining the source, per the style spec. */ addGeoJSON(sourceId: string, geojson?: GeoJSON | null | undefined, props?: GeoJSONSourceSpecification | null | undefined): SourceBoundUtils; /** * Adds or updates a source in the style. * @param id ID of the new source. * @param sourceDef Properties defining the source, per the style spec. * @returns A SourceBoundUtils object for chaining. * @example addSource('mysource', { type: 'geojson', data: { type: 'FeatureCollection', features: [] } }); */ addSource(id: string, sourceDef: SourceSpecification): SourceBoundUtils; layersBySource(source: string): Array; /** Adds a `vector` source * @param sourceId ID of the new source. * @param {string} [data] Optional URL of source tiles (.../{z}/{x}/{y}...), mapbox:// URL or TileJSON endpoint. * @param {object} props Properties defining the source, per the style spec. * @example addVector('mysource', 'http://example.com/tiles/{z}/{x}/{y}.pbf', { maxzoom: 13 }); */ addVectorSource(sourceId: string, props: string | {}, extraProps?: {}): SourceBoundUtils; addVector(sourceId: string, props: string | {}, extraProps?: {}): SourceBoundUtils; /** Adds a `raster` source @param sourceId ID of the new source. @param {object} props Properties defining the source, per the style spec. */ addRasterSource(sourceId: string, props: RasterSourceSpecification): SourceBoundUtils; /** Adds a `raster-dem` source @param sourceId ID of the new source. @param {object} props Properties defining the source, per the style spec. */ addRasterDemSource(sourceId: string, props: RasterDEMSourceSpecification): SourceBoundUtils; /** Adds an `image` source @param sourceId ID of the new source. @param {object} props Properties defining the source, per the style spec. */ addImageSource(sourceId: string, props: ImageSourceSpecification): SourceBoundUtils; /** Adds a `video` source @param sourceId ID of the new source. @param {object} props Properties defining the source, per the style spec. */ addVideoSource(sourceId: string, props: VideoSourceSpecification): SourceBoundUtils; /** Sets a paint or layout property on one or more layers. * @param {string|Array|RegExp|function} layers Layers to update. * @param {string|object} prop Property to update, or object of properties. * @param {any} [value] Value to set property to. * @example setProperty(['buildings-fill', 'parks-fill'], 'fillOpacity', 0.5) */ setProperty: LayerRefFunc2; /** * Converts a set of properties in pascalCase or kebab-case into a layer objectwith layout and paint properties. * @param {object} props Properties to convert. * @returns {object} Layer object with layout and paint properties. * @example properties({ fillOpacity: 0.5, fillColor: 'red' }) * // { paint: { 'fill-opacity': 0.5, 'fill-color': 'red' } } * */ properties(props?: {}): {} | null | undefined; layerStyle(...args: Array): LayerSpecification; /** * Gets the layer definition for a given layer id, as per the style spec. * @param {string} layerId * @returns {LayerSpecification} Layer definition object. */ getLayerStyle(layerId: string): LayerSpecification | undefined; /** * Updates multiple properties for one or more layers. * @param {string|Array|RegExp|function} layers Layers to update. * @param {object} props Properties to update. * @example setLayerStyle('buildings-fill', { fillOpacity: 0.5, fillColor: 'red' }); */ setLayerStyle: LayerRefFunc1<{}>; /** Replaces the current data for a GeoJSON layer. * @param sourceId Id of the source being updated. * @param {GeoJSON} [data] GeoJSON object to set. If not provided, defaults to an empty FeatureCollection. * @example setData('trees', { type: 'FeatureCollection', features: [ ... ] }); */ setData(sourceId: string, data?: GeoJSON): void; /** Makes the given layers visible. * @param {string|Array|RegExp|function} Layers to show. * @example map.U.show(['buildings-fill', 'buildings-outline', 'buildings-label']); */ show: LayerRefFunc0; /** Makes the given layers hidden. * @param {string|Array|RegExp|function} Layers to hide. * @example map.U.hide(/^buildings-/); */ hide: LayerRefFunc0; /** Makes the given layers hidden or visible, depending on an argument. * @param {string|Array|RegExp|function} Layer to toggle. * @param {boolean} state True for visible, false for hidden. * @example map.U.toggle(/^buildings-/, layers.showBuildings); */ toggle: LayerRefFunc1; /** * Makes all layers depending on a given source visible. * @param {string} sourceId Source[s] whose layers will be toggled. * @example map.U.showSource('trees'); * */ showSource: SourceRefFunc0; /** * Makes all layers depending on a given source hidden. * @param {string} sourceId Source[s] whose layers will be toggled. * @example map.U.hideSource('trees'); * */ hideSource: SourceRefFunc0; /** Makes the given layers connected to a given source hidden or visible, depending on an argument. @param {string} sourceId Source[s] whose layers will be toggled. @param {boolean} state True for visible, false for hidden.*/ toggleSource: SourceRefFunc1; /** Replace the filter for one or more layers. * @param {string|Array|RegExp|function} layers Layers to update. * @param {Array} filter New filter to set. * @example map.U.setFilter(['buildings-fill', 'buildings-outline', 'buildings-label'], ['==','level','0']]); */ setFilter: LayerRefFunc1; /** Removes one or more sources, first removing all layers that depend on them. Not an error if source doesn't exist. @param {SourceRef} sources */ removeSource: SourceRefFunc0; /** Changes the source of an existing layer, by removing and readding the source. * @example setLayerSource(['trees-circle', 'trees-label'], 'allpoints', 'trees') * @param {string|Array|RegExp|function} layerId Layer[s] whose source will be changed. * @param {string} sourceId New source ID to set. * @param {string} [sourceLayer] New source layer to set. * */ setLayerSource: LayerRefFunc2; /** Callback that fires when map loads, or immediately if map is already loaded. @returns {Promise} Promise, if callback not provided. */ onLoad(cb?: (arg0: void) => void): void | Promise; /** * Set a property on the style's root, such as `light` or `transition`. * @param {string} propName Name of the property to set. * @param {any} val Value to set the property to. * @example setRootProperty('transition', { duration: 500, delay: 100 }) * */ setRootProperty(propName: string, val: PropValue | TransitionSpecification): void; /** Sets root transition property. * @param {TransitionSpecification} val Transition object. * @example setTransition({ duration: 500, delay: 100 }) */ setTransition(val: TransitionSpecification): void; /** Adds an image for use in a symbol layer, from a URL. * @param {string} id ID of the image. * @param {string} url URL of the image. * @param {StyleImageMetadata} [options] Options for the image. * @example loadImage('marker', '/assets/marker-pin@2x.png', { pixelRatio: 2}) */ loadImage(id: string, url: string, options?: StyleImageMetadata): any; /** * Forcibly prevents the map's pitch or bearing being changed by the user. * @example lockOrientation( * */ lockOrientation(): void; /** * Gets array of font names in use, determined by traversing style. Does not detect fonts in all possible situations. * @returns {Array[string]} * */ fontsInUse(): Array; _makeSource(sourceId: string): SourceBoundUtils; } export type MapGlUtils = _MapGlUtils & UtilsFuncs; export default _MapGlUtils; //# sourceMappingURL=index.d.ts.map