leaflet
Version:
JavaScript library for mobile-friendly interactive maps
132 lines (131 loc) • 6.08 kB
TypeScript
import { LayerBase } from './LayerBase.js';
import { LatLng } from '../geo/LatLng.js';
import type { Defaults, DivOverlayDefaults, DivOverlayEventMap, DivOverlayOptions, LatLngExpression, LayerEventMap, LayerOptions, LeafletEvent, MapListeners, PointExpression } from '../types.js';
import type { LeafletMap } from '../map/Map.js';
import type { Layer, OverlayTriggerEvents } from './Layer.js';
export type OverlayContent = string | HTMLElement | ((layer: Layer) => string | HTMLElement);
/** @import {Defaults, DivOverlayDefaults, DivOverlayEventMap, DivOverlayOptions, LatLngExpression, LayerEventMap, LayerOptions, LeafletEvent, MapListeners, PointExpression, ZoomAnimEvent} from '../types.js' */
/** @import {LatLngBounds} from '../geo/LatLngBounds.js' */
/** @import {LeafletMap} from '../map/Map.js' */
/** @import {Layer, OverlayTriggerEvents} from './Layer.js' */
/**
* Content of a popup or tooltip: HTML, an element, or a function that gets the layer it's bound to and returns
* either.
* @typedef {string | HTMLElement | ((layer: Layer) => string | HTMLElement)} OverlayContent
*/
declare const defaultOptions: {
/** If true, the popup/tooltip will listen to the pointer events. */
interactive: boolean;
/**
* The offset of the overlay position.
* @type {PointExpression}
*/
offset: PointExpression;
/** A custom CSS class name to assign to the overlay. */
className: string;
/**
* Sets the HTML content of the overlay while initializing. If a function is passed the source layer will be
* passed to the function. The function should return a `String` or `HTMLElement` to be used in the overlay.
* String content is rendered as HTML; sanitize untrusted input or pass an `HTMLElement` with safe `textContent`
* instead.
* @type {OverlayContent}
*/
content: OverlayContent;
};
export type DivOverlayDefaultsValues = typeof defaultOptions;
export type DivOverlayEvents = {
/**
* Fired when the content of the overlay is updated
*/
contentupdate: LeafletEvent;
};
/** @typedef {typeof defaultOptions} DivOverlayDefaultsValues */
/**
* @category DivOverlay events
* @typedef {Object} DivOverlayEvents
* @property {LeafletEvent} contentupdate Fired when the content of the overlay is updated
*/
/**
* Base model for Popup and Tooltip. Inherit from it for custom overlays like plugins.
* @template {DivOverlayOptions} [O=DivOverlayOptions]
* @template {DivOverlayEventMap} [E=DivOverlayEventMap]
* @extends {LayerBase<O & DivOverlayDefaults, E>}
*/
export declare class DivOverlay<O extends DivOverlayOptions = DivOverlayOptions, E extends DivOverlayEventMap = DivOverlayEventMap> extends LayerBase<O & DivOverlayDefaults, E> {
_latlng: LatLng | undefined;
/** @type {Layer<LayerOptions, LayerEventMap & OverlayTriggerEvents> | undefined} */
_source: Layer<LayerOptions, LayerEventMap & OverlayTriggerEvents> | undefined;
/** @type {OverlayContent | undefined} */
_content: OverlayContent | undefined;
/** @type {ReturnType<typeof setTimeout> | undefined} */
_removeTimeout: ReturnType<typeof setTimeout> | undefined;
_containerBottom: number;
_containerLeft: number;
static initHooks: boolean;
/** @type {Defaults<DivOverlayOptions>} */
static defaultOptions: Defaults<DivOverlayOptions>;
constructor(options?: NoInfer<Partial<O>>, source?: Layer);
constructor(latlng: LatLng | [number, number, number?], options?: NoInfer<Partial<O>>);
/**
* Adds the overlay to the map. Alternative to `map.openPopup(popup)`/`.openTooltip(tooltip)`.
* @param {LeafletMap} map
*/
openOn(map: LeafletMap): this;
/**
* Closes the overlay. Alternative to `map.closePopup(popup)`/`.closeTooltip(tooltip)`
* and `layer.closePopup()`/`.closeTooltip()`.
*/
close(): this;
/**
* Opens or closes the overlay bound to layer depending on its current state. Argument may be omitted
* only for overlay bound to layer. Alternative to `layer.togglePopup()`/`.toggleTooltip()`.
* @param {Layer} [layer]
*/
toggle(layer?: Layer): this;
/** @param {LeafletMap} map */
onAdd(map: LeafletMap): void;
/** @param {LeafletMap} map */
onRemove(map: LeafletMap): void;
/** Returns the geographical point of the overlay. */
getLatLng(): LatLng | undefined;
/**
* Sets the geographical point where the overlay will open.
* @param {LatLngExpression} latlng
*/
setLatLng(latlng: LatLngExpression): this;
/** Returns the content of the overlay. */
getContent(): OverlayContent | undefined;
/**
* Sets the HTML content of the overlay. A `String` argument is rendered as HTML; if it may contain
* untrusted input, sanitize it (e.g. with DOMPurify) or pass an `HTMLElement` with safe `textContent`
* instead. If a function is passed the source layer will be passed to the function. The function
* should return a `String` or `HTMLElement` to be used in the overlay.
* @param {OverlayContent} content
*/
setContent(content: OverlayContent): this;
/**
* Returns the HTML container of the overlay.
* @returns {HTMLElement | undefined}
*/
getElement(): HTMLElement | undefined;
/**
* Updates the overlay content, layout and position. Useful for updating
* the overlay after something inside changed, e.g. image loaded.
*/
update(): void;
/** @returns {MapListeners} */
getEvents(): MapListeners;
/** Returns `true` when the overlay is visible on the map. */
isOpen(): boolean;
/** Brings this overlay in front of other overlays (in the same map pane). */
bringToFront(): this;
/** Brings this overlay to the back of other overlays (in the same map pane). */
bringToBack(): this;
/** @param {LatLngExpression} [latlng] */
_prepareOpen(latlng?: LatLngExpression): boolean;
_updateContent(): void;
_updatePosition(): void;
/** @returns {PointExpression} */
_getAnchor(): PointExpression;
}
export {};