From 40585efeff6979cabff545377b22e667e68632bb Mon Sep 17 00:00:00 2001 From: Adam Krebs Date: Fri, 26 May 2023 09:25:30 -0400 Subject: [PATCH 1/3] Make canvas readonly instead of protected Change typescript annotation to make the Deck instance canvas readonly instead of protected. Right now there isn't a way to access the canvas instance [as seems to be suggested](https://github.com/visgl/deck.gl/issues/4436#issuecomment-610472868), as Typescript forbids it. It's possible to cast the deck instance as `any` before getting the canvas prop but this way provides a formalized accessor. --- modules/core/src/lib/deck.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/core/src/lib/deck.ts b/modules/core/src/lib/deck.ts index 2bff3100185..b09709dbf53 100644 --- a/modules/core/src/lib/deck.ts +++ b/modules/core/src/lib/deck.ts @@ -286,8 +286,8 @@ export default class Deck { readonly height: number = 0; // Allows attaching arbitrary data to the instance readonly userData: Record = {}; - - protected canvas: HTMLCanvasElement | null = null; + readonly canvas: HTMLCanvasElement | null = null; + protected viewManager: ViewManager | null = null; protected layerManager: LayerManager | null = null; protected effectManager: EffectManager | null = null; From 6248957557953acfc56bd11e5e8dc6e1ddf77cdf Mon Sep 17 00:00:00 2001 From: Adam Krebs Date: Thu, 1 Jun 2023 11:57:22 -0400 Subject: [PATCH 2/3] revert readonly, change to add a getCanvas helper --- modules/core/src/lib/deck.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/core/src/lib/deck.ts b/modules/core/src/lib/deck.ts index b09709dbf53..52d9f25def9 100644 --- a/modules/core/src/lib/deck.ts +++ b/modules/core/src/lib/deck.ts @@ -286,8 +286,8 @@ export default class Deck { readonly height: number = 0; // Allows attaching arbitrary data to the instance readonly userData: Record = {}; - readonly canvas: HTMLCanvasElement | null = null; - + + protected canvas: HTMLCanvasElement | null = null; protected viewManager: ViewManager | null = null; protected layerManager: LayerManager | null = null; protected effectManager: EffectManager | null = null; @@ -559,6 +559,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 */ From 4affbea497bea207c5e5227b138c5ea85e6d0d9f Mon Sep 17 00:00:00 2001 From: Chris Gervang Date: Fri, 15 Sep 2023 04:46:40 +0000 Subject: [PATCH 3/3] documentation and MapboxOverlay.getCanvas --- docs/api-reference/core/deck.md | 13 +++++++++++++ docs/api-reference/mapbox/mapbox-overlay.md | 3 +++ modules/mapbox/src/mapbox-overlay.ts | 5 +++++ 3 files changed, 21 insertions(+) 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/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); };