From 0b8ae8bc2805eb5671e3074cdccb8c749479454b Mon Sep 17 00:00:00 2001 From: Igor D Date: Sat, 23 Sep 2023 04:14:12 +0300 Subject: [PATCH] [feat] deck.gl render callbacks (#2330) --- src/components/src/map-container.tsx | 47 ++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/src/components/src/map-container.tsx b/src/components/src/map-container.tsx index 00c862e114..87b1d24138 100644 --- a/src/components/src/map-container.tsx +++ b/src/components/src/map-container.tsx @@ -310,6 +310,11 @@ export interface MapContainerProps { generateDeckGLLayers?: typeof computeDeckLayers; onMouseMove?: (event: React.MouseEvent & {lngLat?: [number, number]}) => void; + + deckRenderCallbacks?: { + onDeckLoad?: () => void; + onDeckRender?: (deckProps: Record) => Record | null; + }; } export default function MapContainerFactory( @@ -671,6 +676,7 @@ export default function MapContainerFactory( deckGlProps, index, mapControls, + deckRenderCallbacks, theme, generateDeckGLLayers, onMouseMove @@ -754,6 +760,21 @@ export default function MapContainerFactory( ? deckGlProps?.views() : new MapView({legacyMeterSizes: true}); + let allDeckGlProps = { + ...deckGlProps, + pickingRadius: DEFAULT_PICKING_RADIUS, + views, + layers: deckGlLayers + }; + + if (typeof deckRenderCallbacks?.onDeckRender === 'function') { + allDeckGlProps = deckRenderCallbacks.onDeckRender(allDeckGlProps); + if (!allDeckGlProps) { + // if onDeckRender returns null, do not render deck.gl + return null; + } + } + return (
{ + if (typeof deckRenderCallbacks?.onDeckLoad === 'function') { + deckRenderCallbacks.onDeckLoad(); + } + }} + {...allDeckGlProps} controller={{doubleClickZoom: !isEditorDrawingMode}} viewState={mapState} - pickingRadius={DEFAULT_PICKING_RADIUS} onBeforeRender={this._onBeforeRender} onViewStateChange={this._onViewportChange} {...extraDeckParams} @@ -902,6 +925,12 @@ export default function MapContainerFactory( const hasGeocoderLayer = Boolean(layers.find(l => l.id === GEOCODER_LAYER_ID)); const isSplit = Boolean(mapState.isSplit); + const deckOverlay = this._renderDeckOverlay(layersForDeck, {primaryMap: true}); + if (!deckOverlay) { + // deckOverlay can be null if onDeckRender returns null + // in this case we don't want to render the map + return null; + } return ( <> - {this._renderDeckOverlay(layersForDeck, {primaryMap: true})} + {deckOverlay} {this._renderMapboxOverlays()} event.preventDefault()} mixBlendMode={visState.overlayBlending} > - {this._renderMap()} + {mapContent} ); }