@maplibre/maplibre-gl-inspect
Version:
Maplibre GL JS plugin for inspecting vector data
167 lines (162 loc) • 4.21 kB
TypeScript
import { MapGeoJSONFeature, IControl, StyleSpecification, LayerSpecification, Popup, QueryRenderedFeaturesOptions, Map, MapSourceDataEvent, MapMouseEvent } from 'maplibre-gl';
/**
* The options for the InspectButton
*/
type InspectButtonOptions = {
show: boolean;
onToggle: () => void;
};
/**
* A button to toggle the inspect mode
*/
declare class InspectButton {
_btn: HTMLButtonElement;
elem: HTMLDivElement;
constructor(options: InspectButtonOptions);
private createButton;
private createContainer;
setInspectIcon(): void;
setMapIcon(): void;
}
/**
* A GeoJSON feature with a source layer
*/
type GeoJSONFeatureWithSourceLayer = MapGeoJSONFeature & {
layer: {
'source-layer'?: string;
};
};
/**
* This is the main type for the available options for MapLibre Inspect
*/
type MaplibreInspectOptions = {
/**
* Show the inspect map
* @default false
*/
showInspectMap?: boolean;
/**
* Show the inspect button
* @default true
*/
showInspectButton?: boolean;
/**
* Show the map popup
* @default false
*/
showMapPopup?: boolean;
/**
* Show the map popup on hover
* @default true
*/
showMapPopupOnHover?: boolean;
/**
* Show the inspect map popup
* @default true
*/
showInspectMapPopup?: boolean;
/**
* Show the inspect map popup on hover
* @default true
*/
showInspectMapPopupOnHover?: boolean;
/**
* Block hover popup on click
* @default false
*/
blockHoverPopupOnClick?: boolean;
/**
* Background color for the inspect map
* @default '#fff'
*/
backgroundColor?: string;
assignLayerColor?: (layerId: string, alpha: number) => string;
buildInspectStyle?: (originalMapStyle: StyleSpecification, coloredLayers: LayerSpecification[], opts: {
backgroundColor?: string;
}) => StyleSpecification;
renderPopup?: (features: GeoJSONFeatureWithSourceLayer[]) => string | HTMLElement;
/**
* Maplibre GL Popup
*/
popup?: Popup;
/**
* Select threshold
* @default 5
*/
selectThreshold?: number;
/**
* Use inspect style
* @default true
*/
useInspectStyle?: boolean;
/**
* Query parameters for querying rendered features
*/
queryParameters?: QueryRenderedFeaturesOptions;
/**
* Sources to be used for inspecting, setting this will disable the automatic source detection.
* This is a dictionary containing the source IDs and their vector layer IDs
*/
sources?: {
[key: string]: string[];
};
/**
* Callback for toggling the inspect map
*/
toggleCallback?: (showInspectMap: boolean) => void;
};
/**
* Maplibre Inspect Control
*/
declare class MaplibreInspect implements IControl {
options: Required<MaplibreInspectOptions>;
sources: {
[key: string]: string[];
};
assignLayerColor: (layerId: string, alpha: number) => string;
/**
* @hidden
*/
_popup: Popup;
/**
* @hidden
*/
_popupBlocked: boolean;
/**
* @hidden
*/
_showInspectMap: boolean;
/**
* @hidden
*/
_originalStyle: StyleSpecification | undefined;
/**
* @hidden
*/
_toggle: InspectButton;
/**
* @hidden
*/
_map: Map | undefined;
constructor(options: MaplibreInspectOptions);
toggleInspector(): void;
_inspectStyle(): StyleSpecification;
render(): void;
private _setSourcesFromMap;
_onSourceChange: (e: MapSourceDataEvent) => Promise<void>;
/**
* This will set the original style of the map
* It will also update the sources assuming the map has already been loaded
* @param style - The original style
*/
setOriginalStyle(style: StyleSpecification): void;
_onStyleChange: () => void;
_onRightClick: () => void;
_onMousemove: (e: MapMouseEvent) => void;
/** @inheritdoc */
onAdd(map: Map): HTMLDivElement;
/** @inheritdoc */
onRemove(): void;
}
export { MaplibreInspect as default };
export type { GeoJSONFeatureWithSourceLayer, MaplibreInspectOptions };