-
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
7
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
7 commits
Select commit
Hold shift + click to select a range
788fe5d
feat(mapbox): Add widget support to MapboxOverlay via IControl adapter
chrisgervang 81541ab
test(mapbox): Add tests for widget support in MapboxOverlay
chrisgervang 4942acc
test(mapbox): Use isolated WebGL device for overlaid mode tests
chrisgervang 0b1b757
fix(mapbox): Preserve widget container on setProps to prevent orphane…
chrisgervang 282b39d
docs(mapbox): Mark DeckWidgetControl as internal
chrisgervang c4f097d
fix(mapbox): Handle null widgets defensively in _processWidgets
chrisgervang 287b467
fix(mapbox): Update widget reference when reusing DeckWidgetControl
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
| 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; | ||
| private _container: HTMLDivElement | null = null; | ||
|
|
||
| constructor(widget: Widget) { | ||
| 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 { | ||
| 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): 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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Placement change undetected for mutated widget objects
Low Severity
The placement comparison
existingControl.widget.placement === widget.placementfails to detect placement changes when the same widget object is passed with a mutatedplacementproperty. AftersetWidget(widget)is called in a previous iteration,existingControl.widgetbecomes the same reference as the currentwidget. When both sides of the comparison reference the same object, the comparison is trivially true regardless of whether placement was actually changed. The control remains in its original map position even though the widget's placement changed.