@vcmap/core 6.0.0-rc.3 → 6.0.0-rc.5

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.
Files changed (36) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js.map +1 -1
  3. package/dist/src/category/category.d.ts +3 -3
  4. package/dist/src/category/category.js.map +1 -1
  5. package/dist/src/classRegistry.d.ts +3 -2
  6. package/dist/src/classRegistry.js +2 -0
  7. package/dist/src/classRegistry.js.map +1 -1
  8. package/dist/src/map/obliqueMap.d.ts +3 -0
  9. package/dist/src/map/obliqueMap.js +27 -6
  10. package/dist/src/map/obliqueMap.js.map +1 -1
  11. package/dist/src/map/vcsMap.d.ts +8 -0
  12. package/dist/src/map/vcsMap.js +11 -0
  13. package/dist/src/map/vcsMap.js.map +1 -1
  14. package/dist/src/overrideClassRegistry.d.ts +2 -2
  15. package/dist/src/overrideClassRegistry.js +5 -3
  16. package/dist/src/overrideClassRegistry.js.map +1 -1
  17. package/dist/src/util/hiddenObjects.js.map +1 -1
  18. package/dist/src/util/mapCollection.js +8 -0
  19. package/dist/src/util/mapCollection.js.map +1 -1
  20. package/dist/src/util/overrideCollection.d.ts +7 -7
  21. package/dist/src/util/overrideCollection.js +4 -6
  22. package/dist/src/util/overrideCollection.js.map +1 -1
  23. package/dist/src/vcsModuleHelpers.d.ts +1 -0
  24. package/dist/src/vcsModuleHelpers.js +16 -2
  25. package/dist/src/vcsModuleHelpers.js.map +1 -1
  26. package/index.ts +1 -0
  27. package/package.json +1 -1
  28. package/src/category/category.ts +8 -7
  29. package/src/classRegistry.ts +6 -3
  30. package/src/map/obliqueMap.ts +46 -6
  31. package/src/map/vcsMap.ts +20 -2
  32. package/src/overrideClassRegistry.ts +13 -7
  33. package/src/util/hiddenObjects.ts +4 -4
  34. package/src/util/mapCollection.ts +8 -0
  35. package/src/util/overrideCollection.ts +27 -20
  36. package/src/vcsModuleHelpers.ts +25 -2
@@ -30,7 +30,7 @@ export type OverrideCollectionItem = {
30
30
  * removed current item. 2) replaced is called for items which where replaced. 3) added can be called more the once for the same unique id.
31
31
  * Replaced is called before added has been called for the item.
32
32
  */
