@@ -13,6 +13,8 @@ export type Point = { lat: number; lng: number };
1313export type Identifier = string ;
1414export type WithIdentifier < T extends Record < string , unknown > > = T & { '@id' : Identifier } ;
1515
16+ type ExtraData = Record < string , unknown > ;
17+
1618export const IconTypes = {
1719 Url : 'url' ,
1820 Svg : 'svg' ,
@@ -46,6 +48,13 @@ export type MapDefinition<MapOptions, BridgeMapOptions> = {
4648 * These options are specific to the Map Bridge, and can be defined through `ux:map:pre-connect` event.
4749 */
4850 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 ;
4958} ;
5059
5160export type MarkerDefinition < BridgeMarkerOptions , BridgeInfoWindowOptions > = WithIdentifier < {
@@ -69,7 +78,7 @@ export type MarkerDefinition<BridgeMarkerOptions, BridgeInfoWindowOptions> = Wit
6978 * - `ux:map:marker:before-create`
7079 * - `ux:map:marker:after-create`
7180 */
72- extra : Record < string , unknown > ;
81+ extra : ExtraData ;
7382} > ;
7483
7584export type PolygonDefinition < BridgePolygonOptions , BridgeInfoWindowOptions > = WithIdentifier < {
@@ -92,7 +101,7 @@ export type PolygonDefinition<BridgePolygonOptions, BridgeInfoWindowOptions> = W
92101 * - `ux:map:polygon:before-create`
93102 * - `ux:map:polygon:after-create`
94103 */
95- extra : Record < string , unknown > ;
104+ extra : ExtraData ;
96105} > ;
97106
98107export type PolylineDefinition < BridgePolylineOptions , BridgeInfoWindowOptions > = WithIdentifier < {
@@ -115,7 +124,7 @@ export type PolylineDefinition<BridgePolylineOptions, BridgeInfoWindowOptions> =
115124 * - `ux:map:polyline:before-create`
116125 * - `ux:map:polyline:after-create`
117126 */
118- extra : Record < string , unknown > ;
127+ extra : ExtraData ;
119128} > ;
120129
121130export type CircleDefinition < BridgeCircleOptions , BridgeInfoWindowOptions > = WithIdentifier < {
@@ -139,7 +148,7 @@ export type CircleDefinition<BridgeCircleOptions, BridgeInfoWindowOptions> = Wit
139148 * - `ux:map:circle:before-create`
140149 * - `ux:map:circle:after-create`
141150 */
142- extra : Record < string , unknown > ;
151+ extra : ExtraData ;
143152} > ;
144153
145154export type RectangleDefinition < BridgeRectangleOptions , BridgeInfoWindowOptions > = WithIdentifier < {
@@ -163,7 +172,7 @@ export type RectangleDefinition<BridgeRectangleOptions, BridgeInfoWindowOptions>
163172 * - `ux:map:rectangle:before-create`
164173 * - `ux:map:rectangle:after-create`
165174 */
166- extra : Record < string , unknown > ;
175+ extra : ExtraData ;
167176} > ;
168177
169178export type InfoWindowDefinition < BridgeInfoWindowOptions > = {
@@ -188,7 +197,7 @@ export type InfoWindowDefinition<BridgeInfoWindowOptions> = {
188197 * - `ux:map:info-window:before-create`
189198 * - `ux:map:info-window:after-create`
190199 */
191- extra : Record < string , unknown > ;
200+ extra : ExtraData ;
192201} ;
193202
194203export default abstract class <
@@ -219,6 +228,7 @@ export default abstract class<
219228 circles : Array ,
220229 rectangles : Array ,
221230 options : Object ,
231+ extra : Object ,
222232 } ;
223233
224234 declare centerValue : Point | null ;
@@ -230,6 +240,7 @@ export default abstract class<
230240 declare circlesValue : Array < CircleDefinition < BridgeCircleOptions , BridgeInfoWindowOptions > > ;
231241 declare rectanglesValue : Array < RectangleDefinition < BridgeRectangleOptions , BridgeInfoWindowOptions > > ;
232242 declare optionsValue : MapOptions ;
243+ declare extraValue : Record < string , unknown > ;
233244
234245 declare hasCenterValue : boolean;
235246 declare hasZoomValue : boolean;
@@ -240,6 +251,7 @@ export default abstract class<
240251 declare hasCirclesValue : boolean;
241252 declare hasRectanglesValue : boolean;
242253 declare hasOptionsValue : boolean;
254+ declare hasExtraValue : boolean;
243255
244256 protected map : BridgeMap ;
245257 protected markers = new Map < Identifier , BridgeMarker > ( ) ;
@@ -259,10 +271,12 @@ export default abstract class<
259271 protected abstract dispatchEvent ( name : string , payload : Record < string , unknown > ) : void ;
260272
261273 connect ( ) {
274+ const extra = this . hasExtraValue ? this . extraValue : { } ;
262275 const mapDefinition : MapDefinition < MapOptions , BridgeMapOptions > = {
263276 center : this . hasCenterValue ? this . centerValue : null ,
264277 zoom : this . hasZoomValue ? this . zoomValue : null ,
265278 options : this . optionsValue ,
279+ extra,
266280 } ;
267281 this . dispatchEvent ( 'pre-connect' , mapDefinition ) ;
268282
@@ -291,6 +305,7 @@ export default abstract class<
291305 circles : [ ...this . circles . values ( ) ] ,
292306 rectangles : [ ...this . rectangles . values ( ) ] ,
293307 infoWindows : this . infoWindows ,
308+ extra,
294309 } ) ;
295310
296311 this . isConnected = true ;
0 commit comments