-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat(mapbox): Add widget support to MapboxOverlay via IControl adapter #9963
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
Open
chrisgervang
wants to merge
9
commits into
master
Choose a base branch
from
chr/mapbox-widget-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c3668c5
feat(mapbox): Add widget support to MapboxOverlay via IControl adapter
chrisgervang a2d22a1
Merge remote-tracking branch 'origin/master' into chr/mapbox-widget-s…
chrisgervang d9580ac
fix(mapbox): clean up widget controls safely
chrisgervang e3b8713
fix(mapbox): accept generic widget props
chrisgervang 65e3783
Merge remote-tracking branch 'origin/master' into chr/mapbox-widget-s…
chrisgervang efb847d
Merge branch 'master' into chr/mapbox-widget-support
chrisgervang 935eb69
Merge remote-tracking branch 'origin/master' into chr/mapbox-widget-s…
chrisgervang 568a974
Merge remote-tracking branch 'origin/chr/mapbox-widget-support' into …
chrisgervang 5474ab7
Merge remote-tracking branch 'origin/master' into chr/mapbox-widget-s…
chrisgervang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| // deck.gl | ||
| // SPDX-License-Identifier: MIT | ||
| // Copyright (c) vis.gl contributors | ||
|
|
||
| import type {Widget} from '@deck.gl/core'; | ||
| import type {IControl, ControlPosition, Map} from './types'; | ||
|
|
||
| /** | ||
| * Wraps a deck.gl Widget as a Mapbox/MapLibre IControl. | ||
| * | ||
| * This enables deck widgets to be positioned alongside native map controls | ||
| * in the same DOM container, preventing overlap issues. | ||
| * | ||
| * @internal Used by MapboxOverlay for widgets with `viewId: 'mapbox'`. | ||
| */ | ||
| export class DeckWidgetControl implements IControl { | ||
| private _widget: Widget<any>; | ||
| private _container: HTMLDivElement | null = null; | ||
|
|
||
| constructor(widget: Widget<any>) { | ||
| this._widget = widget; | ||
| } | ||
|
|
||
| /** | ||
| * Called when the control is added to the map. | ||
| * Creates a container element that will be positioned by Mapbox/MapLibre, | ||
| * and sets the widget's _container prop so WidgetManager appends the widget here. | ||
| */ | ||
| onAdd(map: Map): HTMLElement { | ||
| this._container = document.createElement('div'); | ||
| this._container.className = 'maplibregl-ctrl mapboxgl-ctrl deck-widget-ctrl'; | ||
|
|
||
| // Set _container so WidgetManager appends the widget's rootElement here | ||
| // instead of in its own overlay container | ||
| this._widget.props._container = this._container; | ||
|
|
||
| return this._container; | ||
| } | ||
|
|
||
| /** | ||
| * Called when the control is removed from the map. | ||
| */ | ||
| onRemove(): void { | ||
| // Clear the _container reference so widget doesn't try to append there | ||
| if (this._widget.props._container === this._container) { | ||
| this._widget.props._container = null; | ||
| } | ||
| this._container?.remove(); | ||
| this._container = null; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the default position for this control. | ||
| * Uses the widget's placement, which conveniently matches Mapbox control positions. | ||
| * Note: 'fill' placement is not supported by Mapbox controls, defaults to 'top-left'. | ||
| */ | ||
| getDefaultPosition(): ControlPosition { | ||
| const placement = this._widget.placement; | ||
| // 'fill' is not a valid Mapbox control position | ||
| if (!placement || placement === 'fill') { | ||
| return 'top-left'; | ||
| } | ||
| return placement; | ||
| } | ||
|
|
||
| /** Returns the wrapped widget */ | ||
| get widget(): Widget<any> { | ||
| return this._widget; | ||
| } | ||
|
|
||
| /** | ||
| * Updates the wrapped widget reference. | ||
| * Used when reusing this control for a new widget instance with the same id. | ||
| */ | ||
| setWidget(widget: Widget<any>): void { | ||
| this._widget = widget; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.