33
- export type OverrideCollectionInterface<T> = {
33
+ export type OverrideCollectionInterface<T, S> = {
34
34
  /**
35
35
  * replaced is called before added
36
36
  */
@@ -40,16 +40,16 @@ export type OverrideCollectionInterface<T> = {
40
40
  * Returns the replaced item or null if the item could not be inserted
41
41
  */
42
42
  replace: (item: T) => T | null;
43
- shadowMap: Map<string, (object & { [moduleIdSymbol]?: string })[]>;
43
+ shadowMap: Map<string, (S & { [moduleIdSymbol]?: string })[]>;
44
44
  /**
45
45
  * returns the overriden item or null if the item could not be inserted (this would be the result of a race condition)
46
46
  */
47
47
  override: (item: T) => T | null;
48
48
  parseItems: (
49
- items: (object & { type?: string })[] | undefined,
49
+ items: (S & { type?: string })[] | undefined,
50
50
  moduleId: string,
51
51
  ) => Promise<void>;
52
- getSerializedByKey: (key: string) => object | undefined;
52
+ getSerializedByKey: (key: string) => S | undefined;
53
53
  removeModule: (moduleId: string) => void;
54
54
  serializeModule: (moduleId: string) => object[];
55
55
  [isOverrideCollection]: boolean;
@@ -59,7 +59,16 @@ export type OverrideCollectionInterface<T> = {
59
59
  export type OverrideCollection<
60
60
  T extends OverrideCollectionItem,
61
61
  C extends Collection<T> = Collection<T>,
62
- > = C & OverrideCollectionInterface<T>;
62
+ S extends object = T['toJSON'] extends () => object
63
+ ? ReturnType<T['toJSON']>
64
+ : T,
65
+ > = C & OverrideCollectionInterface<T, S>;
66
+
67
+ function defaulSerialization(
68
+ i: OverrideCollectionItem,
69
+ ): object & { [moduleIdSymbol]?: string } {
70
+ return i.toJSON ? i.toJSON() : structuredClone(i);
71
+ }
63
72
 
64
73
  /**
65
74
  * @param collection
@@ -71,22 +80,25 @@ export type OverrideCollection<
71
80
  */
72
81
  function makeOverrideCollection<
73
82
  T extends OverrideCollectionItem,
74
- C extends Collection<T>,
83
+ C extends Collection<T> = Collection<T>,
84
+ S extends object = T['toJSON'] extends () => object
85
+ ? ReturnType<T['toJSON']>
86
+ : T,
75
87
  >(
76
88
  collection: C,
77
89
  getDynamicModuleId: () => string,
78
- serializeItem?: (item: T) => object & { [moduleIdSymbol]?: string },
79
- deserializeItem?: (item: object) => T | Promise<T> | null,
90
+ serializeItem?: (item: T) => S & { [moduleIdSymbol]?: string },
91
+ deserializeItem?: (item: S) => T | Promise<T> | null,
80
92
  ctor?: new (...args: any[]) => T,
81
93
  determineShadowIndex?: (
82
94
  item: T,
83
95
  shadow?: T,
84
96
  index?: number,
85
97
  ) => number | null | undefined,
86
- ): OverrideCollection<T, C> {
98
+ ): OverrideCollection<T, C, S> {
87
99
  check(collection, Collection);
88
100
 
89
- const overrideCollection = collection as OverrideCollection<T, C>;
101
+ const overrideCollection = collection as OverrideCollection<T, C, S>;
90
102
  if (overrideCollection[isOverrideCollection]) {
91
103
  throw new Error(
92
104
  'Cannot transform collection, collection already is an OverrideCollection',
@@ -94,11 +106,10 @@ function makeOverrideCollection<
94
106
  }
95
107
  overrideCollection[isOverrideCollection] = true;
96
108
 
97
- const deserialize = deserializeItem || ((i: object): T => i as T);
98
- const serialize =
99
- serializeItem ||
100
- ((i: T): object & { [moduleIdSymbol]?: string } =>
101
- i.toJSON ? i.toJSON() : structuredClone(i));
109
+ const deserialize = deserializeItem || ((i: S): T => i as unknown as T);
110
+ const serialize = (serializeItem || defaulSerialization) as (
111
+ item: T,
112
+ ) => S & { [moduleIdSymbol]?: string };
102
113
  const getShadowIndex =
103
114
  determineShadowIndex ||
104
115
  ((
@@ -196,7 +207,7 @@ function makeOverrideCollection<
196
207
 
197
208
  overrideCollection.getSerializedByKey = function getSerializedByKey(
198
209
  key,
199
- ): object | undefined {
210
+ ): S | undefined {
200
211
  const item = overrideCollection.getByKey(key);
201
212
  if (item) {
202
213
  return serialize(item);
@@ -273,10 +284,6 @@ function makeOverrideCollection<
273
284
 
274
285
  overrideCollection.replaced = new VcsEvent();
275
286
 
276
- /**
277
- * @param {string} moduleId
278
- * @returns {Object[]}
279
- */
280
287
  overrideCollection.serializeModule = function serializeModule(
281
288
  moduleId,
282
289
  ): object[] {
@@ -20,6 +20,7 @@ function getLogger(): Logger {
20
20
 
21
21
  export type ModuleLayerOptions = LayerOptions & {
22
22
  style?: string | StyleItemOptions;
23
+ highlightStyle?: string | StyleItemOptions;
23
24
  tileProvider?: TileProviderOptions;
24
25
  featureProvider?: AbstractFeatureProviderOptions;
25
26
  };
@@ -60,7 +61,18 @@ export function deserializeLayer(
60
61
  layerConfig.style,
61
62
  );
62
63
  }
63
- } // TODO highlightStyle
64
+ }
65
+ let highlightStyle: StyleItem | undefined | null;
66
+ if (layerConfig.highlightStyle) {
67
+ if (typeof layerConfig.highlightStyle === 'string') {
68
+ highlightStyle = vcsApp.styles.getByKey(layerConfig.highlightStyle);
69
+ } else {
70
+ highlightStyle = getObjectFromClassRegistry(
71
+ vcsApp.styleClassRegistry,
72
+ layerConfig.highlightStyle,
73
+ );
74
+ }
75
+ }
64
76
 
65
77
  let tileProvider;
66
78
  if (layerConfig.tileProvider) {
@@ -81,6 +93,7 @@ export function deserializeLayer(
81
93
  return getObjectFromClassRegistry(vcsApp.layerClassRegistry, {
82
94
  ...layerConfig,
83
95
  style,
96
+ highlightStyle,
84
97
  tileProvider,
85
98
  featureProvider,
86
99
  });
@@ -99,7 +112,17 @@ export function serializeLayer(
99
112
  vcsApp.styles.hasKey((serializedLayer.style as StyleItemOptions).name)
100
113
  ) {
101
114
  serializedLayer.style = (serializedLayer.style as StyleItemOptions).name;
102
- } // TODO highlightStyle
115
+ }
116
+ if (
117
+ (serializedLayer?.highlightStyle as StyleItemOptions)?.name &&
118
+ vcsApp.styles.hasKey(
119
+ (serializedLayer.highlightStyle as StyleItemOptions).name,
120
+ )
121
+ ) {
122
+ serializedLayer.highlightStyle = (
123
+ serializedLayer.highlightStyle as StyleItemOptions
124
+ ).name;
125
+ }
103
126
  return serializedLayer;
104
127
  }
105
128