Skip to content

Commit

Permalink
callbacks - changes
Browse files Browse the repository at this point in the history
Signed-off-by: Ihor Dykhta <[email protected]>
  • Loading branch information
ilyabo authored and igorDykhta committed Sep 22, 2023
1 parent 9cce8ae commit bdfd2e0
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions src/components/src/map-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ export interface MapContainerProps {

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

Expand Down Expand Up @@ -760,13 +760,21 @@ export default function MapContainerFactory(
? deckGlProps?.views()
: new MapView({legacyMeterSizes: true});

const allDeckGlProps = {
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 @@ -786,9 +794,7 @@ export default function MapContainerFactory(
deckRenderCallbacks.onDeckLoad();
}
}}
{...(typeof deckRenderCallbacks?.onDeckRender === 'function'
? deckRenderCallbacks.onDeckRender(allDeckGlProps)
: allDeckGlProps)}
{...allDeckGlProps}
controller={{doubleClickZoom: !isEditorDrawingMode}}
viewState={mapState}
onBeforeRender={this._onBeforeRender}
Expand Down Expand Up @@ -919,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 @@ -962,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 @@ -1010,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 bdfd2e0

Please sign in to comment.