| 42 | * Renders deck.gl layers over the base map and automatically synchronizes with the map's camera |
| 43 | */ |
| 44 | export default class MapboxOverlay implements IControl { |
| 45 | private _props: MapboxOverlayProps; |
| 46 | private _deck?: Deck<any>; |
| 47 | private _map?: Map; |
| 48 | private _container?: HTMLDivElement; |
| 49 | private _interleaved: boolean; |
| 50 | private _lastMouseDownPoint?: {x: number; y: number; clientX: number; clientY: number}; |
| 51 | |
| 52 | constructor(props: MapboxOverlayProps) { |
| 53 | const {interleaved = false} = props; |
| 54 | this._interleaved = interleaved; |
| 55 | this._props = this.filterProps(props); |
| 56 | } |
| 57 | |
| 58 | /** Filter out props to pass to Deck **/ |
| 59 | filterProps(props: MapboxOverlayProps): MapboxOverlayProps { |
| 60 | const {interleaved = false, useDevicePixels, ...deckProps} = props; |
| 61 | if (!interleaved && useDevicePixels !== undefined) { |
| 62 | // useDevicePixels cannot be used in interleaved mode |
| 63 | (deckProps as MapboxOverlayProps).useDevicePixels = useDevicePixels; |
| 64 | } |
| 65 | return deckProps; |
| 66 | } |
| 67 | |
| 68 | /** Update (partial) props of the underlying Deck instance. */ |
| 69 | setProps(props: MapboxOverlayProps): void { |
| 70 | if (this._interleaved && props.layers) { |
| 71 | this._resolveLayers(this._map, this._deck, this._props.layers, props.layers); |
| 72 | } |
| 73 | |
| 74 | Object.assign(this._props, this.filterProps(props)); |
| 75 | |
| 76 | if (this._deck && this._map) { |
| 77 | this._deck.setProps({ |
| 78 | ...this._props, |
| 79 | views: this._getViews(this._map), |
| 80 | parameters: { |
| 81 | ...getDefaultParameters(this._map, this._interleaved), |
| 82 | ...this._props.parameters |
| 83 | } |
| 84 | }); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | // The local Map type is for internal typecheck only. It does not necesarily satisefy mapbox/maplibre types at runtime. |
| 89 | // Do not restrict the argument type here to avoid type conflict. |
| 90 | /** Called when the control is added to a map */ |
| 91 | onAdd(map: unknown): HTMLDivElement { |
| 92 | this._map = map as Map; |
| 93 | return this._interleaved ? this._onAddInterleaved(map as Map) : this._onAddOverlaid(map as Map); |
| 94 | } |
| 95 | |
| 96 | private _onAddOverlaid(map: Map): HTMLDivElement { |
| 97 | /* global document */ |
| 98 | const container = document.createElement('div'); |
| 99 | Object.assign(container.style, { |
| 100 | position: 'absolute', |
| 101 | left: 0, |
nothing calls this directly
no test coverage detected
searching dependent graphs…