@vcmap/core 5.1.2 → 5.1.4

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 (55) hide show
  1. package/dist/cesium.d.ts +1 -0
  2. package/dist/index.d.ts +1 -0
  3. package/dist/index.js +1 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/src/category/category.js.map +1 -1
  6. package/dist/src/layer/featureStoreFeatureVisibility.d.ts +10 -0
  7. package/dist/src/layer/featureStoreFeatureVisibility.js +49 -0
  8. package/dist/src/layer/featureStoreFeatureVisibility.js.map +1 -0
  9. package/dist/src/layer/featureStoreLayer.d.ts +4 -1
  10. package/dist/src/layer/featureStoreLayer.js +6 -0
  11. package/dist/src/layer/featureStoreLayer.js.map +1 -1
  12. package/dist/src/layer/vectorLayer.d.ts +3 -0
  13. package/dist/src/layer/vectorLayer.js +4 -1
  14. package/dist/src/layer/vectorLayer.js.map +1 -1
  15. package/dist/src/layer/wmsLayer.js +5 -1
  16. package/dist/src/layer/wmsLayer.js.map +1 -1
  17. package/dist/src/style/declarativeStyleItem.d.ts +1 -1
  18. package/dist/src/style/modelFill.d.ts +6 -0
  19. package/dist/src/style/modelFill.js +13 -0
  20. package/dist/src/style/modelFill.js.map +1 -0
  21. package/dist/src/style/styleFactory.js +1 -1
  22. package/dist/src/style/styleFactory.js.map +1 -1
  23. package/dist/src/style/vectorStyleItem.d.ts +7 -2
  24. package/dist/src/style/vectorStyleItem.js +6 -2
  25. package/dist/src/style/vectorStyleItem.js.map +1 -1
  26. package/dist/src/util/editor/editGeometrySession.js +1 -3
  27. package/dist/src/util/editor/editGeometrySession.js.map +1 -1
  28. package/dist/src/util/editor/selectFeaturesSession.js +3 -2
  29. package/dist/src/util/editor/selectFeaturesSession.js.map +1 -1
  30. package/dist/src/util/featureconverter/pointHelpers.d.ts +1 -1
  31. package/dist/src/util/featureconverter/pointHelpers.js +12 -1
  32. package/dist/src/util/featureconverter/pointHelpers.js.map +1 -1
  33. package/dist/src/util/featureconverter/pointToCesium.js +2 -2
  34. package/dist/src/util/featureconverter/pointToCesium.js.map +1 -1
  35. package/dist/tests/unit/helpers/cesiumHelpers.d.ts +4 -46
  36. package/dist/tests/unit/helpers/cesiumHelpers.js +3 -0
  37. package/dist/tests/unit/helpers/cesiumHelpers.js.map +1 -1
  38. package/dist/tests/unit/helpers/terrain/terrainData.d.ts +2 -2
  39. package/dist/tests/unit/helpers/terrain/terrainData.js +1 -1
  40. package/index.ts +1 -0
  41. package/package.json +1 -1
  42. package/src/category/category.ts +1 -1
  43. package/src/cesium/cesium.d.ts +1 -0
  44. package/src/layer/featureStoreFeatureVisibility.ts +55 -0
  45. package/src/layer/featureStoreLayer.ts +15 -2
  46. package/src/layer/vectorLayer.ts +4 -1
  47. package/src/layer/wmsLayer.ts +10 -1
  48. package/src/style/declarativeStyleItem.ts +1 -1
  49. package/src/style/modelFill.ts +15 -0
  50. package/src/style/styleFactory.ts +1 -1
  51. package/src/style/vectorStyleItem.ts +14 -4
  52. package/src/util/editor/editGeometrySession.ts +1 -3
  53. package/src/util/editor/selectFeaturesSession.ts +3 -2
  54. package/src/util/featureconverter/pointHelpers.ts +13 -0
  55. package/src/util/featureconverter/pointToCesium.ts +2 -0
