@vcmap/core 5.0.0-rc.22 → 5.0.0-rc.24

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 (59) hide show
  1. package/index.d.ts +631 -98
  2. package/index.js +24 -9
  3. package/package.json +2 -2
  4. package/src/category/category.js +1 -1
  5. package/src/featureProvider/abstractFeatureProvider.js +1 -18
  6. package/src/featureProvider/wmsFeatureProvider.js +1 -1
  7. package/src/interaction/eventHandler.js +14 -0
  8. package/src/layer/cesium/clusterContext.js +12 -0
  9. package/src/layer/cesium/vectorCesiumImpl.js +2 -2
  10. package/src/layer/cesium/vectorContext.js +115 -7
  11. package/src/layer/cesiumTilesetLayer.js +0 -14
  12. package/src/layer/czmlLayer.js +1 -1
  13. package/src/layer/dataSourceLayer.js +1 -53
  14. package/src/layer/featureLayer.js +0 -44
  15. package/src/layer/featureStoreLayer.js +0 -15
  16. package/src/layer/layer.js +0 -11
  17. package/src/layer/vectorHelpers.js +0 -85
  18. package/src/layer/vectorLayer.js +0 -9
  19. package/src/layer/vectorProperties.js +150 -8
  20. package/src/layer/vectorTileLayer.js +0 -9
  21. package/src/layer/wmsHelpers.js +2 -0
  22. package/src/map/baseOLMap.js +12 -6
  23. package/src/map/cesiumMap.js +48 -38
  24. package/src/map/openlayersMap.js +6 -5
  25. package/src/map/vcsMap.js +22 -0
  26. package/src/style/arcStyle.js +316 -0
  27. package/src/style/arrowStyle.js +269 -0
  28. package/src/util/editor/createFeatureSession.js +3 -1
  29. package/src/util/editor/editFeaturesSession.js +315 -0
  30. package/src/util/editor/editGeometrySession.js +5 -1
  31. package/src/util/editor/editorHelpers.js +118 -14
  32. package/src/util/editor/editorSessionHelpers.js +12 -0
  33. package/src/util/editor/editorSymbols.js +6 -0
  34. package/src/util/editor/interactions/editFeaturesMouseOverInteraction.js +120 -0
  35. package/src/util/editor/interactions/editGeometryMouseOverInteraction.js +1 -3
  36. package/src/util/editor/interactions/ensureHandlerSelectionInteraction.js +48 -0
  37. package/src/util/editor/interactions/mapInteractionController.js +5 -2
  38. package/src/util/editor/interactions/selectMultiFeatureInteraction.js +146 -0
  39. package/src/util/editor/interactions/translateVertexInteraction.js +2 -2
  40. package/src/util/editor/transformation/create2DHandlers.js +294 -0
  41. package/src/util/editor/transformation/create3DHandlers.js +575 -0
  42. package/src/util/editor/transformation/extrudeInteraction.js +91 -0
  43. package/src/util/editor/transformation/rotateInteraction.js +188 -0
  44. package/src/util/editor/transformation/scaleInteraction.js +185 -0
  45. package/src/util/editor/transformation/transformationHandler.js +168 -0
  46. package/src/util/editor/transformation/transformationTypes.js +83 -0
  47. package/src/util/editor/transformation/translateInteraction.js +209 -0
  48. package/src/util/featureconverter/arcToCesium.js +87 -0
  49. package/src/util/featureconverter/convert.js +7 -1
  50. package/src/util/featureconverter/extent3D.js +64 -1
  51. package/src/util/featureconverter/lineStringToCesium.js +103 -2
  52. package/src/util/featureconverter/pointHelpers.js +341 -0
  53. package/src/util/featureconverter/pointToCesium.js +27 -76
  54. package/src/util/geometryHelpers.js +11 -8
  55. package/src/util/mapCollection.js +25 -0
  56. package/src/util/math.js +99 -2
  57. package/tests/unit/helpers/cesiumHelpers.js +17 -5
  58. package/tests/unit/helpers/helpers.js +13 -0
  59. package/src/featureProvider/featureProviderHelpers.js +0 -50
package/index.js CHANGED
@@ -13,7 +13,6 @@ export { default as CategoryCollection } from './src/category/categoryCollection
13
13
  export { layerClassRegistry, tileProviderClassRegistry, featureProviderClassRegistry, mapClassRegistry, styleClassRegistry, categoryClassRegistry, getObjectFromClassRegistry, default as ClassRegistry } from './src/classRegistry.js';
14
14
  export { volatileContextId, markVolatile, default as Context } from './src/context.js';
15
15
  export { default as AbstractFeatureProvider } from './src/featureProvider/abstractFeatureProvider.js';
16
- export { getGenericFeatureFromProvidedFeature } from './src/featureProvider/featureProviderHelpers.js';
17
16
  export { isProvidedFeature, showProvidedFeature } from './src/featureProvider/featureProviderSymbols.js';
18
17
  export { default as TileProviderFeatureProvider } from './src/featureProvider/tileProviderFeatureProvider.js';
19
18
  export { getFormat, default as WMSFeatureProvider } from './src/featureProvider/wmsFeatureProvider.js';
@@ -33,7 +32,7 @@ export { default as SingleImageCesiumImpl } from './src/layer/cesium/singleImage
33
32
  export { default as TerrainCesiumImpl } from './src/layer/cesium/terrainCesiumImpl.js';
