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]; }; type UtilsMap = MapboxGLMap & { U: MapGlUtils | null | undefined; }; 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; static interpolateZoom(stops: number | { [s: string]: unknown; } | ArrayLike, ...moreStops: (number | undefined)[]): any[]; static zoom: typeof _MapGlUtils.interpolateZoom; static step(expression: ExpressionSpecification, lowest: number, stops: [number, ExpressionSpecification][] | { number: ExpressionSpecification; } | number, ...moreStops: (number | ExpressionSpecification)[]): any[]; static stepZoom(lowest: number, stops: [number, ExpressionSpecification][] | { number: ExpressionSpecification; } | number, ...moreStops: (number | ExpressionSpecification)[]): any[]; static interpolate(expression: string | ExpressionSpecification, stops: number | { [s: string]: unknown; } | ArrayLike, ...moreStops: (number | undefined)[]): any[]; static match(expression: string, cases: { [s: string]: unknown; default?: any; }, fallback: number | undefined): any[]; /** Sets Map's cursor to 'pointer' whenever the mouse is over these layers. @returns A function to remove the handler. */ 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) */ 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. */ 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. */ 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 A function to remove the handler. */ hoverLayer: (layers: LayerRef, cb: LayerCallback) => OffHandler; _mapAddLayerBefore(layerDef: LayerSpecification, beforeLayerId: string | null | undefined): void; /** Adds a layer, given an id, source, type, and properties. */ addLayer(id: string, source: string, type: string, props: {}, before: string | null | undefined): SourceBoundUtils; 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; removeLayer: LayerRefFunc; /** Adds a layer of type `line`.*/ addLineLayer(id: string, props: {}, before?: string): void; /** Adds a layer of type `fill`.*/ addFillLayer(id: string, props: {}, before?: string): void; /** Adds a layer of type `circle`.*/ addCircleLayer(id: string, props: {}, before?: string): void; /** Adds a layer of type `symbol`.*/ addSymbolLayer(id: string, props: {}, before?: string): void; /** Adds a layer of type `video`.*/ addVideoLayer(id: string, props: {}, before?: string): void; /** Adds a layer of type `raster`.*/ addRasterLayer(id: string, props: {}, before?: string): void; /** Adds a layer of type `fill-extrusion`.*/ addFillExtrusionLayer(id: string, props: {}, before?: string): void; /** Adds a layer of type `heatmap`.*/ addHeatmapLayer(id: string, props: {}, before?: string): void; /** Adds a layer of type `hillshade`.*/ addHillshadeLayer(id: string, props: {}, before?: string): void; /** Create a GeoJSON layer. */ addGeoJSONSource(id: string, geojson: GeoJSON | null | undefined, props: GeoJSONSourceSpecification | null | undefined): SourceBoundUtils; addGeoJSON(id: string, geojson: GeoJSON | null | undefined, props: GeoJSONSourceSpecification | null | undefined): SourceBoundUtils; 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. @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. */ properties(props?: {}): {} | null | undefined; layerStyle(...args: Array): LayerSpecification; /** Gets the layer definition for a given layer id, as per the style spec.. */ getLayerStyle(layerId: string): LayerSpecification | undefined; 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. */ setData(sourceId: string, data?: GeoJSON): void; /** Makes the given layers visible. @param {string|Array|RegExp|function} Layer to toggle. */ show: LayerRefFunc0; /** Makes the given layers hidden. @param {string|Array|RegExp|function} Layer to toggle. */ 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. */ toggle: LayerRefFunc1; /** Makes all layers depending on a given source visible. */ showSource: SourceRefFunc0; /** Makes all layers depending on a given source hidden. */ 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 attach handler to. @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`. */ setRootProperty(propName: string, val: PropValue | TransitionSpecification): void; /** Sets root transition property. @example setTransition({ duration: 500, delay: 100 }) */ setTransition(val: TransitionSpecification): void; /** Adds an image for use as a symbol layer, from a URL. @example loadImage('marker', '/assets/marker-pin@2x.png', { pixelRatio: 2}) */ loadImage(id: string, url: string, options?: StyleImageMetadata): any; 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