@@ -13,6 +13,8 @@ export type Point = { lat: number; lng: number };
13
13
export type Identifier = string ;
14
14
export type WithIdentifier < T extends Record < string , unknown > > = T & { '@id' : Identifier } ;
15
15
16
+ type ExtraData = Record < string , unknown > ;
17
+
16
18
export const IconTypes = {
17
19
Url : 'url' ,
18
20
Svg : 'svg' ,
@@ -46,6 +48,13 @@ export type MapDefinition<MapOptions, BridgeMapOptions> = {
46
48
* These options are specific to the Map Bridge, and can be defined through `ux:map:pre-connect` event.
47
49
*/
48
50
bridgeOptions ?: BridgeMapOptions ;
51
+ /**
52
+ * Extra data defined by the developer.
53
+ * They are not directly used by the Stimulus controller, but they can be used by the developer with event listeners:
54
+ * - `ux:map:pre-connect`
55
+ * - `ux:map:connect`
56
+ */
57
+ extra : ExtraData ;
49
58
} ;
50
59
51
60
export type MarkerDefinition < BridgeMarkerOptions , BridgeInfoWindowOptions > = WithIdentifier < {
@@ -69,7 +78,7 @@ export type MarkerDefinition<BridgeMarkerOptions, BridgeInfoWindowOptions> = Wit
69
78
* - `ux:map:marker:before-create`
70
79
* - `ux:map:marker:after-create`
71
80
*/
72
- extra : Record < string , unknown > ;
81
+ extra : ExtraData ;
73
82
} > ;
74
83
75
84
export type PolygonDefinition < BridgePolygonOptions , BridgeInfoWindowOptions > = WithIdentifier < {
@@ -92,7 +101,7 @@ export type PolygonDefinition<BridgePolygonOptions, BridgeInfoWindowOptions> = W
92
101
* - `ux:map:polygon:before-create`
93
102
* - `ux:map:polygon:after-create`
94
103
*/
95
- extra : Record < string , unknown > ;
104
+ extra : ExtraData ;
96
105
} > ;
97
106
98
107
export type PolylineDefinition < BridgePolylineOptions , BridgeInfoWindowOptions > = WithIdentifier < {
@@ -115,7 +124,7 @@ export type PolylineDefinition<BridgePolylineOptions, BridgeInfoWindowOptions> =
115
124
* - `ux:map:polyline:before-create`
116
125
* - `ux:map:polyline:after-create`
117
126
*/
118
- extra : Record < string , unknown > ;
127
+ extra : ExtraData ;
119
128
} > ;
120
129
121
130
export type CircleDefinition < BridgeCircleOptions , BridgeInfoWindowOptions > = WithIdentifier < {
@@ -139,7 +148,7 @@ export type CircleDefinition<BridgeCircleOptions, BridgeInfoWindowOptions> = Wit
139
148
* - `ux:map:circle:before-create`
140
149
* - `ux:map:circle:after-create`
141
150
*/
142
- extra : Record < string , unknown > ;
151
+ extra : ExtraData ;
143
152
} > ;
144
153
145
154
export type RectangleDefinition < BridgeRectangleOptions , BridgeInfoWindowOptions > = WithIdentifier < {
@@ -163,7 +172,7 @@ export type RectangleDefinition<BridgeRectangleOptions, BridgeInfoWindowOptions>
163
172
* - `ux:map:rectangle:before-create`
164
173
* - `ux:map:rectangle:after-create`
165
174
*/
166
- extra : Record < string , unknown > ;
175
+ extra : ExtraData ;
167
176
} > ;
168
177
169
178
export type InfoWindowDefinition < BridgeInfoWindowOptions > = {
@@ -188,7 +197,7 @@ export type InfoWindowDefinition<BridgeInfoWindowOptions> = {
188
197
* - `ux:map:info-window:before-create`
189
198
* - `ux:map:info-window:after-create`
190
199
*/
191
- extra : Record < string , unknown > ;
200
+ extra : ExtraData ;
192
201
} ;
193
202
194
203
export default abstract class <
@@ -219,6 +228,7 @@ export default abstract class<
219
228
circles : Array ,
220
229
rectangles : Array ,
221
230
options : Object ,
231
+ extra : Object ,
222
232
} ;
223
233
224
234
declare centerValue : Point | null ;
@@ -230,6 +240,7 @@ export default abstract class<
230
240
declare circlesValue : Array < CircleDefinition < BridgeCircleOptions , BridgeInfoWindowOptions > > ;
231
241
declare rectanglesValue : Array < RectangleDefinition < BridgeRectangleOptions , BridgeInfoWindowOptions > > ;
232
242
declare optionsValue : MapOptions ;
243
+ declare extraValue : Record < string , unknown > ;
233
244
234
245
declare hasCenterValue : boolean;
235
246
declare hasZoomValue : boolean;
@@ -240,6 +251,7 @@ export default abstract class<
240
251
declare hasCirclesValue : boolean;
241
252
declare hasRectanglesValue : boolean;
242
253
declare hasOptionsValue : boolean;
254
+ declare hasExtraValue : boolean;
243
255
244
256
protected map : BridgeMap ;
245
257
protected markers = new Map < Identifier , BridgeMarker > ( ) ;
@@ -259,10 +271,12 @@ export default abstract class<
259
271
protected abstract dispatchEvent ( name : string , payload : Record < string , unknown > ) : void ;
260
272
261
273
connect ( ) {
274
+ const extra = this . hasExtraValue ? this . extraValue : { } ;
262
275
const mapDefinition : MapDefinition < MapOptions , BridgeMapOptions > = {
263
276
center : this . hasCenterValue ? this . centerValue : null ,
264
277
zoom : this . hasZoomValue ? this . zoomValue : null ,
265
278
options : this . optionsValue ,
279
+ extra,
266
280
} ;
267
281
this . dispatchEvent ( 'pre-connect' , mapDefinition ) ;
268
282
@@ -291,6 +305,7 @@ export default abstract class<
291
305
circles : [ ...this . circles . values ( ) ] ,
292
306
rectangles : [ ...this . rectangles . values ( ) ] ,
293
307
infoWindows : this . infoWindows ,
308
+ extra,
294
309
} ) ;
295
310
296
311
this . isConnected = true ;
0 commit comments