@@ -11,10 +11,11 @@ import {
1111 getDefaultParameters ,
1212 getProjection
1313} from './deck-utils' ;
14+ import { DeckWidgetControl } from './deck-widget-control' ;
1415
1516import type { Map , IControl , MapMouseEvent , ControlPosition } from './types' ;
1617import type { MjolnirGestureEvent , MjolnirPointerEvent } from 'mjolnir.js' ;
17- import type { DeckProps , LayersList } from '@deck.gl/core' ;
18+ import type { DeckProps , LayersList , Widget } from '@deck.gl/core' ;
1819
1920import { resolveLayers } from './resolve-layers' ;
2021import { resolveLayerGroups } from './resolve-layer-groups' ;
@@ -55,6 +56,8 @@ export default class MapboxOverlay implements IControl {
5556 private _interleaved : boolean ;
5657 private _renderLayersInGroups : boolean ;
5758 private _lastMouseDownPoint ?: { x : number ; y : number ; clientX : number ; clientY : number } ;
59+ /** IControl wrappers for widgets with viewId: 'mapbox' */
60+ private _widgetControls : DeckWidgetControl [ ] = [ ] ;
5861
5962 constructor ( props : MapboxOverlayProps ) {
6063 const { interleaved = false } = props ;
@@ -79,6 +82,12 @@ export default class MapboxOverlay implements IControl {
7982 this . _resolveLayers ( this . _map , this . _deck , this . _props . layers , props . layers ) ;
8083 }
8184
85+ // Process widgets with viewId: 'mapbox' before updating props
86+ // This must happen before deck.setProps so _container is set
87+ if ( props . widgets !== undefined ) {
88+ this . _processWidgets ( props . widgets ) ;
89+ }
90+
8291 Object . assign ( this . _props , this . filterProps ( props ) ) ;
8392
8493 if ( this . _deck && this . _map ) {
@@ -112,6 +121,10 @@ export default class MapboxOverlay implements IControl {
112121 } ) ;
113122 this . _container = container ;
114123
124+ // Process widgets with viewId: 'mapbox' BEFORE creating Deck
125+ // so _container is set when WidgetManager initializes
126+ this . _processWidgets ( this . _props . widgets ) ;
127+
115128 this . _deck = new Deck < any > ( {
116129 ...this . _props ,
117130 parent : container ,
@@ -143,6 +156,11 @@ export default class MapboxOverlay implements IControl {
143156 'Incompatible basemap library. See: https://deck.gl/docs/api-reference/mapbox/overview#compatibility'
144157 ) ( ) ;
145158 }
159+
160+ // Process widgets with viewId: 'mapbox' BEFORE creating Deck
161+ // so _container is set when WidgetManager initializes
162+ this . _processWidgets ( this . _props . widgets ) ;
163+
146164 this . _deck = getDeckInstance ( {
147165 map,
148166 deck : new Deck ( {
@@ -171,11 +189,46 @@ export default class MapboxOverlay implements IControl {
171189 }
172190 }
173191
192+ /**
193+ * Process widgets and wrap those with viewId: 'mapbox' as IControls.
194+ * This enables deck widgets to be positioned in Mapbox's control container
195+ * alongside native map controls, preventing overlap.
196+ */
197+ private _processWidgets ( widgets : Widget [ ] | undefined ) : void {
198+ const map = this . _map ;
199+ if ( ! map ) return ;
200+
201+ // Remove old widget controls
202+ for ( const control of this . _widgetControls ) {
203+ map . removeControl ( control ) ;
204+ }
205+ this . _widgetControls = [ ] ;
206+
207+ if ( ! widgets ) return ;
208+
209+ // Wrap widgets with viewId: 'mapbox' as IControls
210+ for ( const widget of widgets ) {
211+ if ( widget . viewId === 'mapbox' ) {
212+ const control = new DeckWidgetControl ( widget ) ;
213+ // Add to map - this calls onAdd() synchronously, setting _container
214+ // Use control.getDefaultPosition() which handles 'fill' -> 'top-left' conversion
215+ map . addControl ( control , control . getDefaultPosition ( ) ) ;
216+ this . _widgetControls . push ( control ) ;
217+ }
218+ }
219+ }
220+
174221 /** Called when the control is removed from a map */
175222 onRemove ( ) : void {
176223 const map = this . _map ;
177224
178225 if ( map ) {
226+ // Remove widget controls
227+ for ( const control of this . _widgetControls ) {
228+ map . removeControl ( control ) ;
229+ }
230+ this . _widgetControls = [ ] ;
231+
179232 if ( this . _interleaved ) {
180233 this . _onRemoveInterleaved ( map ) ;
181234 } else {
0 commit comments