Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a getCanvas helper function on deck #7919

Merged
merged 5 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/api-reference/core/deck.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
3 changes: 3 additions & 0 deletions docs/api-reference/mapbox/mapbox-overlay.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions modules/core/src/lib/deck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
5 changes: 5 additions & 0 deletions modules/mapbox/src/mapbox-overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
Loading