leaflet
Version:
JavaScript library for mobile-friendly interactive maps
129 lines (128 loc) • 5.1 kB
TypeScript
import { Layer } from './Layer.js';
import type { Feature, FeatureCollection, MultiPoint } from 'geojson';
import type { InteractiveLayerEventMap, InteractiveLayerOptions } from '../types.js';
import type { LatLng } from '../geo/LatLng.js';
import type { LatLngBounds } from '../geo/LatLngBounds.js';
import type { LeafletMap } from '../map/Map.js';
import type { LayerBase } from './LayerBase.js';
export type MemberLayer<L extends LayerBase = Layer> = L & {
setZIndex?(zIndex: number): unknown;
setStyle?(style?: object): unknown;
bringToFront?(): unknown;
bringToBack?(): unknown;
getBounds?(): LatLngBounds;
getLatLng?(): LatLng;
toGeoJSON?(precision?: number | false): Feature | FeatureCollection;
};
/** @import {Feature, FeatureCollection, MultiPoint, Position} from 'geojson' */
/** @import {InteractiveLayerEventMap, InteractiveLayerOptions} from '../types.js' */
/** @import {LatLng} from '../geo/LatLng.js' */
/** @import {LatLngBounds} from '../geo/LatLngBounds.js' */
/** @import {LeafletMap} from '../map/Map.js' */
/** @import {Marker} from './marker/Marker.js' */
/** @import {LayerBase} from './LayerBase.js' */
/**
* @template {LayerBase} [L=Layer]
* @typedef {L & {
* setZIndex?(zIndex: number): unknown,
* setStyle?(style?: object): unknown,
* bringToFront?(): unknown,
* bringToBack?(): unknown,
* getBounds?(): LatLngBounds,
* getLatLng?(): LatLng,
* toGeoJSON?(precision?: number | false): Feature | FeatureCollection
* }} MemberLayer
*/
/**
* Used to group several layers and handle them as one. If you add it to the map, any layers added
* or removed from the group will be added/removed on the map as well. Extends `Layer`.
* @example
* ```js
* new LayerGroup([marker1, marker2])
* .addLayer(polyline)
* .addTo(map);
* ```
* @template {LayerBase} [L=Layer]
* @template {InteractiveLayerOptions} [O=InteractiveLayerOptions]
* @template {InteractiveLayerEventMap} [E=InteractiveLayerEventMap]
* @extends {Layer<O, E>}
*/
export declare class LayerGroup<L extends LayerBase = Layer, O extends InteractiveLayerOptions = InteractiveLayerOptions, E extends InteractiveLayerEventMap = InteractiveLayerEventMap> extends Layer<O, E> {
/** @type {{[id: number]: MemberLayer<L>}} */
_layers: {
[id: number]: MemberLayer<L>;
};
static initHooks: boolean;
/**
* Create a layer group, optionally given an initial set of layers and an `options` object.
* @param {NoInfer<L>[]} [layers]
* @param {NoInfer<Partial<O>>} [options]
*/
constructor(layers?: NoInfer<L>[], options?: NoInfer<Partial<O>>);
/**
* Adds the given layer to the group.
* @param {L} layer
*/
addLayer(layer: L): this;
/**
* Removes the given layer, or the layer with the given internal ID, from the group.
* @param {L | number} layer
*/
removeLayer(layer: L | number): this;
/**
* Returns `true` if the given layer, or the layer with the given internal ID, is currently added to the group.
* @param {L | number} layer
*/
hasLayer(layer: L | number): boolean;
/** Removes all the layers from the group. */
clearLayers(): this;
/** @param {LeafletMap} map */
onAdd(map: LeafletMap): void;
/** @param {LeafletMap} map */
onRemove(map: LeafletMap): void;
/**
* Iterates over the layers of the group, optionally specifying context of the iterator function.
* ```js
* group.eachLayer(layer => layer.bindPopup('Hello'));
* ```
* @param {(layer: L) => void} method
* @param {unknown} [context]
*/
eachLayer(method: (layer: L) => void, context?: unknown): this;
/**
* Returns the layer with the given internal ID.
* @param {number} id
* @returns {L | undefined}
*/
getLayer(id: number): L | undefined;
/**
* Returns an array of all the layers added to the group.
* @returns {L[]}
*/
getLayers(): L[];
/**
* Calls `setZIndex` on every layer contained in this group, passing the z-index.
* @param {number} zIndex
*/
setZIndex(zIndex: number): this;
/**
* Returns the internal ID for a layer
* @param {L} layer
*/
getLayerId(layer: L): number;
/**
* Returns a GeoJSON `MultiPoint` feature with the positions of the group's markers. `precision` is the number of
* decimal places for coordinates, as in [`toGeoJSON`](#layergroup-togeojson).
* @param {number | false} [precision]
* @returns {Feature<MultiPoint>}
*/
toMultiPoint(precision?: number | false): Feature<MultiPoint>;
/**
* Coordinates values are rounded with [`formatNum`](#util-formatnum) function with given `precision`.
* Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON) representation of the layer group
* (as a GeoJSON `FeatureCollection`, `GeometryCollection`, or `MultiPoint`).
* @param {number | false} [precision]
* @returns {Feature | FeatureCollection}
*/
toGeoJSON(precision?: number | false): Feature | FeatureCollection;
}