@opendatasoft/visualizations
Version:
Opendatasoft's components to easily build dashboards and visualizations.
132 lines (131 loc) • 5.26 kB
TypeScript
import type { BBox } from 'geojson';
import type { MapOptions, StyleSpecification } from 'maplibre-gl';
import type { PopupConfigurationByLayers, CenterZoomOptions, Images, OnFeatureClick } from './types';
export default class MapPOI {
/** The Map object representing the Map instance. */
private map;
/** Map resize observer */
private mapResizeObserver;
/** Flag indicating whether the map is ready. */
private isReady;
/** The base style of the map */
private baseStyle;
/** A navigation control for the map. */
private navigationControl;
/** A fullscreen control for the map. */
private fullscreenControl;
/** A popup for displaying information on the map. */
private popup;
/** An object to store popup configurations for each layers */
private popupConfigurationByLayers;
/** Value to represent the active display of the popup */
private activePopupDisplay;
/** An active GeoJSONFeature. Its information are displayed within the popup. */
private activeFeature;
/** All available GeoJSONFeatures on click event */
private availableFeaturesOnClick;
/** An array of functions to be executed when the map is ready. */
private queuedFunctions;
/** Additional custom click handler */
private onFeatureClick;
/** To queue functions that depend on map readiness. Will be executed when the card is ready. */
private queue;
/** Execute queued functions */
private enqueue;
/** Make active feature bigger and sort it on top of other features in the layer */
private highlightFeature;
/** Reset active feature highlight state */
private unhighlightFeature;
/** Initialize a resize observer to always fit the map to its container */
private initializeMapResizer;
/**
* Event handler for mousemove event.
* Show a pointer cursor if hovering a feature with a popup configuration on an onClick callback
*/
private onMouseMove;
private bindedOnMouseMove;
/**
* How cursor should react on drag and when mouse move over the map
*/
private initializeCursorBehavior;
/**
* Event handler for click events on the map.
* Currently, is only used to handle popup display.
* @param {MapLayerMouseEvent} event
*/
private onMapClick;
private bindedOnMapClick;
/** Update popup display between tooltip, sidebar and modal modes */
private updatePopupDisplay;
private navigateToFeature;
private renderFeaturesNavigationControls;
/**
* Update popup content.
* - First add a loading state,
* - Then replace it with content
*
* Navigation controls element is always displayed
*/
private updatePopupContent;
/** Handler for popup display changes */
private onPopupDisplayUpdate;
private handleCustomFeatureClick;
/**
* Is triggered when a click has been made on the map.
* Is responsible for opening and closing the popup.
*
* Opening the popup happens when:
* - A feature is clicked for which a popup configuration is available (popup configuration are set by layer)
*
* Closing the popup happens when:
* - No features are near the click
* - The clicked feature is the current feature (activeFeature) displayed in the popup
* - The button icon button in the popup is clicked
*
* @param map The map instance
* @param point The pixel coordinates of the cursor click, relative to the map
*/
private handlePopupAfterMapClick;
/**
* Check if all specified controls exist on the map.
*/
private hasAllControls;
/**
* Add navigation and fullscreen controls to the map.
*/
private addControls;
private removeControls;
initialize(style: MapOptions['style'], container: HTMLElement, options: Omit<MapOptions, 'style' | 'container'>): void;
destroy(): void;
/**
* Update the sources and layers of the map.
* Layers of the map base style are untouched.
*/
setSourcesAndLayers(sources: StyleSpecification['sources'], layers: StyleSpecification['layers']): void;
setMinZoom(minZoom?: number): void;
setMaxZoom(maxZoom?: number): void;
setBbox(bbox?: BBox): void;
updateClickHandler(handler?: OnFeatureClick): void;
/**
* Changes any combination of center and zoom without an animated transition.
* The map will retain its current values for any details not specified in options
*/
jumpTo(options: CenterZoomOptions): void;
/**
* Store the new popup configuration for each layer.
* When this configuration is updated, we need to update the popup content and display
* to reflect the new configuration.
* @param config Popups configuration
*/
setPopupConfigurationByLayers(config: PopupConfigurationByLayers): void;
/**
* Load images into the map.
* Remove automatically any images previously loaded that are no longer defined in the images object.
*/
loadImages(images?: Images): void;
toggleInteractivity(interaction: 'enable' | 'disable', { onDisable, onEnable }: {
onDisable?: () => void;
onEnable?: () => void;
}): void;
constructor();
}