34
33
  export { default as TmsCesiumImpl } from './src/layer/cesium/tmsCesiumImpl.js';
35
34
  export { default as VectorCesiumImpl } from './src/layer/cesium/vectorCesiumImpl.js';
36
- export { setReferenceForPicking, removeArrayFromCollection, removeFeatureFromMap, addPrimitiveToContext, default as VectorContext } from './src/layer/cesium/vectorContext.js';
35
+ export { setReferenceForPicking, removeArrayFromCollection, removeFeatureFromMap, addPrimitiveToContext, setupScalingPrimitiveCollection, default as VectorContext } from './src/layer/cesium/vectorContext.js';
37
36
  export { default as VectorRasterTileCesiumImpl } from './src/layer/cesium/vectorRasterTileCesiumImpl.js';
38
37
  export { toContext, getCanvasFromFeatures, default as VectorTileImageryProvider } from './src/layer/cesium/vectorTileImageryProvider.js';
39
38
  export { default as WmsCesiumImpl } from './src/layer/cesium/wmsCesiumImpl.js';
@@ -79,9 +78,9 @@ export { default as StaticGeoJSONTileProvider } from './src/layer/tileProvider/s
79
78
  export { mercatorResolutionsToLevel, rectangleToExtent, default as TileProvider } from './src/layer/tileProvider/tileProvider.js';
80
79
  export { getURL, default as URLTemplateTileProvider } from './src/layer/tileProvider/urlTemplateTileProvider.js';
81
80
  export { default as TMSLayer } from './src/layer/tmsLayer.js';
82
- export { fvLastUpdated, globalHiderLastUpdated, updateFeatureVisibility, updateGlobalHider, synchronizeFeatureVisibilityWithSource, getGenericFeatureFromClickedObject } from './src/layer/vectorHelpers.js';
81
+ export { fvLastUpdated, globalHiderLastUpdated, updateFeatureVisibility, updateGlobalHider, synchronizeFeatureVisibilityWithSource } from './src/layer/vectorHelpers.js';
83
82
  export { default as VectorLayer } from './src/layer/vectorLayer.js';
84
- export { AltitudeModeCesium, ClassificationTypeCesium, parseNearFarScalar, parseCartesian3, parseStoreyHeights, getAltitudeModeOptions, getClassificationTypeOptions, getNearFarValueOptions, getCartesian3Options, default as VectorProperties } from './src/layer/vectorProperties.js';
83
+ export { PrimitiveOptionsType, AltitudeModeCesium, ClassificationTypeCesium, parseNearFarScalar, parseCartesian3, parseStoreyHeights, getAltitudeModeOptions, getClassificationTypeOptions, getNearFarValueOptions, getCartesian3Options, default as VectorProperties } from './src/layer/vectorProperties.js';
85
84
  export { alreadyTransformedToMercator, alreadyTransformedToImage, obliqueGeometry, doNotTransform, originalFeatureSymbol, actuallyIsCircle, createSync } from './src/layer/vectorSymbols.js';
86
85
  export { default as VectorTileLayer } from './src/layer/vectorTileLayer.js';
87
86
  export { default as WFSLayer } from './src/layer/wfsLayer.js';
@@ -106,6 +105,8 @@ export { default as ObliqueView } from './src/oblique/obliqueView.js';
106
105
  export { ObliqueViewDirection, obliqueViewDirectionNames, getDirectionName } from './src/oblique/obliqueViewDirection.js';
107
106
  export { getVersionFromImageJson, parseImageMeta, parseImageData, parseLegacyImageData } from './src/oblique/parseImageJson.js';
108
107
  export { default as OverrideClassRegistry } from './src/overrideClassRegistry.js';
108
+ export { featureArcStruct, default as ArcStyle } from './src/style/arcStyle.js';
109
+ export { ArrowEnd, default as ArrowStyle } from './src/style/arrowStyle.js';
109
110
  export { defaultDeclarativeStyle, default as DeclarativeStyleItem } from './src/style/declarativeStyleItem.js';
110
111
  export { getShapeFromOptions, shapeCategory } from './src/style/shapesCategory.js';
111
112
  export { getStyleOrDefaultStyle } from './src/style/styleFactory.js';
@@ -118,30 +119,44 @@ export { default as ClippingObjectManager } from './src/util/clipping/clippingOb
118
119
  export { createClippingPlaneCollection, copyClippingPlanesToCollection, clearClippingPlanes, setClippingPlanes, createClippingFeature, getClippingOptions } from './src/util/clipping/clippingPlaneHelper.js';
119
120
  export { default as Collection } from './src/util/collection.js';
120
121
  export { default as startCreateFeatureSession } from './src/util/editor/createFeatureSession.js';
122
+ export { default as startEditFeaturesSession } from './src/util/editor/editFeaturesSession.js';
121
123
  export { default as startEditGeometrySession } from './src/util/editor/editGeometrySession.js';
122
- export { createVertex, pointOnLine3D, pointOnLine2D, createVerticalPlane, createHorizontalPlane } from './src/util/editor/editorHelpers.js';
124
+ export { createVertex, getClosestPointOn2DLine, pointOnLine3D, pointOnLine2D, createCameraVerticalPlane, createHorizontalPlane, getCartographicFromPlane, drapeGeometryOnTerrain, placeGeometryOnTerrain, ensureFeatureAbsolute, clampFeature } from './src/util/editor/editorHelpers.js';
123
125
  export { SessionType, setupScratchLayer, GeometryType } from './src/util/editor/editorSessionHelpers.js';