@@ -0,0 +1,55 @@
1
+ import FeatureVisibility, { HighlightStyleType } from './featureVisibility.js';
2
+ import type FeatureStoreLayerChanges from './featureStoreLayerChanges.js';
3
+
4
+ export default class FeatureStoreFeatureVisibility extends FeatureVisibility {
5
+ private _changeTracker: FeatureStoreLayerChanges;
6
+
7
+ constructor(changeTracker: FeatureStoreLayerChanges) {
8
+ super();
9
+ this._changeTracker = changeTracker;
10
+ }
11
+
12
+ highlight(toHighlight: Record<string, HighlightStyleType>): void {
13
+ const isTracking = this._changeTracker.active;
14
+ if (isTracking) {
15
+ this._changeTracker.pauseTracking('changefeature');
16
+ }
17
+ super.highlight(toHighlight);
18
+ if (isTracking) {
19
+ this._changeTracker.track();
20
+ }
21
+ }
22
+
23
+ unHighlight(toUnHighlight: (string | number)[]): void {
24
+ const isTracking = this._changeTracker.active;
25
+ if (isTracking) {
26
+ this._changeTracker.pauseTracking('changefeature');
27
+ }
28
+ super.unHighlight(toUnHighlight);
29
+ if (isTracking) {
30
+ this._changeTracker.track();
31
+ }
32
+ }
33
+
34
+ hideObjects(toHide: (string | number)[]): void {
35
+ const isTracking = this._changeTracker.active;
36
+ if (isTracking) {
37
+ this._changeTracker.pauseTracking('changefeature');
38
+ }
39
+ super.hideObjects(toHide);
40
+ if (isTracking) {
41
+ this._changeTracker.track();
42
+ }
43
+ }
44
+
45
+ showObjects(unHide: (string | number)[]): void {
46
+ const isTracking = this._changeTracker.active;
47
+ if (isTracking) {
48
+ this._changeTracker.pauseTracking('changefeature');
49
+ }
50
+ super.showObjects(unHide);
51
+ if (isTracking) {
52
+ this._changeTracker.track();
53
+ }
54
+ }
55
+ }
@@ -45,6 +45,7 @@ import { vcsLayerName } from './layerSymbols.js';
45
45
  import StyleItem from '../style/styleItem.js';
46
46
  import VcsMap from '../map/vcsMap.js';
47
47
  import VectorCesiumImpl from './cesium/vectorCesiumImpl.js';
48
+ import FeatureStoreFeatureVisibility from './featureStoreFeatureVisibility.js';
48
49
 
