@@ -116,13 +116,11 @@ export class Marker<TUserData = unknown> {
116
116
this . bindMarkerEvents ( ) ;
117
117
118
118
// set all remaining parameters as attributes
119
- for ( const [ key , value ] of Object . entries ( attributes ) ) {
120
- this . setAttribute_ ( key as AttributeKey , value ) ;
121
- }
119
+ this . setAttributes ( attributes ) ;
122
120
123
121
if ( map ) {
124
122
this . map = map ;
125
- this . scheduleUpdate ( ) ;
123
+ this . update ( ) ;
126
124
}
127
125
}
128
126
@@ -188,7 +186,7 @@ export class Marker<TUserData = unknown> {
188
186
) ;
189
187
190
188
this . onMapBoundsChange ( map ) ;
191
- this . scheduleUpdate ( ) ;
189
+ this . update ( ) ;
192
190
}
193
191
}
194
192
@@ -199,7 +197,18 @@ export class Marker<TUserData = unknown> {
199
197
setData ( data : TUserData ) {
200
198
this . data_ = data ;
201
199
202
- this . scheduleUpdate ( ) ;
200
+ this . update ( ) ;
201
+ }
202
+
203
+ /**
204
+ * Sets multiple attributes at once.
205
+ * @param attributes
206
+ */
207
+ setAttributes ( attributes : Partial < Attributes < TUserData > > ) {
208
+ // set all remaining parameters as attributes
209
+ for ( const [ key , value ] of Object . entries ( attributes ) ) {
210
+ this . setAttribute_ ( key as AttributeKey , value ) ;
211
+ }
203
212
}
204
213
205
214
/**
@@ -213,7 +222,7 @@ export class Marker<TUserData = unknown> {
213
222
TValue extends Attributes < TUserData > [ TKey ]
214
223
> ( name : TKey , value : TValue ) {
215
224
// update the marker when we're done
216
- this . scheduleUpdate ( ) ;
225
+ this . update ( ) ;
217
226
218
227
if ( typeof value === 'function' ) {
219
228
this . dynamicAttributes_ [ name ] =
@@ -242,15 +251,14 @@ export class Marker<TUserData = unknown> {
242
251
/**
243
252
* Schedules an update via microtask. This makes sure that we won't
244
253
* run multiple updates when multiple attributes are changed sequentially.
245
- * @internal
246
254
*/
247
- private scheduleUpdate ( ) {
255
+ update ( ) {
248
256
if ( this . updateScheduled_ ) return ;
249
257
250
258
this . updateScheduled_ = true ;
251
259
queueMicrotask ( ( ) => {
252
260
this . updateScheduled_ = false ;
253
- this . update ( ) ;
261
+ this . performUpdate ( ) ;
254
262
} ) ;
255
263
}
256
264
@@ -264,7 +272,7 @@ export class Marker<TUserData = unknown> {
264
272
* setAttribute_ or the ComputedMarkerAttributes class
265
273
* @internal
266
274
*/
267
- private update ( ) {
275
+ private performUpdate ( ) {
268
276
if ( ! this . map || ! this . mapState_ ) {
269
277
console . warn ( 'marker update skipped: missing map or mapState' ) ;
270
278
return ;
@@ -359,12 +367,12 @@ export class Marker<TUserData = unknown> {
359
367
360
368
this . addListener ( 'pointerenter' , ( ) => {
361
369
this . markerState_ . hovered = true ;
362
- this . scheduleUpdate ( ) ;
370
+ this . update ( ) ;
363
371
} ) ;
364
372
365
373
this . addListener ( 'pointerleave' , ( ) => {
366
374
this . markerState_ . hovered = false ;
367
- this . scheduleUpdate ( ) ;
375
+ this . update ( ) ;
368
376
} ) ;
369
377
} ;
370
378
@@ -393,7 +401,7 @@ export class Marker<TUserData = unknown> {
393
401
tilt : map . getTilt ( ) || 0
394
402
} ;
395
403
396
- this . scheduleUpdate ( ) ;
404
+ this . update ( ) ;
397
405
} ;
398
406
399
407
/**
@@ -572,7 +580,7 @@ export type DynamicAttributes<TUserData> = {
572
580
573
581
// These are the attribute-types as specified to the constructor and
574
582
// individual attribute setters
575
- export type Attributes < TUserData > = {
583
+ export type Attributes < TUserData = unknown > = {
576
584
[ key in AttributeKey ] : AttributeValue < TUserData , StaticAttributes [ key ] > ;
577
585
} ;
578
586
0 commit comments