@vcmap/core 5.0.0-rc.13 → 5.0.0-rc.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -1828,7 +1828,9 @@ export class FeatureStoreLayerChanges extends VcsObject {
1828
1828
  /**
1829
1829
  * commits the changes to the provided url. url should contain accessTokens and point to a featureStore layers bulk operation endpoint
1830
1830
  */
1831
- commitChanges(url: string): Promise<void>;
1831
+ commitChanges(url: string, headers?: {
1832
+ [key: string]: string;
1833
+ }): Promise<void>;
1832
1834
  /**
1833
1835
  * resets all changes since the last commit or the beginning of tracking
1834
1836
  */
@@ -7502,9 +7504,11 @@ export class VcsApp {
7502
7504
  readonly styles: OverrideCollection<StyleItem>;
7503
7505
  readonly categories: CategoryCollection;
7504
7506
  readonly destroyed: VcsEvent<void>;
7507
+ readonly contexts: Context[];
7505
7508
  readonly contextAdded: any;
7506
7509
  readonly contextRemoved: any;
7507
7510
  readonly dynamicContextId: string;
7511
+ readonly dynamicContextIdChanged: VcsEvent<string>;
7508
7512
  readonly mapClassRegistry: OverrideClassRegistry<VcsMap>;
7509
7513
  readonly layerClassRegistry: OverrideClassRegistry<Layer>;
7510
7514
  readonly styleClassRegistry: OverrideClassRegistry<StyleItem>;
@@ -7516,6 +7520,14 @@ export class VcsApp {
7516
7520
  protected _parseContext(context: Context): Promise<void>;
7517
7521
  protected _setContextState(context: Context): Promise<void>;
7518
7522
  addContext(context: Context): Promise<void>;
7523
+ /**
7524
+ * sets the given context as the dynamic
7525
+ */
7526
+ setDynamicContext(context: Context): void;
7527
+ /**
7528
+ * resets the dynamic Context to the "defaultDynamicContext"
7529
+ */
7530
+ resetDynamicContext(): void;
7519
7531
  protected _removeContext(contextId: string): Promise<void>;
7520
7532
  removeContext(contextId: string): Promise<void>;
7521
7533
  /**
@@ -7609,8 +7621,13 @@ export class VcsObject {
7609
7621
 
7610
7622
 
7611
7623
 
7624
+ export interface ReplacedEvent<T extends any> {
7625
+ new: T,
7626
+ old: T,
7627
+ }
7628
+
7612
7629
  export interface OverrideCollectionInterface<T extends any> {
7613
- replaced: VcsEvent<T>;
7630
+ replaced: VcsEvent<ReplacedEvent<T>>;
7614
7631
  shadowMap: Map<string, object[]>;
7615
7632
  override: (item: T) => T;
7616
7633
  parseItems: (items: object[], contextId: string) => Promise<void>;
@@ -7619,7 +7636,7 @@ export interface OverrideCollectionInterface<T extends any> {
7619
7636
  }
7620
7637
 
7621
7638
  export class OverrideCollection<T extends any> extends Collection<T> implements OverrideCollectionInterface<T> {
7622
- replaced: VcsEvent<T>;
7639
+ replaced: VcsEvent<ReplacedEvent<T>>;
7623
7640
  shadowMap: Map<string, object[]>;
7624
7641
  override: (item: T) => T;
7625
7642
  parseItems: (items: object[], contextId: string) => Promise<void>;
@@ -7628,7 +7645,7 @@ export class OverrideCollection<T extends any> extends Collection<T> implements
7628
7645
  }
7629
7646
 
7630
7647
  export class OverrideLayerCollection extends LayerCollection implements OverrideCollectionInterface<Layer> {
7631
- replaced: VcsEvent<Layer>;
7648
+ replaced: VcsEvent<ReplacedEvent<Layer>>;
7632
7649
  shadowMap: Map<string, object[]>;
7633
7650
  override: (item: Layer) => Layer;
7634
7651
  parseItems: (items: object[], contextId: string) => Promise<void>;
@@ -7637,7 +7654,7 @@ export class OverrideLayerCollection extends LayerCollection implements Override
7637
7654
  }
7638
7655
 
7639
7656
  export class OverrideMapCollection extends MapCollection implements OverrideCollectionInterface<VcsMap> {
7640
- replaced: VcsEvent<VcsMap>;
7657
+ replaced: VcsEvent<ReplacedEvent<VcsMap>>;
7641
7658
  shadowMap: Map<string, object[]>;
7642
7659
  override: (item: VcsMap) => VcsMap;
7643
7660
  parseItems: (items: object[], contextId: string) => Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vcmap/core",
3
- "version": "5.0.0-rc.13",
3
+ "version": "5.0.0-rc.14",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -163,15 +163,17 @@ class FeatureStoreLayerChanges extends VcsObject {
163
163
  /**
164
164
  * commits the changes to the provided url. url should contain accessTokens and point to a featureStore layers bulk operation endpoint
165
165
  * @param {string} url
166
+ * @param {Object<string, string>=} headers
166
167
  * @returns {Promise<void>}
167
168
  * @api
168
169
  */
169
- async commitChanges(url) {
170
+ async commitChanges(url, headers = {}) {
170
171
  const actions = createCommitActions(this._addedFeatures, this._editedFeatures, this._removedFeatures);
171
172
  if (actions.length > 0) {
172
173
  const data = await requestJson(url.toString(), {
173
174
  method: 'POST',
174
175
  headers: {
176
+ ...headers,
175
177
  'Content-Type': 'application/json',
176
178
  },
177
179
  body: JSON.stringify(actions.map(a => ({ action: a.action, feature: a.feature }))),
@@ -91,18 +91,18 @@ function makeOverrideCollection(
91
91
  }
92
92
  const shadowsArray = overrideCollection.shadowMap.get(itemId);
93
93
  const serializedShadow = serialize(shadow);
94
- // @ts-ignore
95
- if (shadow.destroy) {
96
- // @ts-ignore
97
- shadow.destroy();
98
- }
99
94
  serializedShadow[contextIdSymbol] = shadow[contextIdSymbol];
100
95
  shadowsArray.push(serializedShadow);
101
96
  }
102
97
 
103
98
  const usedIndex = shadow ? getShadowIndex(shadow, item, index) : null;
104
99
  if (shadow) {
105
- overrideCollection.replaced.raiseEvent(item);
100
+ overrideCollection.replaced.raiseEvent({ old: shadow, new: item });
101
+ // @ts-ignore
102
+ if (shadow.destroy) {
103
+ // @ts-ignore
104
+ shadow.destroy();
105
+ }
106
106
  }
107
107
  // @ts-ignore
108
108
  if (overrideCollection.add(item, usedIndex) >= 0) {
@@ -186,7 +186,7 @@ function makeOverrideCollection(
186
186
  };
187
187
 
188
188
  /**
189
- * @type {VcsEvent<T>}
189
+ * @type {VcsEvent<ReplacedEvent<T>>}
190
190
  */
191
191
  overrideCollection.replaced = new VcsEvent();
192
192
 
package/src/vcsApp.js CHANGED
@@ -70,6 +70,12 @@ class VcsApp {
70
70
 
71
71
  const getDynamicContextId = () => this._dynamicContext.id;
72
72
 
73
+ /**
74
+ * @type {VcsEvent<string>}
75
+ * @private
76
+ */
77
+ this._dynamicContextIdChanged = new VcsEvent();
78
+
73
79
  /**
74
80
  * represents the current Locale.
75
81
  * @type {string}
@@ -287,6 +293,14 @@ class VcsApp {
287
293
  */
288
294
  get destroyed() { return this._destroyed; }
289
295
 
296
+ /**
297
+ * @type {Array<Context>}
298
+ * @readonly
299
+ */
300
+ get contexts() {
301
+ return [...this._contexts];
302
+ }
303
+
290
304
  /**
291
305
  * @returns {VcsEvent<Context>}
292
306
  * @readonly
@@ -305,6 +319,12 @@ class VcsApp {
305
319
  */
306
320
  get dynamicContextId() { return this._dynamicContext.id; }
307
321
 
322
+ /**
323
+ * @type {VcsEvent<string>}
324
+ * @readonly
325
+ */
326
+ get dynamicContextIdChanged() { return this._dynamicContextIdChanged; }
327
+
308
328
  /**
309
329
  * @type {OverrideClassRegistry<VcsMap>}
310
330
  * @readonly
@@ -446,6 +466,27 @@ class VcsApp {
446
466
  return this._contextMutationPromise;
447
467
  }
448
468
 
469
+ /**
470
+ * sets the given context as the dynamic
471
+ * @param {Context} context
472
+ */
473
+ setDynamicContext(context) {
474
+ if (!this._contexts.has(context)) {
475
+ throw new Error('Context is not managed by this app, call add(context) before');
476
+ }
477
+ if (this._dynamicContext !== context) {
478
+ this._dynamicContext = context;
479
+ this.dynamicContextIdChanged.raiseEvent(this.dynamicContextId);
480
+ }
481
+ }
482
+
483
+ /**
484
+ * resets the dynamic Context to the "defaultDynamicContext"
485
+ */
486
+ resetDynamicContext() {
487
+ this.setDynamicContext(this._defaultDynamicContext);
488
+ }
489
+
449
490
  /**
450
491
  * @param {string} contextId
451
492
  * @returns {Promise<void>}
@@ -507,6 +548,7 @@ class VcsApp {
507
548
  this.destroyed.raiseEvent();
508
549
  this.destroyed.destroy();
509
550
  this.localeChanged.destroy();
551
+ this.dynamicContextIdChanged.destroy();
510
552
  }
511
553
  }
512
554