124
- export { vertexSymbol, vertexIndex } from './src/util/editor/editorSymbols.js';
126
+ export { vertexSymbol, vertexIndex, handlerSymbol } from './src/util/editor/editorSymbols.js';
125
127
  export { default as CreateBBoxInteraction } from './src/util/editor/interactions/createBBoxInteraction.js';
126
128
  export { default as CreateCircleInteraction } from './src/util/editor/interactions/createCircleInteraction.js';
127
129
  export { default as CreateLineStringInteraction } from './src/util/editor/interactions/createLineStringInteraction.js';
128
130
  export { default as CreatePointInteraction } from './src/util/editor/interactions/createPointInteraction.js';
129
131
  export { default as CreatePolygonInteraction } from './src/util/editor/interactions/createPolygonInteraction.js';
132
+ export { default as EditFeaturesMouseOverInteraction } from './src/util/editor/interactions/editFeaturesMouseOverInteraction.js';
130
133
  export { cursorMap, default as EditGeometryMouseOverInteraction } from './src/util/editor/interactions/editGeometryMouseOverInteraction.js';
134
+ export { default as EnsureHandlerSelectionInteraction } from './src/util/editor/interactions/ensureHandlerSelectionInteraction.js';
131
135
  export { default as InsertVertexInteraction } from './src/util/editor/interactions/insertVertexInteraction.js';
132
136
  export { default as MapInteractionController } from './src/util/editor/interactions/mapInteractionController.js';
133
137
  export { default as RemoveVertexInteraction } from './src/util/editor/interactions/removeVertexInteraction.js';
138
+ export { default as SelectMultiFeatureInteraction } from './src/util/editor/interactions/selectMultiFeatureInteraction.js';
134
139
  export { default as SelectSingleFeatureInteraction } from './src/util/editor/interactions/selectSingleFeatureInteraction.js';
135
140
  export { default as TranslateVertexInteraction } from './src/util/editor/interactions/translateVertexInteraction.js';
141
+ export { default as create2DHandlers } from './src/util/editor/transformation/create2DHandlers.js';
142
+ export { default as create3DHandlers } from './src/util/editor/transformation/create3DHandlers.js';
143
+ export { default as ExtrudeInteraction } from './src/util/editor/transformation/extrudeInteraction.js';
144
+ export { default as RotateInteraction } from './src/util/editor/transformation/rotateInteraction.js';
145
+ export { default as ScaleInteraction } from './src/util/editor/transformation/scaleInteraction.js';
146
+ export { default as createTransformationHandler } from './src/util/editor/transformation/transformationHandler.js';
147
+ export { AXIS_AND_PLANES, TransformationMode, greyedOutColor, is1DAxis, is2DAxis } from './src/util/editor/transformation/transformationTypes.js';
148
+ export { default as TranslateInteraction } from './src/util/editor/transformation/translateInteraction.js';
136
149
  export { default as geometryIsValid } from './src/util/editor/validateGeoemetry.js';
137
150
  export { default as ExclusiveManager } from './src/util/exclusiveManager.js';
138
151
  export { default as Extent } from './src/util/extent.js';
152
+ export { default as arcToCesium } from './src/util/featureconverter/arcToCesium.js';
139
153
  export { validateCircle, default as circleToCesium } from './src/util/featureconverter/circleToCesium.js';
140
154
  export { getStylesArray, default as convert } from './src/util/featureconverter/convert.js';
141
155
  export { default as Extent3D } from './src/util/featureconverter/extent3D.js';
142
156
  export { getMaterialAppearance, createClassificationPrimitive, createPrimitive, createOutlinePrimitive, createLinePrimitive, getMinHeightOrGroundLevel, getStoreyHeights, validateStoreys, getHeightAboveGround, getHeightInfo, getStoreyOptions, addPrimitivesToContext } from './src/util/featureconverter/featureconverterHelper.js';
143
- export { validateLineString, default as lineStringToCesium } from './src/util/featureconverter/lineStringToCesium.js';
144
- export { getBillboardOptions, getLabelOptions, getModelOptions, validatePoint, getCartesian3AndWGS84FromCoordinates, default as pointToCesium } from './src/util/featureconverter/pointToCesium.js';
157
+ export { addArrowsToContext, validateLineString, default as lineStringToCesium } from './src/util/featureconverter/lineStringToCesium.js';
158
+ export { getModelOptions, getPrimitiveOptions } from './src/util/featureconverter/pointHelpers.js';
159
+ export { getBillboardOptions, getLabelOptions, validatePoint, getCartesian3AndWGS84FromCoordinates, default as pointToCesium } from './src/util/featureconverter/pointToCesium.js';
145
160
  export { validatePolygon, default as polygonToCesium } from './src/util/featureconverter/polygonToCesium.js';
146
161
  export { requestUrl, requestJson, requestArrayBuffer } from './src/util/fetch.js';
147
162
  export { getFlatCoordinatesFromSimpleGeometry, getFlatCoordinatesFromGeometry, circleFromCenterRadius, convertGeometryToPolygon, enforceEndingVertex, removeEndingVertex, removeEndingVertexFromGeometry, enforceRightHand } from './src/util/geometryHelpers.js';
