import * as L from 'leaflet'; import { DistanceGrid } from './DistanceGrid.js'; import { MarkerCluster } from './MarkerCluster.js'; import './MarkerPatches.js'; import type { CRS, DivIcon, FeatureGroupEventMap, Icon, InteractiveLayerOptions, LatLng, LatLngBounds, Layer, LayerGroup, LeafletEvent, LeafletMap, LeafletPointerEvent, Marker, Point, Polygon, Polyline, PolylineOptions, PopupEvent } from 'leaflet'; import type { ClusterChild } from './MarkerCluster.js'; export type MarkerClusterGroupProps = { /** * The maximum distance in pixels from a cluster's * center to its markers, or a function that returns it for a zoom. Smaller makes more, smaller clusters. */ maxClusterRadius: number | ((zoom: number) => number); /** * Creates the icon of a cluster. The * default shows the marker count, styled by `MarkerCluster.Default.css`. */ iconCreateFunction: (cluster: MarkerCluster) => Icon | DivIcon; /** * The accessible name of a cluster's icon, * read out by screen readers, e.g. to translate it; "N markers" by default. */ clusterLabel: (cluster: MarkerCluster) => string; /** * The map pane for clusters; the marker pane if not set. */ clusterPane: string; /** * Spiderfy a cluster when clicked at any zoom. */ spiderfyOnEveryZoom: boolean; /** * Spiderfy a cluster when clicked at the bottom zoom, where it can't split. */ spiderfyOnMaxZoom: boolean; /** * Show the bounds of a cluster's markers on hover. */ showCoverageOnHover: boolean; /** * Zoom to a cluster's bounds when it's clicked. */ zoomToBoundsOnClick: boolean; /** * Give single markers the cluster icon too, as clusters of 1. */ singleMarkerMode: boolean; /** * Don't cluster markers at this zoom and above. */ disableClusteringAtZoom: number | null; /** * Remove clusters and markers far from the view from the map, for * performance. */ removeOutsideVisibleBounds: boolean; /** * Animate clusters splitting and merging on zoom, and spiderfying. */ animate: boolean; /** * How long those animations take, in milliseconds. */ animationDuration: number; /** * Animate markers added with `addLayer` into their clusters, once the group * is on the map. Slow for many markers; `addLayers` never animates. */ animateAddingMarkers: boolean; /** * Places spiderfied * markers: gets their count and the cluster's position in layer pixels, returns their positions. */ spiderfyShapePositions: ((count: number, centerPoint: Point) => Point[]) | null; /** * Scales the distance of spiderfied markers from the center, e.g. for * big icons. */ spiderfyDistanceMultiplier: number; /** * Style of spider legs. */ spiderLegPolylineOptions: PolylineOptions; /** * Opacity of a cluster while it's spiderfied. */ spiderfiedClusterOpacity: number; /** * Split `addLayers` into chunks with breaks in between, so that the page doesn't * freeze. */ chunkedLoading: boolean; /** * Milliseconds of processing per chunk. */ chunkInterval: number; /** * Milliseconds between chunks. */ chunkDelay: number; /** * Called after each * chunk with the number of markers processed and total, and the milliseconds since the start, e.g. for a * progress bar. */ chunkProgress: ((processed: number, total: number, elapsed: number) => void) | null; /** * Style of the * coverage polygon shown on hover, or a function that returns it for a cluster. */ polygonOptions: PolylineOptions | ((cluster: MarkerCluster) => PolylineOptions); }; export type MarkerClusterGroupOptions = InteractiveLayerOptions & Partial>; export type ClusterPointerEvent = LeafletPointerEvent & { layer: MarkerCluster; }; export type SpiderfyEvent = LeafletEvent & { cluster: MarkerCluster; markers: M[]; }; export type MarkerClusterGroupEvents = { /** * Fired when a cluster is clicked, or activated with the keyboard. */ clusterclick: ClusterPointerEvent; clusterdblclick: ClusterPointerEvent; clustercontextmenu: ClusterPointerEvent; /** * Fired when the pointer enters a cluster. */ clustermouseover: ClusterPointerEvent; /** * Fired when the pointer leaves a cluster. */ clustermouseout: ClusterPointerEvent; /** * Fired when a cluster has spread out its markers. */ spiderfied: SpiderfyEvent; /** * Fired when a cluster has brought its markers back in. */ unspiderfied: SpiderfyEvent; /** * Fired when clusters have finished splitting or merging after a zoom. */ animationend: LeafletEvent; }; export type MarkerClusterGroupEventMap = FeatureGroupEventMap & MarkerClusterGroupEvents; /** * A `FeatureGroup` that clusters the markers in it. Layers that aren't points, like polylines, are kept as they are. * @template {Layer} [M=Marker] The layers in the group. * @extends {L.FeatureGroup & MarkerClusterGroupProps, MarkerClusterGroupEventMap>} */ export declare class MarkerClusterGroup extends L.FeatureGroup & MarkerClusterGroupProps, MarkerClusterGroupEventMap> { /** @type {L.FeatureGroup} */ _featureGroup: L.FeatureGroup; /** @type {L.FeatureGroup} */ _nonPointGroup: L.FeatureGroup; /** @type {number} */ _inZoomAnimation: number; /** @type {boolean} */ _ignoreMove: boolean; /** Markers not in the clusters: added while we aren't on the map, or being dragged. @type {Set>} */ _needsClustering: Set>; /** @type {Array<() => void>} */ _queue: Array<() => void>; /** @type {number | null} */ _queueTimeout: number | null; /** The cluster currently spiderfied, if any. @type {MarkerCluster | null} */ _spiderfied: MarkerCluster | null; /** * Spiderfied markers with their legs and real latlngs, until they're back in the cluster (the latlng is restored * as soon as the unspiderfy animation starts, the leg is removed when it ends). * @type {Map, {leg: Polyline, latlng: LatLng | null}>} */ _spiders: Map, { leg: Polyline; latlng: LatLng | null; }>; /** @type {Polygon | null} */ _shownPolygon: Polygon | null; /** * Markers being dragged, which wait in _needsClustering and are shown as they are until dragend. Markers get * a listener for move only, since each costs ~100 bytes per marker: drags are told apart by the pointer or * key event of their moves, and dragend is listened to only during one. * @type {Set>} */ _dragging: Set>; /** The marker being reclustered after a move, which stays on the map meanwhile. @type {ClusterChild | null} */ _moving: ClusterChild | null; /** Markers and clusters panned out of view but kept on the map for their open popup. @type {Set | MarkerCluster>} */ _keptForPopup: Set | MarkerCluster>; /** Bumped by clearLayers, which stops the chunked addLayers calls started before it. @type {number} */ _generation: number; /** The cluster class to create, animated or not. @type {typeof MarkerCluster} */ _markerCluster: typeof MarkerCluster; /** @type {number | undefined} */ _maxLat: number | undefined; /** @type {number} */ _zoom: number; /** The bounds of the currently shown area, from _getExpandedVisibleBounds. @type {LatLngBounds} */ _currentShownBounds: LatLngBounds; /** The lowest zoom with clusters. @type {number} */ _minZoom: number; /** The highest zoom with clusters. @type {number} */ _maxZoom: number; /** @type {typeof CRS} */ _crs: typeof CRS; /** @type {{[zoom: number]: DistanceGrid>}} */ _gridClusters: { [zoom: number]: DistanceGrid>; }; /** @type {{[zoom: number]: DistanceGrid>}} */ _gridUnclustered: { [zoom: number]: DistanceGrid>; }; /** * The points of the markers in the distance grids, projected once at _maxZoom, where every grid works * with its radius scaled to match. Clusters keep theirs in _gridPoint. * @type {Map, Point>} */ _points: Map, Point>; /** @type {MarkerCluster} */ _topClusterLevel: MarkerCluster; static initHooks: boolean; /** @param {MarkerClusterGroupOptions} [options] */ constructor(options?: MarkerClusterGroupOptions); /** @param {MarkerClusterGroupOptions} [options] */ _initGroup(options?: MarkerClusterGroupOptions): void; /** * Adds a marker, or a layer group's layers, to be clustered. Layers that aren't points are added as they are. * @param {M | LayerGroup} layerOrGroup * @returns {this} */ addLayer(layerOrGroup: M | LayerGroup): this; /** * Removes a marker, or a layer group's layers. * @param {M | LayerGroup | number} layerOrGroup A layer, a layer group, or a layer's id. * @returns {this} */ removeLayer(layerOrGroup: M | LayerGroup | number): this; /** * Adds markers and layer groups in bulk, much faster than one by one. With `chunkedLoading`, the rest of them * are added in chunks after this returns. * @param {Array> | M | LayerGroup} layersArray * @param {boolean} [skipLayerAddEvent] Don't fire `layeradd` for each layer. * @returns {this} */ addLayers(layersArray: Array> | M | LayerGroup, skipLayerAddEvent?: boolean): this; /** * Removes markers and layer groups in bulk, much faster than one by one. * @param {Array> | M | LayerGroup} layersArray * @returns {this} */ removeLayers(layersArray: Array> | M | LayerGroup): this; /** Removes all layers from the group. */ clearLayers(): this; /** The bounds of all layers in the group. */ getBounds(): LatLngBounds; /** * Calls `method` on each layer in the group, including the markers in clusters. * @param {(layer: M) => void} method * @param {unknown} [context] */ eachLayer(method: (layer: M) => void, context?: unknown): this; /** * All layers in the group, including the markers in clusters. * @returns {M[]} */ getLayers(): M[]; /** * The layer with the given id (see `L.Util.stamp`). Goes through all layers, so it's slow for many. * @param {number} id * @returns {M | undefined} */ getLayer(id: number): M | undefined; /** * Whether the layer is in the group, either in a cluster or not. For a layer group, whether all its layers are. * @param {M | LayerGroup | number} layer A layer, a layer group, or a layer's id. * @returns {boolean} */ hasLayer(layer: M | LayerGroup | number): boolean; /** * Zooms in to show the marker, spiderfying its cluster if needed, then calls the callback. Does nothing if the group * isn't on the map or doesn't have the marker, and stops without calling the callback if either changes on the way. * @param {M} marker * @param {() => void} [callback] */ zoomToShowLayer(marker: M, callback?: () => void): void; /** @param {LeafletMap} map */ onAdd(map: LeafletMap): void; /** @param {LeafletMap} map */ onRemove(map: LeafletMap): void; /** * The marker if it's shown on the map, or the cluster it's shown in, or null if neither is (e.g. out of view). * @param {M} marker * @returns {M | MarkerCluster | null} */ getVisibleParent(marker: M): M | MarkerCluster | null; /** * The cluster a marker or cluster is directly in, whether shown or not, so calling it again walks up to the * lowest zoom. Null if there's none: the marker never clusters, isn't in the group, or waits to be clustered. * @param {M | MarkerCluster} layer * @returns {MarkerCluster | null} */ getParent(layer: M | MarkerCluster): MarkerCluster | null; /** * Takes the markers and clusters collected by a bulk function out of the top level at once, since there can be * many of them (with a high map minZoom, every marker that never clusters is there, and every cluster at minZoom). * @param {Set | MarkerCluster>} removed */ _removeFromTop(removed: Set | MarkerCluster>): void; /** * Removes the object from the array, returning true if it was there. * @template T * @param {T[]} anArray * @param {T} obj */ _arraySplice(anArray: T[], obj: T): boolean; /** * Removes a marker from all _gridUnclustered zoom levels, starting at the supplied zoom. * @param {ClusterChild} marker * @param {number} z Bottom start zoom level (included). */ _removeFromGridUnclustered(marker: ClusterChild, z: number): void; /** @param {ClusterChild} layer */ _unbindChild(layer: ClusterChild): void; /** @param {LeafletEvent & {originalEvent?: Event}} e */ _childMarkerMoved(e: LeafletEvent & { originalEvent?: Event; }): void; /** * The group keeps the projected point each marker was clustered at, so the old latlng isn't needed. * @param {ClusterChild} layer */ _moveChild(layer: ClusterChild): void; /** * Takes the marker out of its clusters until dragend, so that it stays shown where it's dragged: zooming would * otherwise cluster it, and unspiderfying would put it back at its real latlng. * @param {ClusterChild} marker */ _startDrag(marker: ClusterChild): void; /** @param {LeafletEvent} e */ _childMarkerDragEnd(e: LeafletEvent): void; /** * Removes a marker from everything. Works off the map too. * @param {ClusterChild} marker * @param {boolean} removeFromDistanceGrid * @param {Set | MarkerCluster>} [removedFromTop] Given by bulk functions, which update the map * themselves and filter the markers and clusters collected in it out of the top level at once. * @param {MarkerCluster} [cluster] The marker's cluster, if the caller has it already. */ _removeLayer(marker: ClusterChild, removeFromDistanceGrid: boolean, removedFromTop?: Set | MarkerCluster>, cluster?: MarkerCluster): void; /** * Events from clusters are fired as clusterclick, clustermouseover, etc. * @param {string} type * @param {{[key: string]: any}} [data] * @param {boolean} [propagate] */ fire(type: string, data?: { [key: string]: any; }, propagate?: boolean): this; /** * @param {string} type * @param {...any} args * @returns {boolean} */ listens(type: string, ...args: any[]): boolean; /** * The default iconCreateFunction. * @param {MarkerCluster} cluster */ _defaultIconCreateFunction(cluster: MarkerCluster): DivIcon; _bindEvents(): void; /** @param {LeafletEvent & {[key: string]: any}} e clusterclick, or clusterkeypress on 1.x */ _zoomOrSpiderfy(e: LeafletEvent & { [key: string]: any; }): void; /** * Whether all the cluster's markers stay in one cluster down to the bottom zoom. * @param {MarkerCluster} cluster */ _neverSplits(cluster: MarkerCluster): boolean; /** @param {MarkerCluster} cluster */ _spiderfiesOnClick(cluster: MarkerCluster): boolean; /** @param {{layer: MarkerCluster}} e clustermouseover, or the cluster's icon getting focus */ _showCoverage(e: { layer: MarkerCluster; }): void; _hideCoverage(): void; _unbindEvents(): void; _stopAnimations(): void; _zoomEnd(): void; _moveEnd(): void; /** @param {number} zoom */ _updateShownLayers(zoom: number): void; /** * Whether a layer has an open popup, its own or the group's, and so stays on the map out of view; removing it * would close the popup. Called during autopan too, which runs before popupopen fires. * @param {ClusterChild | MarkerCluster} layer */ _keepForPopup(layer: ClusterChild | MarkerCluster): boolean; /** @param {PopupEvent} e */ _popupClose(e: PopupEvent): void; /** * Removes a layer kept for its popup if it's still out of view, where the recursive removals don't reach it. * @param {ClusterChild | MarkerCluster} layer */ _removeKeptForPopup(layer: ClusterChild | MarkerCluster): void; /** The lowest and highest zoom with clusters for the map's zoom range. */ _zoomRange(): number[]; _zoomRangeChanged(): boolean; _zoomLevelsChange(): void; _generateInitialClusters(): void; /** * @param {ClusterChild} layer * @param {Set | MarkerCluster>} [removedFromTop] Given by bulk functions, see _removeLayer. * @returns {MarkerCluster} The cluster the layer went into. */ _addLayer(layer: ClusterChild, removedFromTop?: Set | MarkerCluster>): MarkerCluster; /** * Refreshes the icon of all "dirty" visible clusters. * Non-visible "dirty" clusters will be updated when they are added to the map. */ _refreshClustersIcons(): void; /** * Enqueue code to fire after the marker expand/contract has happened. * @param {() => void} fn */ _enqueue(fn: () => void): void; _processQueue(): void; _mergeSplitClusters(): void; _getExpandedVisibleBounds(): LatLngBounds; /** * Expands the latitude to Infinity (or -Infinity) if the input bounds reach the map projection maximum defined latitude * (in the case of Web/Spherical Mercator, it is 85.0511287798 / see https://en.wikipedia.org/wiki/Web_Mercator#Formulas). * Otherwise, the removeOutsideVisibleBounds option will remove markers beyond that limit, whereas the same markers without * this option (or outside MCG) will have their position floored (ceiled) by the projection and rendered at that limit, * making the user think that MCG "eats" them and never displays them again. * @param {LatLngBounds} bounds * @returns {LatLngBounds} */ _checkBoundsMaxLat(bounds: LatLngBounds): LatLngBounds; /** * Shared animation code. * @param {ClusterChild} layer * @param {ClusterChild | MarkerCluster} newCluster The layer, or the cluster it's shown in. */ _animationAddLayerNonAnimated(layer: ClusterChild, newCluster: ClusterChild | MarkerCluster): void; /** * Implements the singleMarkerMode option. * @param {ClusterChild} layer Marker to re-style using the Clusters iconCreateFunction. * @returns {Icon} The newly created icon. */ _overrideMarkerIcon(layer: ClusterChild): Icon; /** * Updates the icons of the clusters of the given markers, e.g. after changing data that `iconCreateFunction` * uses. In `singleMarkerMode`, also updates the icons of the markers. * @param {MarkerClusterGroup | LayerGroup | MarkerCluster | M | M[] | {[id: string]: M}} [layers] The * markers, or a group or cluster of them; all markers in this group if not given. * @returns {this} */ refreshClusters(layers?: MarkerClusterGroup | LayerGroup | MarkerCluster | M | M[] | { [id: string]: M; }): this; /** * Simply flags all parent clusters of the given markers as having a "dirty" icon. * @param {ClusterChild[] | {[id: string]: ClusterChild}} layers */ _flagParentsIconsNeedUpdate(layers: ClusterChild[] | { [id: string]: ClusterChild; }): void; /** * Re-draws the icon of the supplied markers. * To be used in singleMarkerMode only. * @param {ClusterChild[] | {[id: string]: ClusterChild}} layers */ _refreshSingleMarkerModeMarkers(layers: ClusterChild[] | { [id: string]: ClusterChild; }): void; /** Unspiderfies the spiderfied cluster, if any. */ unspiderfy(): void; _spiderfierOnAdd(): void; _spiderfierOnRemove(): void; /** * Escape closes the spiderfied markers like it closes a popup, after Leaflet's own handler, so that it closes an * open popup first; and like there, not from a control, e.g. a geocoder input. * @param {KeyboardEvent} e */ _onKeyDown(e: KeyboardEvent): void; _unspiderfyZoomStart(): void; _unspiderfyZoomOff(): void; _unspiderfyZoomAnim(): void; _unspiderfyZoom(): void; /** @param {boolean} [withZoom] */ _unspiderfy(withZoom?: boolean): void; _noanimationUnspiderfy(): void; /** * Unspiderfies if the cluster that a marker was added to is the spiderfied one or inside it. * @param {MarkerCluster | undefined} cluster */ _unspiderfyIfIn(cluster: MarkerCluster | undefined): void; /** * Takes the layer out of the spider if it's in one, unspiderfying the rest of its cluster. * @param {ClusterChild} layer */ _unspiderfyLayer(layer: ClusterChild): void; /** * @param {MarkerCluster} cluster * @param {number} previousZoomLevel * @param {number} newZoomLevel */ _animationZoomOutSingle(cluster: MarkerCluster, previousZoomLevel: number, newZoomLevel: number): void; _animationStart(): void; /** * @param {number} previousZoomLevel * @param {number} newZoomLevel */ _animationZoomIn(previousZoomLevel: number, newZoomLevel: number): void; /** * @param {number} previousZoomLevel * @param {number} newZoomLevel */ _animationZoomOut(previousZoomLevel: number, newZoomLevel: number): void; /** * @param {ClusterChild} layer * @param {ClusterChild | MarkerCluster} newCluster The layer, or the cluster it's shown in. */ _animationAddLayer(layer: ClusterChild, newCluster: ClusterChild | MarkerCluster): void; _animationEnd(): void; }