Skip to content

Commit

Permalink
[feat] deck.gl render callbacks (#2330)
Browse files Browse the repository at this point in the history
  • Loading branch information
igorDykhta authored Sep 23, 2023
1 parent 6596187 commit 0b8ae8b
Showing 1 changed file with 41 additions and 6 deletions.
47 changes: 41 additions & 6 deletions src/components/src/map-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@ export interface MapContainerProps {
generateDeckGLLayers?: typeof computeDeckLayers;

onMouseMove?: (event: React.MouseEvent & {lngLat?: [number, number]}) => void;

deckRenderCallbacks?: {
onDeckLoad?: () => void;
onDeckRender?: (deckProps: Record<string, unknown>) => Record<string, unknown> | null;
};
}

export default function MapContainerFactory(
Expand Down Expand Up @@ -671,6 +676,7 @@ export default function MapContainerFactory(
deckGlProps,
index,
mapControls,
deckRenderCallbacks,
theme,
generateDeckGLLayers,
onMouseMove
Expand Down Expand Up @@ -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 (
<div
onMouseMove={
Expand All @@ -768,12 +789,14 @@ export default function MapContainerFactory(
>
<DeckGL
id="default-deckgl-overlay"
{...deckGlProps}
views={views}
layers={deckGlLayers}
onLoad={() => {
if (typeof deckRenderCallbacks?.onDeckLoad === 'function') {
deckRenderCallbacks.onDeckLoad();
}
}}
{...allDeckGlProps}
controller={{doubleClickZoom: !isEditorDrawingMode}}
viewState={mapState}
pickingRadius={DEFAULT_PICKING_RADIUS}
onBeforeRender={this._onBeforeRender}
onViewStateChange={this._onViewportChange}
{...extraDeckParams}
Expand Down Expand Up @@ -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 (
<>
<MapControl
Expand Down Expand Up @@ -945,7 +974,7 @@ export default function MapContainerFactory(
{...bottomMapContainerProps}
ref={this._setMapboxMap}
>
{this._renderDeckOverlay(layersForDeck, {primaryMap: true})}
{deckOverlay}
{this._renderMapboxOverlays()}
<Editor
index={index || 0}
Expand Down Expand Up @@ -993,14 +1022,20 @@ export default function MapContainerFactory(

render() {
const {visState} = this.props;
const mapContent = this._renderMap();
if (!mapContent) {
// mapContent can be null if onDeckRender returns null
// in this case we don't want to render the map
return null;
}
return (
<StyledMap
ref={this._ref}
style={this.styleSelector(this.props)}
onContextMenu={event => event.preventDefault()}
mixBlendMode={visState.overlayBlending}
>
{this._renderMap()}
{mapContent}
</StyledMap>
);
}
Expand Down

0 comments on commit 0b8ae8b

Please sign in to comment.