diff --git a/docs/api-reference/core/deck.md b/docs/api-reference/core/deck.md index 4170fcc898b..2de5e7131a0 100644 --- a/docs/api-reference/core/deck.md +++ b/docs/api-reference/core/deck.md @@ -587,6 +587,19 @@ Frees all resources associated with this `Deck` instance. `deck.finalize()` +##### `getCanvas` {#getcanvas} + +Get the canvas element attached to this `Deck` instance. + +`deck.getCanvas()` + +Returns: + +* Either an `HTMLCanvasElement` or `null` if one isn't assigned. + +Notes: + +* See the [canvas](#canvas) prop for more information. ##### `setProps` {#setprops} diff --git a/docs/api-reference/mapbox/mapbox-overlay.md b/docs/api-reference/mapbox/mapbox-overlay.md index e0ad28b6cc4..186425de704 100644 --- a/docs/api-reference/mapbox/mapbox-overlay.md +++ b/docs/api-reference/mapbox/mapbox-overlay.md @@ -173,6 +173,9 @@ See [Deck.pickMultipleObjects](../core/deck.md#pickmultipleobjects). Removes the control and deletes all resources. +##### getCanvas + +See [Deck.getCanvas](../core/deck.md#getcanvas). When using `interleaved: true`, returns the base map's `canvas`. ## Remarks diff --git a/modules/core/src/lib/deck.ts b/modules/core/src/lib/deck.ts index e775bc9c3f3..784ae2e7f6e 100644 --- a/modules/core/src/lib/deck.ts +++ b/modules/core/src/lib/deck.ts @@ -587,6 +587,11 @@ export default class Deck { return this.viewManager.getViewports(rect); } + /** Get the current canvas element. */ + getCanvas(): HTMLCanvasElement | null { + return this.canvas; + } + /** Query the object rendered on top at a given point */ pickObject(opts: { /** x position in pixels */ diff --git a/modules/mapbox/src/mapbox-overlay.ts b/modules/mapbox/src/mapbox-overlay.ts index e1d7dc065a7..ea45037bec4 100644 --- a/modules/mapbox/src/mapbox-overlay.ts +++ b/modules/mapbox/src/mapbox-overlay.ts @@ -177,6 +177,11 @@ export default class MapboxOverlay implements IControl { } } + /** If interleaved: true, returns base map's canvas, otherwise forwards the Deck.getCanvas method. */ + getCanvas(): HTMLCanvasElement | null { + return this._interleaved ? this._map.getCanvas() : this._deck.getCanvas(); + } + private _handleStyleChange = () => { resolveLayers(this._map, this._deck, this._props.layers, this._props.layers); };