({
map,
deck
}: {
map: Map & {__deck?: Deck<any> | null};
deck: Deck<any>;
})
| 23 | |
| 24 | // Create an interleaved deck instance. |
| 25 | export function getDeckInstance({ |
| 26 | map, |
| 27 | deck |
| 28 | }: { |
| 29 | map: Map & {__deck?: Deck<any> | null}; |
| 30 | deck: Deck<any>; |
| 31 | }): Deck<any> { |
| 32 | // Only create one deck instance per context |
| 33 | if (map.__deck) { |
| 34 | return map.__deck; |
| 35 | } |
| 36 | |
| 37 | // Only initialize certain props once per context |
| 38 | const customRender = deck.props._customRender; |
| 39 | const onLoad = deck.props.onLoad; |
| 40 | |
| 41 | const deckProps = { |
| 42 | ...deck.props, |
| 43 | _customRender: () => { |
| 44 | map.triggerRepaint(); |
| 45 | // customRender may be subscribed by DeckGL React component to update child props |
| 46 | // make sure it is still called |
| 47 | // Hack - do not pass a redraw reason here to prevent the React component from clearing the context |
| 48 | // Rerender will be triggered by MapboxLayerGroup's render() |
| 49 | customRender?.(''); |
| 50 | } |
| 51 | }; |
| 52 | deckProps.views ||= getDefaultView(map); |
| 53 | |
| 54 | // deck is using the WebGLContext created by mapbox. |
| 55 | // The map and its attached luma canvas context own canvas sizing and DPR state here. |
| 56 | // Deck only follows view state and avoids trying to size the shared canvas itself. |
| 57 | Object.assign(deckProps, { |
| 58 | width: null, |
| 59 | height: null, |
| 60 | touchAction: 'unset', |
| 61 | viewState: getViewState(map) |
| 62 | }); |
| 63 | if (deck.isInitialized) { |
| 64 | watchMapMove(deck, map); |
| 65 | } else { |
| 66 | deckProps.onLoad = () => { |
| 67 | onLoad?.(); |
| 68 | watchMapMove(deck, map); |
| 69 | }; |
| 70 | } |
| 71 | |
| 72 | deck.setProps(deckProps); |
| 73 | |
| 74 | map.__deck = deck; |
| 75 | map.on('render', () => { |
| 76 | if (deck.isInitialized) afterRender(deck, map); |
| 77 | }); |
| 78 | |
| 79 | return deck; |
| 80 | } |
| 81 | |
| 82 | function watchMapMove(deck: Deck, map: Map & {__deck?: Deck | null}) { |
no test coverage detected
searching dependent graphs…