49
50
  export type FeatureStoreStaticRepresentation = {
50
51
  /**
@@ -57,7 +58,10 @@ export type FeatureStoreStaticRepresentation = {
57
58
  twoDim?: string;
58
59
  };
59
60
 
60
- export type FeatureStoreLayerSchema = VectorOptions & {
61
+ export type FeatureStoreLayerSchema = Omit<
62
+ VectorOptions,
63
+ 'featureVisibility'
64
+ > & {
61
65
  /**
62
66
  * layer mongo id
63
67
  */
@@ -91,6 +95,8 @@ export type FeatureStoreOptions = FeatureStoreLayerSchema & {
91
95
  * injected function for fetching dynamic features from a remote FeatureStoreLayer server
92
96
  */
93
97
  injectedFetchDynamicFeatureFunc?: FetchDynamicFeatureCallback;
98
+
99
+ featureVisibility?: FeatureStoreFeatureVisibility;
94
100
  };
95
101
 
96
102
  export const isTiledFeature: unique symbol = Symbol('isTiledFeature');
@@ -112,6 +118,7 @@ class FeatureStoreLayer extends VectorLayer {
112
118
  featureType: 'simple',
113
119
  features: [],
114
120
  ...VectorLayer.getDefaultOptions(),
121
+ featureVisibility: undefined,
115
122
  projection: mercatorProjection.toJSON(),
116
123
  staticRepresentation: {},
117
124
  hiddenStaticFeatureIds: [],
@@ -142,6 +149,8 @@ class FeatureStoreLayer extends VectorLayer {
142
149
 
143
150
  screenSpaceError: number | undefined;
144
151
 
152
+ featureVisibility: FeatureStoreFeatureVisibility;
153
+
145
154
  private _removeVectorPropertiesChangeHandler: () => void;
146
155
 
147
156
  /**
@@ -210,6 +219,10 @@ class FeatureStoreLayer extends VectorLayer {
210
219
  options.injectedFetchDynamicFeatureFunc ??
211
220
  this.injectedFetchDynamicFeatureFunc;
212
221
 
222
+ this.featureVisibility =
223
+ options.featureVisibility ??
224
+ new FeatureStoreFeatureVisibility(this.changeTracker);
225
+
213
226
  this._featureVisibilitySyncListeners = [
214
227
  synchronizeFeatureVisibility(
215
228
  this.featureVisibility,
@@ -571,7 +584,7 @@ class FeatureStoreLayer extends VectorLayer {
571
584
  }
572
585
 
573
586
  toJSON(): FeatureStoreOptions {
574
- const config: Partial<FeatureStoreOptions> = super.toJSON();
587
+ const config = super.toJSON() as Partial<FeatureStoreOptions>;
575
588
  const defaultOptions = FeatureStoreLayer.getDefaultOptions();
576
589
 
577
590
  delete config.projection;
@@ -436,7 +436,10 @@ class VectorLayer
436
436
  /**
437
437
  * add features to the vector layer and return an array with their ids.
438
438
  * The geometry will be mutated and transformed to EPSG 3857 mercator coordinate system
439
+ * features will be added an id, if they do not already have one.
439
440
  *
441
+ * returns the ids of the added features. if a feature has an id and the same id is alread in the
442
+ * layer, it will not be added.
440
443
  * @todo mechanism to enforce XYZ coordinate layout for internal usage
441
444
  */
442
445
  addFeatures(features: Feature[]): (string | number)[] {
@@ -475,7 +478,7 @@ class VectorLayer
475
478
  .filter((f) => f) as Feature[];
476
479
 
477
480
  this.source.addFeatures(toAdd);
478
- return features.map((f) => f.getId()) as (string | number)[];
481
+ return toAdd.map((f) => f.getId()) as (string | number)[];
479
482
  }
480
483
 
481
484
  /**
@@ -39,6 +39,7 @@ export type WMSOptions = RasterLayerOptions & {
39
39
  * key value pair of additional WMS parameters, url query notation possible
40
40
  */
41
41
  parameters?: Record<string, string> | string;
42
+
42
43
  /**
43
44
  * whether this layer should send getFeatureInfo requests to the service when objects are clicked.
44
45
  */
@@ -75,6 +76,7 @@ class WMSLayer extends RasterLayer<WmsCesiumImpl | WmsOpenlayersImpl> {
75
76
  tileSize: [256, 256],
76
77
  highResolution: false,
77
78
  layers: '',
79
+ singleImage2d: false,
78
80
  };
79
81
  }
80
82
 
@@ -134,7 +136,10 @@ class WMSLayer extends RasterLayer<WmsCesiumImpl | WmsOpenlayersImpl> {
134
136
  this._featureInfoOptions =
135
137
  options.featureInfo || defaultOptions.featureInfo;
136
138
  this._supportedMaps = [CesiumMap.className, OpenlayersMap.className];
137
- this.singleImage2d = parseBoolean(options.singleImage2d, false);
139
+ this.singleImage2d = parseBoolean(
140
+ options.singleImage2d,
141
+ defaultOptions.singleImage2d,
142
+ );
138
143
  }
139
144
 
140
145
  initialize(): Promise<void> {
@@ -252,6 +257,10 @@ class WMSLayer extends RasterLayer<WmsCesiumImpl | WmsOpenlayersImpl> {
252
257
  config.tileSize = this.tileSize.slice();
253
258
  }
254
259
 
260
+ if (this.singleImage2d !== defaultOptions.singleImage2d) {
261
+ config.singleImage2d = this.singleImage2d;
262
+ }
263
+
255
264
  if (
256
265
  this.featureProvider &&
257
266
  this.featureProvider instanceof WMSFeatureProvider
@@ -95,7 +95,7 @@ function addCustomProperty(
95
95
  * @group Style
96
96
  */
97
97
  class DeclarativeStyleItem extends StyleItem {
98
- static get className(): string {
98
+ static get className(): 'DeclarativeStyleItem' {
99
99
  return 'DeclarativeStyleItem';
100
100
  }
101
101
 
@@ -0,0 +1,15 @@
1
+ import { Fill } from 'ol/style.js';
2
+
3
+ class ModelFill extends Fill {
4
+ static fromFill(fill: Fill): ModelFill {
5
+ return new ModelFill({ color: fill.getColor() });
6
+ }
7
+
8
+ toFill(result?: Fill): Fill {
9
+ const fill = result ?? new Fill();
10
+ fill.setColor(this.getColor());
11
+ return fill;
12
+ }
13
+ }
14
+
15
+ export default ModelFill;
@@ -27,7 +27,7 @@ export function getStyleOrDefaultStyle(
27
27
  styleItem instanceof VectorStyleItem &&
28
28
  defaultStyle instanceof VectorStyleItem
29
29
  ) {
30
- return defaultStyle.assign(styleItem);
30
+ return styleItem.assign(defaultStyle.clone().assign(styleItem));
31
31
  }
32
32
  return styleItem;
33
33
  }
@@ -33,6 +33,7 @@ import {
33
33
  import { getShapeFromOptions } from './shapesCategory.js';
34
34
  import { styleClassRegistry } from '../classRegistry.js';
35
35
  import { isSameOrigin } from '../util/urlHelpers.js';
36
+ import ModelFill from './modelFill.js';
36
37
 
37
38
  export type ColorType = OLColor | OLColorLike;
38
39
  export type VectorStyleItemPattern = {
@@ -45,6 +46,12 @@ export type VectorStyleItemPattern = {
45
46
  export type VectorStyleItemFill = {
46
47
  color: ColorType;
47
48
  pattern?: VectorStyleItemPattern;
49
+ type?: 'fill' | 'modelFill';
50
+ };
51
+
52
+ export type VectorStyleItemStroke = {
53
+ width?: number;
54
+ color?: ColorType;
48
55
  };
49
56
 
50
57
  export type VectorStyleItemImage = {
@@ -87,7 +94,7 @@ export enum OlcsGeometryType {
87
94
 
88
95
  export type VectorStyleItemOptions = StyleItemOptions & {
89
96
  fill?: VectorStyleItemFill | false;
90
- stroke?: StrokeOptions | false;
97
+ stroke?: StrokeOptions | VectorStyleItemStroke | false;
91
98
  image?: VectorStyleItemImage | false;
92
99
  text?: VectorStyleItemText;
93
100
  label?: string;
@@ -104,7 +111,7 @@ export const vectorStyleSymbol: unique symbol = Symbol('VcsVectorStyleItem');
104
111
  * @group Style
105
112
  */
106
113
  class VectorStyleItem extends StyleItem {
107
- static get className(): string {
114
+ static get className(): 'VectorStyleItem' {
108
115
  return 'VectorStyleItem';
109
116
  }
110
117
 
@@ -171,7 +178,7 @@ class VectorStyleItem extends StyleItem {
171
178
  });
172
179
 
173
180
  if (options.fill) {
174
- this._fillOptions = options.fill;
181
+ this._fillOptions = structuredClone(options.fill);
175
182
  this._setFill();
176
183
  } else {
177
184
  this.updateCesiumStyle();
@@ -446,7 +453,10 @@ class VectorStyleItem extends StyleItem {
446
453
  if (this._fill) {
447
454
  this._fill.setColor(color);
448
455
  } else {
449
- this._fill = new Fill({ color });
456
+ this._fill =
457
+ this._fillOptions?.type === 'modelFill'
458
+ ? new ModelFill({ color })
459
+ : new Fill({ color });
450
460
  this._style.setFill(this._fill);
451
461
  }
452
462
 
@@ -322,9 +322,7 @@ function createEditPointInteraction(
322
322
  let suspend = false;
323
323
  translateVertex.vertexChanged.addEventListener(() => {
324
324
  suspend = true;
325
- feature
326
- .getGeometry()!
327
- .setCoordinates(vertex.getGeometry()!.getCoordinates());
325
+ geometry.setCoordinates(vertex.getGeometry()!.getCoordinates());
328
326
  suspend = false;
329
327
  });
330
328
 
@@ -1,5 +1,5 @@
1
1
  import { check, ofEnum } from '@vcsuite/check';
2
- import { Circle, Fill, Style, Stroke } from 'ol/style.js';
2
+ import { Circle, Style, Stroke } from 'ol/style.js';
3
3
  import type { Feature } from 'ol/index.js';
4
4
  import { createSync } from '../../layer/vectorSymbols.js';
5
5
  import {
@@ -19,6 +19,7 @@ import type VectorLayer from '../../layer/vectorLayer.js';
19
19
  import type VcsApp from '../../vcsApp.js';
20
20
  import type VcsMap from '../../map/vcsMap.js';
21
21
  import { type HighlightStyleType } from '../../layer/featureVisibility.js';
22
+ import ModelFill from '../../style/modelFill.js';
22
23
 
23
24
  type SelectionHighlightManager = {
24
25
  highlightedFeatures: Feature[];
@@ -104,7 +105,7 @@ function createHighlightManager(
104
105
  }
105
106
 
106
107
  export function getDefaultHighlightStyle(): Style {
107
- const fill = new Fill({ color: 'rgba(76,175,80,0.2)' });
108
+ const fill = new ModelFill({ color: 'rgba(76,175,80,0.2)' });
108
109
  const stroke = new Stroke({ color: '#4CAF50', width: 2 });
109
110
 
110
111
  return new Style({
@@ -28,6 +28,7 @@ import {
28
28
  import type { Feature } from 'ol/index.js';
29
29
  import type { Coordinate } from 'ol/coordinate.js';
30
30
  import { RegularShape, type Style } from 'ol/style.js';
31
+ import { asColorLike } from 'ol/colorlike.js';
31
32
  import { createSync } from '../../layer/vectorSymbols.js';
32
33
  import VectorProperties, {
33
34
  PrimitiveOptionsType,
@@ -37,6 +38,7 @@ import VectorProperties, {
37
38
  VectorPropertiesPrimitiveOptions,
38
39
  } from '../../layer/vectorProperties.js';
39
40
  import { getCesiumColor } from '../../style/styleHelpers.js';
41
+ import ModelFill from '../../style/modelFill.js';
40
42
 
41
43
  function makeOffsetAutoScalePrimitive(
42
44
  primitive: Primitive | Model,
@@ -124,6 +126,7 @@ export async function getModelOptions(
124
126
  positions: Cartesian3[],
125
127
  vectorProperties: VectorProperties,
126
128
  scene: Scene,
129
+ style?: Style,
127
130
  ): Promise<null | {
128
131
  primitives: Model[];
129
132
  options: VectorPropertiesModelOptions;
@@ -139,6 +142,15 @@ export async function getModelOptions(
139
142
  options.roll,
140
143
  );
141
144
  const allowPicking = vectorProperties.getAllowPicking(feature);
145
+ const fill = style?.getFill();
146
+ let color: Color | undefined;
147
+ if (fill instanceof ModelFill) {
148
+ const olColor = fill.getColor();
149
+ if (olColor) {
150
+ color = Color.fromCssColorString(asColorLike(olColor) as string);
151
+ }
152
+ }
153
+
142
154
  const primitives = await Promise.all(
143
155
  positions.map(async (position, index) => {
144
156
  const modelMatrix = Matrix4.multiply(
@@ -154,6 +166,7 @@ export async function getModelOptions(
154
166
  url: options.url,
155
167
  modelMatrix,
156
168
  allowPicking,
169
+ color,
157
170
  ...additionalModelOptions,
158
171
  });
159
172
 
@@ -301,6 +301,7 @@ export default async function pointToCesium(
301
301
  positions,
302
302
  vectorProperties,
303
303
  scene,
304
+ style,
304
305
  );
305
306
  } else if (feature.get('olcs_primitiveOptions')) {
306
307
  modelOrPrimitiveOptions = await getPrimitiveOptions(
@@ -319,6 +320,7 @@ export default async function pointToCesium(
319
320
  positions,
320
321
  vectorProperties,
321
322
  scene,
323
+ style,
322
324
  )) ??
323
325
  (await getPrimitiveOptions(
324
326
  feature,