@@ -150,7 +165,7 @@ export { isMobile } from './src/util/isMobile.js';
150
165
  export { maxZIndex, default as LayerCollection } from './src/util/layerCollection.js';
151
166
  export { detectBrowserLocale } from './src/util/locale.js';
152
167
  export { default as MapCollection } from './src/util/mapCollection.js';
153
- export { coordinateAtDistance, initialBearingBetweenCoords, cartesian2DDistance, cartesian3DDistance, modulo } from './src/util/math.js';
168
+ export { coordinateAtDistance, initialBearingBetweenCoords, getCartesianBearing, cartesian2DDistance, cartesian3DDistance, modulo, cartographicToWgs84, mercatorToCartesian, cartesianToMercator, getMidPoint, getCartesianPitch } from './src/util/math.js';
154
169
  export { isOverrideCollection, default as makeOverrideCollection } from './src/util/overrideCollection.js';
155
170
  export { wgs84ToMercatorTransformer, mercatorToWgs84Transformer, setDefaultProjectionOptions, getDefaultProjection, wgs84Projection, mercatorProjection, default as Projection } from './src/util/projection.js';
156
171
  export { default as SplitScreen } from './src/util/splitScreen.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vcmap/core",
3
- "version": "5.0.0-rc.22",
3
+ "version": "5.0.0-rc.24",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -53,7 +53,7 @@
53
53
  "sinon": "^9.2.4",
54
54
  "sinon-chai": "^3.6.0",
55
55
  "tui-jsdoc-template": "^1.2.2",
56
- "typescript": "^4.6.2"
56
+ "typescript": "^4.9.3"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "@vcmap/cesium": "~1.97.1",
@@ -364,7 +364,7 @@ class Category extends VcsObject {
364
364
  /**
365
365
  * @protected
366
366
  * @param {T} item
367
- * @returns {Array<Object>}
367
+ * @returns {Object}
368
368
  */
369
369
  _serializeItem(item) {
370
370
  const config = JSON.parse(JSON.stringify(item));
@@ -14,7 +14,6 @@ import { isProvidedFeature, showProvidedFeature } from './featureProviderSymbols
14
14
  /**
15
15
  * @typedef {VcsObjectOptions} AbstractFeatureProviderOptions
16
16
  * @property {import("@vcmap/core").StyleItemOptions|import("@vcmap/core").StyleItem|undefined} style - the style to apply to features created by this feature provider
17
- * @property {Object|undefined} genericFeatureProperties - generic properties to add to features created by this feature provider
18
17
  * @property {import("@vcmap/core").VectorProperties|import("@vcmap/core").VectorPropertiesOptions|undefined} vectorProperties - the vector properties of the features. Allow picking is false by default.
19
18
  * @property {boolean} [showGeometry=false] - show the resulting geometry in the map
20
19
  * @property {Array<string>} [mapTypes=[]] - can be used to constrict the featureProvider to specific mapTypes empty array means no restriction
@@ -38,7 +37,6 @@ class AbstractFeatureProvider extends VcsObject {
38
37
  vectorProperties: {
39
38
  allowPicking: false,
40
39
  },
41
- genericFeatureProperties: undefined,
42
40
  showGeometry: false,
43
41
  mapTypes: [],
44
42
  };
@@ -79,13 +77,6 @@ class AbstractFeatureProvider extends VcsObject {
79
77
  this.vectorProperties = options.vectorProperties instanceof VectorProperties ?
80
78
  options.vectorProperties :
81
79
  new VectorProperties({ ...defaultOptions.vectorProperties, ...options.vectorProperties });
82
- /**
83
- * An object of potential generic feature properties to add to all feature created by this provider
84
- * @type {Object<string, *>|undefined}
85
- * @api
86
- */
87
- this.genericFeatureProperties = options.genericFeatureProperties || defaultOptions.genericFeatureProperties;
88
-
89
80
  /**
90
81
  * Map ClassNames Can be used to only apply this featureProvider to the specified maps
91
82
  * @type {Array<string>}
@@ -106,7 +97,7 @@ class AbstractFeatureProvider extends VcsObject {
106
97
  }
107
98
 
108
99
  /**
109
- * Ensures the feature has an ID, applies all vectorProperties and adds the generic properties, style and the vcsLayerName
100
+ * Ensures the feature has an ID, applies all vectorProperties and adds style and the vcsLayerName
110
101
  * and isProvidedFeature symbols to the feature
111
102
  * @param {import("ol").Feature<import("ol/geom/Geometry").default>} feature
112
103
  * @returns {import("ol").Feature<import("ol/geom/Geometry").default>}
@@ -119,9 +110,6 @@ class AbstractFeatureProvider extends VcsObject {
119
110
  if (this.style) {
120
111
  feature.setStyle(this.style.style);
121
112
  }
122
- if (this.genericFeatureProperties) {
123
- feature.setProperties(this.genericFeatureProperties);
124
- }
125
113
  feature[vcsLayerName] = this.layerName;
126
114
  feature[isProvidedFeature] = true;
127
115
  feature[showProvidedFeature] = this.showGeometry;
@@ -164,10 +152,6 @@ class AbstractFeatureProvider extends VcsObject {
164
152
  config.showGeometry = this.showGeometry;
165
153
  }
166
154
 
167
- if (this.genericFeatureProperties) {
168
- config.genericFeatureProperties = { ...this.genericFeatureProperties };
169
- }
170
-
171
155
  if (this.style) {
172
156
  config.style = this.style.toJSON();
173
157
  }
@@ -187,7 +171,6 @@ class AbstractFeatureProvider extends VcsObject {
187
171
  destroy() {
188
172
  this.style = null;
189
173
  this.vectorProperties.destroy();
190
- this.genericFeatureProperties = undefined;
191
174
  super.destroy();
192
175
  }
193
176
  }
@@ -61,7 +61,7 @@ export function getFormat(responseType, options = {}) {
61
61
  if (responseType === 'application/vnd.ogc.gml') {
62
62
  return new GML2(options);
63
63
  }
64
- if (responseType === 'application/vnd.ogc.gml/3.1.1') {
64
+ if (responseType === 'application/vnd.ogc.gml/3.1.1' || responseType === 'text/xml; subtype=gml/3.1.1') {
65
65
  return new GML3(options);
66
66
  }
67
67
  return null;
@@ -167,6 +167,12 @@ class EventHandler {
167
167
  this._boundKeyListener = this._keyListener.bind(this);
168
168
  window.addEventListener('keydown', this._boundKeyListener);
169
169
  window.addEventListener('keyup', this._boundKeyListener);
170
+
171
+ /**
172
+ * @type {VcsEvent<ModificationKeyType>}
173
+ * @private
174
+ */
175
+ this._modifierChanged = new VcsEvent();
170
176
  }
171
177
 
172
178
  /**
@@ -198,6 +204,13 @@ class EventHandler {
198
204
  */
199
205
  get interactions() { return this._interactionChain.chain.slice(); }
200
206
 
207
+ /**
208
+ * An event called, when the modifier changes. Order of precedence, if more then one key is pressed: SHIFT, ALT, CTRL
209
+ * @type {VcsEvent<ModificationKeyType>}
210
+ * @readonly
211
+ */
212
+ get modifierChanged() { return this._modifierChanged; }
213
+
201
214
  /**
202
215
  * Add a dynamic interaction to the interaction chain. This is the default methodology for
203
216
  * user map interactions, such as drawing or measuring. If another exclusive interaction is added,
@@ -417,6 +430,7 @@ class EventHandler {
417
430
  if (modifier !== this._lastDispatchedModifier) {
418
431
  this._interactionChain.modifierChanged(modifier);
419
432
  this._lastDispatchedModifier = modifier;
433
+ this._modifierChanged.raiseEvent(modifier);
420
434
  }
421
435
  }
422
436
  }
@@ -24,6 +24,14 @@ class ClusterContext {
24
24
  // eslint-disable-next-line class-methods-use-this,no-unused-vars
25
25
  addPrimitives(primitives, feature, allowPicking) {}
26
26
 
27
+ /**
28
+ * @param {Array<import("@vcmap/cesium").Primitive|import("@vcmap/cesium").GroundPrimitive|import("@vcmap/cesium").GroundPolylinePrimitive|import("@vcmap/cesium").ClassificationPrimitive|import("@vcmap/cesium").Model>} primitives
29
+ * @param {import("ol").Feature<import("ol/geom/Geometry").default>} feature
30
+ * @param {boolean=} allowPicking
31
+ */
32
+ // eslint-disable-next-line class-methods-use-this,no-unused-vars
33
+ addScaledPrimitives(primitives, feature, allowPicking) {}
34
+
27
35
  /**
28
36
  * @param {Array<Object>} billboardOptions
29
37
  * @param {import("ol").Feature<import("ol/geom/Geometry").default>} feature
@@ -90,6 +98,10 @@ class ClusterContext {
90
98
  this.featureToBillboardMap.clear();
91
99
  this.featureToLabelMap.clear();
92
100
  }
101
+
102
+ destroy() {
103
+ this.clear();
104
+ }
93
105
  }
94
106
 
95
107
  export default ClusterContext;
@@ -104,7 +104,7 @@ class VectorCesiumImpl extends LayerImplementation {
104
104
  */
105
105
  async _setupContext(cesiumMap) {
106
106
  const rootCollection = /** @type {import("@vcmap/cesium").PrimitiveCollection} */ (this._rootCollection);
107
- this._context = new VectorContext(this._scene, rootCollection);
107
+ this._context = new VectorContext(cesiumMap, rootCollection);
108
108
  cesiumMap.addPrimitiveCollection(rootCollection);
109
109
  }
110
110
 
@@ -230,7 +230,7 @@ class VectorCesiumImpl extends LayerImplementation {
230
230
  */
231
231
  destroy() {
232
232
  if (this.initialized) {
233
- this._context.clear();
233
+ this._context.destroy();
234
234
  this._destroyCollection();
235
235
  }
236
236
  this._context = null;
@@ -1,8 +1,17 @@
1
- import { PrimitiveCollection, BillboardCollection, LabelCollection } from '@vcmap/cesium';
1
+ import {
2
+ PrimitiveCollection,
3
+ BillboardCollection,
4
+ LabelCollection,
5
+ Matrix4,
6
+ Cartesian3,
7
+ Math as CesiumMath,
8
+ } from '@vcmap/cesium';
9
+ import Viewpoint from '../../util/viewpoint.js';
2
10
 
3
11
  /**
4
12
  * @typedef {Object} VectorContextFeatureCache
5
13
  * @property {Array<import("@vcmap/cesium").Primitive|import("@vcmap/cesium").GroundPrimitive|import("@vcmap/cesium").GroundPolylinePrimitive|import("@vcmap/cesium").ClassificationPrimitive|import("@vcmap/cesium").Model>|undefined} primitives
14
+ * @property {Array<import("@vcmap/cesium").Primitive|import("@vcmap/cesium").GroundPrimitive|import("@vcmap/cesium").GroundPolylinePrimitive|import("@vcmap/cesium").ClassificationPrimitive|import("@vcmap/cesium").Model>|undefined} scaledPrimitives
6
15
  * @property {Array<import("@vcmap/cesium").Billboard|import("@vcmap/cesium").Entity>|undefined} billboards
7
16
  * @property {Array<import("@vcmap/cesium").Label|import("@vcmap/cesium").Entity>|undefined} labels
8
17
  */
@@ -31,10 +40,11 @@ export function removeArrayFromCollection(collection, array) {
31
40
  * @param {import("ol").Feature<import("ol/geom/Geometry").default>} feature
32
41
  * @param {Map<import("ol").Feature<import("ol/geom/Geometry").default>, Array<import("@vcmap/cesium").Primitive|import("@vcmap/cesium").GroundPrimitive|import("@vcmap/cesium").GroundPolylinePrimitive|import("@vcmap/cesium").ClassificationPrimitive|import("@vcmap/cesium").Billboard|import("@vcmap/cesium").Label|import("@vcmap/cesium").Entity|import("@vcmap/cesium").Model>>} featuresMap
33
42
  * @param {import("@vcmap/cesium").PrimitiveCollection|import("@vcmap/cesium").BillboardCollection|import("@vcmap/cesium").LabelCollection|import("@vcmap/cesium").EntityCollection} primitiveCollection
43
+ * @returns {boolean} - if a feature was removed from the map
34
44
  */
35
45
  export function removeFeatureFromMap(feature, featuresMap, primitiveCollection) {
36
46
  removeArrayFromCollection(primitiveCollection, featuresMap.get(feature));
37
- featuresMap.delete(feature);
47
+ return featuresMap.delete(feature);
38
48
  }
39
49
 
40
50
  /**
@@ -61,31 +71,94 @@ export function addPrimitiveToContext(primitives, feature, allowPicking, primiti
61
71
  }
62
72
  }
63
73
 
74
+ /**
75
+ * Symbol used in self scaling
76
+ * @type {symbol}
77
+ */
78
+ const scaleSymbol = Symbol('Scale');
79
+ /**
80
+ * self scaling scratch
81
+ * @type {import("@vcmap/cesium").Cartesian3}
82
+ */
83
+ const scratchCenter = new Cartesian3();
84
+
85
+ /**
86
+ * Creates a self scaling primitive collection. It will scale a primitive of model in the collection
87
+ * in such a fashion, that the cartesian unit of 1 equals 1 pixel.
88
+ * @param {import("@vcmap/core").CesiumMap} map
89
+ * @param {import("@vcmap/cesium").PrimitiveCollection} primitiveCollection
90
+ * @param {{value: boolean}}dirtyRef
91
+ * @returns {function():void}
92
+ */
93
+ export function setupScalingPrimitiveCollection(map, primitiveCollection, dirtyRef) {
94
+ let cachedVP = new Viewpoint({});
95
+ return map.getScene().postRender.addEventListener(() => {
96
+ const { length } = primitiveCollection;
97
+ if (length === 0) {
98
+ return;
99
+ }
100
+
101
+ const vp = map.getViewpointSync();
102
+ if (!dirtyRef.value && cachedVP.equals(vp, CesiumMath.EPSILON5)) {
103
+ return;
104
+ }
105
+
106
+ for (let i = 0; i < length; i++) {
107
+ const primitive = primitiveCollection.get(i);
108
+ if (!primitive.isDestroyed()) {
109
+ const { modelMatrix } = primitive;
110
+ const center = Matrix4.getTranslation(modelMatrix, scratchCenter);
111
+ const res = map.getCurrentResolutionFromCartesian(center);
112
+ if (primitive[scaleSymbol] !== res) {
113
+ primitive.modelMatrix = Matrix4.setScale(modelMatrix, new Cartesian3(res, res, res), new Matrix4());
114
+ primitive[scaleSymbol] = res;
115
+ }
116
+ }
117
+ }
118
+ dirtyRef.value = false;
119
+ cachedVP = vp;
120
+ });
121
+ }
122
+
64
123
  /**
65
124
  * @class
66
125
  */
67
126
  class VectorContext {
68
127
  /**
69
- * @param {import("@vcmap/cesium").Scene} scene
128
+ * @param {import("@vcmap/core").CesiumMap} map
70
129
  * @param {import("@vcmap/cesium").PrimitiveCollection} rootCollection
71
130
  */
72
- constructor(scene, rootCollection) {
131
+ constructor(map, rootCollection) {
132
+ const scene = map.getScene();
73
133
  /** @type {import("@vcmap/cesium").PrimitiveCollection} */
74
134
  this.primitives = new PrimitiveCollection();
135
+ /** @type {import("@vcmap/cesium").PrimitiveCollection} */
136
+ this.scaledPrimitives = new PrimitiveCollection();
75
137
  /** @type {import("@vcmap/cesium").BillboardCollection} */
76
138
  this.billboards = new BillboardCollection({ scene });
77
139
  /** @type {import("@vcmap/cesium").LabelCollection} */
78
140
  this.labels = new LabelCollection({ scene });
79
141
  /** @type {Map<import("ol").Feature<import("ol/geom/Geometry").default>, Array<import("@vcmap/cesium").Primitive|import("@vcmap/cesium").GroundPrimitive|import("@vcmap/cesium").GroundPolylinePrimitive|import("@vcmap/cesium").ClassificationPrimitive|import("@vcmap/cesium").Model>>} */
80
142
  this.featureToPrimitiveMap = new Map();
143
+ /** @type {Map<import("ol").Feature<import("ol/geom/Geometry").default>, Array<import("@vcmap/cesium").Primitive|import("@vcmap/cesium").GroundPrimitive|import("@vcmap/cesium").GroundPolylinePrimitive|import("@vcmap/cesium").ClassificationPrimitive|import("@vcmap/cesium").Model>>} */
144
+ this.featureToScaledPrimitiveMap = new Map();
81
145
  /** @type {Map<import("ol").Feature<import("ol/geom/Geometry").default>, Array<import("@vcmap/cesium").Billboard>>} */
82
146
  this.featureToBillboardMap = new Map();
83
147
  /** @type {Map<import("ol").Feature<import("ol/geom/Geometry").default>, Array<import("@vcmap/cesium").Label>>} */
84
148
  this.featureToLabelMap = new Map();
85
149
 
86
- rootCollection.add(this.primitives);
87
- rootCollection.add(this.billboards);
88
- rootCollection.add(this.labels);
150
+ /**
151
+ * @type {import("@vcmap/cesium").PrimitiveCollection}
152
+ * @private
153
+ */
154
+ this._rootCollection = rootCollection;
155
+ this._rootCollection.add(this.primitives);
156
+ this._rootCollection.add(this.scaledPrimitives);
157
+ this._rootCollection.add(this.billboards);
158
+ this._rootCollection.add(this.labels);
159
+
160
+ this._scaledDirty = { value: true };
161
+ this._postRenderListener = setupScalingPrimitiveCollection(map, this.scaledPrimitives, this._scaledDirty);
89
162
  }
90
163
 
91
164
  /**
@@ -97,6 +170,16 @@ class VectorContext {
97
170
  addPrimitiveToContext(primitives, feature, allowPicking, this.primitives, this.featureToPrimitiveMap);
98
171
  }
99
172
 
173
+ /**
174
+ * @param {Array<import("@vcmap/cesium").Primitive|import("@vcmap/cesium").GroundPrimitive|import("@vcmap/cesium").GroundPolylinePrimitive|import("@vcmap/cesium").ClassificationPrimitive|import("@vcmap/cesium").Model>} primitives
175
+ * @param {import("ol").Feature<import("ol/geom/Geometry").default>} feature
176
+ * @param {boolean=} allowPicking
177
+ */
178
+ addScaledPrimitives(primitives, feature, allowPicking) {
179
+ addPrimitiveToContext(primitives, feature, allowPicking, this.scaledPrimitives, this.featureToScaledPrimitiveMap);
180
+ this._scaledDirty.value = true;
181
+ }
182
+
100
183
  /**
101
184
  * @param {Array<Object>} billboardOptions
102
185
  * @param {import("ol").Feature<import("ol/geom/Geometry").default>} feature
@@ -120,6 +203,7 @@ class VectorContext {
120
203
  */
121
204
  removeFeature(feature) {
122
205
  removeFeatureFromMap(feature, this.featureToPrimitiveMap, this.primitives);
206
+ this._scaledDirty.value = removeFeatureFromMap(feature, this.featureToScaledPrimitiveMap, this.scaledPrimitives);
123
207
  removeFeatureFromMap(feature, this.featureToBillboardMap, this.billboards);
124
208
  removeFeatureFromMap(feature, this.featureToLabelMap, this.labels);
125
209
  }
@@ -134,6 +218,8 @@ class VectorContext {
134
218
  const cache = {};
135
219
  cache.primitives = this.featureToPrimitiveMap.get(feature);
136
220
  this.featureToPrimitiveMap.delete(feature);
221
+ cache.scaledPrimitives = this.featureToScaledPrimitiveMap.get(feature);
222
+ this.featureToScaledPrimitiveMap.delete(feature);
137
223
  cache.billboards = this.featureToBillboardMap.get(feature);
138
224
  this.featureToBillboardMap.delete(feature);
139
225
  cache.labels = this.featureToLabelMap.get(feature);
@@ -146,6 +232,7 @@ class VectorContext {
146
232
  */
147
233
  clearFeatureCache(cache) {
148
234
  removeArrayFromCollection(this.primitives, cache.primitives);
235
+ removeArrayFromCollection(this.scaledPrimitives, cache.scaledPrimitives);
149
236
  removeArrayFromCollection(this.billboards, cache.billboards);
150
237
  removeArrayFromCollection(this.labels, cache.labels);
151
238
  }
@@ -156,11 +243,32 @@ class VectorContext {
156
243
  */
157
244
  clear() {
158
245
  this.primitives.removeAll();
246
+ this.scaledPrimitives.removeAll();
159
247
  this.billboards.removeAll();
160
248
  this.labels.removeAll();
161
249
  this.featureToBillboardMap.clear();
162
250
  this.featureToLabelMap.clear();
163
251
  this.featureToPrimitiveMap.clear();
252
+ this._scaledDirty.value = this.featureToScaledPrimitiveMap.size > 0;
253
+ this.featureToScaledPrimitiveMap.clear();
254
+ }
255
+
256
+ /**
257
+ * Destroys this context and all its resources
258
+ */
259
+ destroy() {
260
+ if (this._rootCollection) {
261
+ this._rootCollection.remove(this.primitives);
262
+ this._rootCollection.remove(this.scaledPrimitives);
263
+ this._rootCollection.remove(this.billboards);
264
+ this._rootCollection.remove(this.labels);
265
+ }
266
+ this._rootCollection = null;
267
+ this.featureToBillboardMap.clear();
268
+ this.featureToLabelMap.clear();
269
+ this.featureToPrimitiveMap.clear();
270
+ this.featureToScaledPrimitiveMap.clear();
271
+ this._postRenderListener();
164
272
  }
165
273
  }
166
274
 
@@ -276,20 +276,6 @@ class CesiumTilesetLayer extends FeatureLayer {
276
276
  return null;
277
277
  }
278
278
 
279
- // TODO type params
280
- getGenericFeatureFromClickedObject(object) {
281
- const attributes = { ...this.genericFeatureProperties, ...object.attributes || object };
282
- return {
283
- layerName: this.name,
284
- layerClass: this.className,
285
- attributes,
286
- longitude: object.clickedPosition.longitude,
287
- latitude: object.clickedPosition.latitude,
288
- height: object.clickedPosition.height + this.balloonHeightOffset,
289
- relativeToGround: false,
290
- };
291
- }
292
-
293
279
  /**
294
280
  * set the maximum screenspace error of this layer
295
281
  * @param {number} value
@@ -5,7 +5,7 @@ import { vcsLayerName } from './layerSymbols.js';
5
5
  import { layerClassRegistry } from '../classRegistry.js';
6
6
 
7
7
  /**
8
- * @typedef {DataSourceOptions} CzmlOptions
8
+ * @typedef {LayerOptions} CzmlOptions
9
9
  * @property {string|undefined} sourceUri
10
10
  * @api
11
11
  */
@@ -6,12 +6,6 @@ import { vcsLayerName } from './layerSymbols.js';
6
6
  import FeatureVisibility, { FeatureVisibilityAction } from './featureVisibility.js';
7
7
  import { layerClassRegistry } from '../classRegistry.js';
8
8
 
9
- /**
10
- * @typedef {LayerOptions} DataSourceOptions
11
- * @property {Object|undefined} genericFeatureProperties
12
- * @api
13
- */
14
-
15
9
  /**
16
10
  * @typedef {Object} DataSourcePickedObject
17
11
  * @property {import("@vcmap/cesium").Entity} id
@@ -36,21 +30,10 @@ class DataSourceLayer extends Layer {
36
30
  static get className() { return 'DataSourceLayer'; }
37
31
 
38
32
  /**
39
- * @returns {DataSourceOptions}
40
- */
41
- static getDefaultOptions() {
42
- return {
43
- ...Layer.getDefaultOptions(),
44
- genericFeatureProperties: {},
45
- };
46
- }
47
-
48
- /**
49
- * @param {DataSourceOptions} options
33
+ * @param {LayerOptions} options
50
34
  */
51
35
  constructor(options) {
52
36
  super(options);
53
- const defaultOptions = DataSourceLayer.getDefaultOptions();
54
37
  /**
55
38
  * The entities of this layer. Use the `addEntity` API to add Enitities to ensure interoperability with vcm interfaces
56
39
  * @type {import("@vcmap/cesium").EntityCollection}
@@ -61,12 +44,6 @@ class DataSourceLayer extends Layer {
61
44
  * @type {import("@vcmap/cesium").DataSourceClock|undefined}
62
45
  */
63
46
  this.clock = undefined;
64
- /**
65
- * @type {Object}
66
- * @private
67
- */
68
- this._genericFeatureProperties = options.genericFeatureProperties || defaultOptions.genericFeatureProperties;
69
-
70
47
  /**
71
48
  * The feature visibility of this layer. NOTE: Entities cannot be highlighted at this moment.
72
49
  * @type {FeatureVisibility}
@@ -223,35 +200,6 @@ class DataSourceLayer extends Layer {
223
200
  return null;
224
201
  }
225
202
 
226
- /**
227
- * @param {DataSourcePickedObject} object
228
- * @returns {GenericFeature}
229
- */
230
- getGenericFeatureFromClickedObject(object) {
231
- const attributes = { ...this._genericFeatureProperties, ...object.attributes || {} };
232
- return {
233
- layerName: this.name,
234
- layerClass: this.className,
235
- attributes,
236
- longitude: object.clickedPosition.longitude,
237
- latitude: object.clickedPosition.latitude,
238
- height: object.clickedPosition.height,
239
- relativeToGround: false,
240
- };
241
- }
242
-
243
- /**
244
- * @inheritDoc
245
- * @returns {DataSourceOptions}
246
- */
247
- toJSON() {
248
- const config = /** @type {DataSourceOptions} */ (super.toJSON());
249
- if (Object.keys(this._genericFeatureProperties).length > 0) {
250
- config.genericFeatureProperties = { ...this._genericFeatureProperties };
251
- }
252
- return config;
253
- }
254
-
255
203
  /**
256
204
  * @inheritDoc
257
205
  */