@vcmap/core 5.0.0-rc.3 → 5.0.0-rc.31
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/LICENSE.md +1 -1
- package/README.md +12 -5
- package/build/postinstall.js +14 -3
- package/index.d.ts +3480 -2008
- package/index.js +169 -131
- package/package.json +25 -27
- package/src/category/category.js +483 -0
- package/src/category/categoryCollection.js +153 -0
- package/src/cesium/cesium3DTileFeature.js +2 -2
- package/src/cesium/cesium3DTilePointFeature.js +1 -1
- package/src/cesium/cesiumVcsCameraPrimitive.js +16 -8
- package/src/cesium/entity.js +29 -0
- package/src/cesium/wallpaperMaterial.js +5 -3
- package/src/classRegistry.js +169 -0
- package/src/{vcs/vcm/util/featureProvider → featureProvider}/abstractFeatureProvider.js +49 -46
- package/src/{vcs/vcm/util/featureProvider → featureProvider}/tileProviderFeatureProvider.js +13 -5
- package/src/{vcs/vcm/util/featureProvider → featureProvider}/wmsFeatureProvider.js +56 -26
- package/src/{vcs/vcm/interaction → interaction}/abstractInteraction.js +33 -21
- package/src/{vcs/vcm/interaction → interaction}/coordinateAtPixel.js +40 -21
- package/src/{vcs/vcm/interaction → interaction}/eventHandler.js +131 -26
- package/src/{vcs/vcm/interaction → interaction}/featureAtPixelInteraction.js +108 -53
- package/src/interaction/featureProviderInteraction.js +58 -0
- package/src/{vcs/vcm/interaction → interaction}/interactionChain.js +40 -41
- package/src/{vcs/vcm/interaction → interaction}/interactionType.js +24 -31
- package/src/{vcs/vcm/layer/cesium/cesiumTilesetCesium.js → layer/cesium/cesiumTilesetCesiumImpl.js} +83 -70
- package/src/{vcs/vcm/layer → layer}/cesium/clusterContext.js +33 -8
- package/src/{vcs/vcm/layer/cesium/dataSourceCesium.js → layer/cesium/dataSourceCesiumImpl.js} +24 -13
- package/src/layer/cesium/openStreetMapCesiumImpl.js +32 -0
- package/src/{vcs/vcm/layer/cesium/rasterLayerCesium.js → layer/cesium/rasterLayerCesiumImpl.js} +12 -9
- package/src/{vcs/vcm/layer/cesium/singleImageCesium.js → layer/cesium/singleImageCesiumImpl.js} +19 -9
- package/src/{vcs/vcm/layer/cesium/terrainCesium.js → layer/cesium/terrainCesiumImpl.js} +8 -9
- package/src/{vcs/vcm/layer/cesium/tmsCesium.js → layer/cesium/tmsCesiumImpl.js} +21 -10
- package/src/{vcs/vcm/layer/cesium/vectorCesium.js → layer/cesium/vectorCesiumImpl.js} +93 -35
- package/src/layer/cesium/vectorContext.js +363 -0
- package/src/{vcs/vcm/layer/cesium/vectorRasterTileCesium.js → layer/cesium/vectorRasterTileCesiumImpl.js} +21 -13
- package/src/{vcs/vcm/layer → layer}/cesium/vectorTileImageryProvider.js +58 -21
- package/src/{vcs/vcm/layer/cesium/wmsCesium.js → layer/cesium/wmsCesiumImpl.js} +20 -9
- package/src/{vcs/vcm/layer/cesium/wmtsCesium.js → layer/cesium/wmtsCesiumImpl.js} +24 -13
- package/src/{vcs/vcm/layer → layer}/cesium/x3dmHelper.js +6 -3
- package/src/{vcs/vcm/layer/cesiumTileset.js → layer/cesiumTilesetLayer.js} +71 -112
- package/src/{vcs/vcm/layer/czml.js → layer/czmlLayer.js} +23 -20
- package/src/{vcs/vcm/layer/dataSource.js → layer/dataSourceLayer.js} +55 -90
- package/src/{vcs/vcm/layer → layer}/featureLayer.js +89 -74
- package/src/{vcs/vcm/layer/featureStore.js → layer/featureStoreLayer.js} +197 -150
- package/src/{vcs/vcm/layer/featureStoreChanges.js → layer/featureStoreLayerChanges.js} +150 -92
- package/src/{vcs/vcm/layer/featureStoreState.js → layer/featureStoreLayerState.js} +1 -2
- package/src/{vcs/vcm/layer → layer}/featureVisibility.js +114 -82
- package/src/{vcs/vcm/layer → layer}/geojsonHelpers.js +84 -69
- package/src/{vcs/vcm/layer/geojson.js → layer/geojsonLayer.js} +30 -27
- package/src/{vcs/vcm/layer → layer}/globalHider.js +25 -39
- package/src/{vcs/vcm/layer → layer}/layer.js +171 -96
- package/src/{vcs/vcm/layer → layer}/layerImplementation.js +13 -6
- package/src/{vcs/vcm/layer → layer}/layerState.js +0 -1
- package/src/{vcs/vcm/layer → layer}/layerSymbols.js +2 -1
- package/src/{vcs/vcm/layer/oblique/layerOblique.js → layer/oblique/layerObliqueImpl.js} +7 -5
- package/src/{vcs/vcm/layer → layer}/oblique/obliqueHelpers.js +76 -31
- package/src/{vcs/vcm/layer/oblique/vectorOblique.js → layer/oblique/vectorObliqueImpl.js} +198 -80
- package/src/{vcs/vcm/layer/openStreetMap.js → layer/openStreetMapLayer.js} +59 -40
- package/src/layer/openlayers/layerOpenlayersImpl.js +165 -0
- package/src/layer/openlayers/openStreetMapOpenlayersImpl.js +28 -0
- package/src/layer/openlayers/rasterLayerOpenlayersImpl.js +44 -0
- package/src/{vcs/vcm/layer/openlayers/singleImageOpenlayers.js → layer/openlayers/singleImageOpenlayersImpl.js} +8 -7
- package/src/{vcs/vcm/layer/openlayers/tileDebugOpenlayers.js → layer/openlayers/tileDebugOpenlayersImpl.js} +7 -6
- package/src/{vcs/vcm/layer/openlayers/tmsOpenlayers.js → layer/openlayers/tmsOpenlayersImpl.js} +12 -10
- package/src/{vcs/vcm/layer/openlayers/vectorOpenlayers.js → layer/openlayers/vectorOpenlayersImpl.js} +21 -12
- package/src/{vcs/vcm/layer/openlayers/vectorTileOpenlayers.js → layer/openlayers/vectorTileOpenlayersImpl.js} +18 -12
- package/src/{vcs/vcm/layer/openlayers/wmsOpenlayers.js → layer/openlayers/wmsOpenlayersImpl.js} +9 -8
- package/src/{vcs/vcm/layer/openlayers/wmtsOpenlayers.js → layer/openlayers/wmtsOpenlayersImpl.js} +19 -12
- package/src/{vcs/vcm/layer/pointCloud.js → layer/pointCloudLayer.js} +42 -39
- package/src/{vcs/vcm/layer → layer}/rasterLayer.js +86 -37
- package/src/{vcs/vcm/layer/singleImage.js → layer/singleImageLayer.js} +25 -22
- package/src/layer/terrainHelpers.js +95 -0
- package/src/{vcs/vcm/layer/terrain.js → layer/terrainLayer.js} +28 -21
- package/src/{vcs/vcm/layer → layer}/tileLoadedHelper.js +13 -8
- package/src/{vcs/vcm/layer → layer}/tileProvider/mvtTileProvider.js +51 -8
- package/src/layer/tileProvider/staticGeojsonTileProvider.js +87 -0
- package/src/{vcs/vcm/layer → layer}/tileProvider/tileProvider.js +200 -89
- package/src/{vcs/vcm/layer → layer}/tileProvider/urlTemplateTileProvider.js +54 -13
- package/src/{vcs/vcm/layer/tms.js → layer/tmsLayer.js} +22 -22
- package/src/layer/vectorHelpers.js +129 -0
- package/src/{vcs/vcm/layer/vector.js → layer/vectorLayer.js} +124 -94
- package/src/{vcs/vcm/layer → layer}/vectorProperties.js +419 -107
- package/src/{vcs/vcm/layer → layer}/vectorSymbols.js +11 -1
- package/src/{vcs/vcm/layer/vectorTile.js → layer/vectorTileLayer.js} +181 -116
- package/src/{vcs/vcm/layer/wfs.js → layer/wfsLayer.js} +33 -23
- package/src/{vcs/vcm/layer → layer}/wmsHelpers.js +14 -7
- package/src/{vcs/vcm/layer/wms.js → layer/wmsLayer.js} +53 -32
- package/src/{vcs/vcm/layer/wmts.js → layer/wmtsLayer.js} +56 -42
- package/src/{vcs/vcm/maps → map}/baseOLMap.js +83 -35
- package/src/{vcs/vcm/maps → map}/cameraLimiter.js +64 -37
- package/src/{vcs/vcm/maps/cesium.js → map/cesiumMap.js} +431 -277
- package/src/{vcs/vcm/maps → map}/mapState.js +0 -1
- package/src/{vcs/vcm/maps/oblique.js → map/obliqueMap.js} +132 -97
- package/src/{vcs/vcm/maps/openlayers.js → map/openlayersMap.js} +69 -45
- package/src/{vcs/vcm/maps/map.js → map/vcsMap.js} +118 -46
- package/src/oblique/defaultObliqueCollection.js +62 -0
- package/src/{vcs/vcm/oblique → oblique}/helpers.js +221 -78
- package/src/{vcs/vcm/oblique/ObliqueCollection.js → oblique/obliqueCollection.js} +151 -55
- package/src/{vcs/vcm/oblique/ObliqueDataSet.js → oblique/obliqueDataSet.js} +77 -46
- package/src/{vcs/vcm/oblique/ObliqueImage.js → oblique/obliqueImage.js} +58 -26
- package/src/{vcs/vcm/oblique/ObliqueImageMeta.js → oblique/obliqueImageMeta.js} +9 -9
- package/src/{vcs/vcm/oblique/ObliqueProvider.js → oblique/obliqueProvider.js} +85 -35
- package/src/{vcs/vcm/oblique/ObliqueView.js → oblique/obliqueView.js} +45 -5
- package/src/{vcs/vcm/oblique/ObliqueViewDirection.js → oblique/obliqueViewDirection.js} +3 -5
- package/src/{vcs/vcm/oblique → oblique}/parseImageJson.js +62 -28
- package/src/ol/feature.js +34 -1
- package/src/ol/geom/circle.js +14 -5
- package/src/ol/geom/geometryCollection.js +14 -8
- package/src/ol/render/canvas/canvasTileRenderer.js +11 -10
- package/src/overrideClassRegistry.js +214 -0
- package/src/style/arcStyle.js +453 -0
- package/src/style/arrowStyle.js +304 -0
- package/src/{vcs/vcm/util/style → style}/declarativeStyleItem.js +147 -82
- package/src/{vcs/vcm/util/style → style}/shapesCategory.js +8 -8
- package/src/style/styleFactory.js +32 -0
- package/src/{vcs/vcm/util/style → style}/styleHelpers.js +24 -26
- package/src/style/styleItem.js +174 -0
- package/src/{vcs/vcm/util/style → style}/vectorStyleItem.js +230 -156
- package/src/{vcs/vcm/util/style → style}/writeStyle.js +7 -12
- package/src/{vcs/vcm/util → util}/clipping/clippingObject.js +79 -49
- package/src/{vcs/vcm/util → util}/clipping/clippingObjectManager.js +56 -23
- package/src/{vcs/vcm/util → util}/clipping/clippingPlaneHelper.js +149 -88
- package/src/{vcs/vcm/util → util}/collection.js +28 -10
- package/src/util/editor/createFeatureSession.js +195 -0
- package/src/util/editor/editFeaturesSession.js +325 -0
- package/src/util/editor/editGeometrySession.js +452 -0
- package/src/util/editor/editorHelpers.js +300 -0
- package/src/util/editor/editorSessionHelpers.js +132 -0
- package/src/util/editor/editorSymbols.js +21 -0
- package/src/util/editor/interactions/createBBoxInteraction.js +154 -0
- package/src/util/editor/interactions/createCircleInteraction.js +119 -0
- package/src/util/editor/interactions/createLineStringInteraction.js +119 -0
- package/src/util/editor/interactions/createPointInteraction.js +73 -0
- package/src/util/editor/interactions/createPolygonInteraction.js +136 -0
- package/src/util/editor/interactions/editFeaturesMouseOverInteraction.js +88 -0
- package/src/util/editor/interactions/editGeometryMouseOverInteraction.js +119 -0
- package/src/util/editor/interactions/ensureHandlerSelectionInteraction.js +50 -0
- package/src/util/editor/interactions/insertVertexInteraction.js +103 -0
- package/src/util/editor/interactions/mapInteractionController.js +119 -0
- package/src/util/editor/interactions/removeVertexInteraction.js +42 -0
- package/src/util/editor/interactions/selectFeatureMouseOverInteraction.js +152 -0
- package/src/util/editor/interactions/selectMultiFeatureInteraction.js +165 -0
- package/src/util/editor/interactions/selectSingleFeatureInteraction.js +120 -0
- package/src/util/editor/interactions/translateVertexInteraction.js +60 -0
- package/src/util/editor/selectFeaturesSession.js +303 -0
- package/src/util/editor/transformation/create2DHandlers.js +339 -0
- package/src/util/editor/transformation/create3DHandlers.js +678 -0
- package/src/util/editor/transformation/extrudeInteraction.js +106 -0
- package/src/util/editor/transformation/rotateInteraction.js +201 -0
- package/src/util/editor/transformation/scaleInteraction.js +201 -0
- package/src/util/editor/transformation/transformationHandler.js +178 -0
- package/src/util/editor/transformation/transformationTypes.js +88 -0
- package/src/util/editor/transformation/translateInteraction.js +263 -0
- package/src/util/editor/validateGeoemetry.js +24 -0
- package/src/{vcs/vcm/util → util}/exclusiveManager.js +6 -3
- package/src/{vcs/vcm/util → util}/extent.js +26 -20
- package/src/util/featureconverter/arcToCesium.js +121 -0
- package/src/{vcs/vcm/util → util}/featureconverter/circleToCesium.js +70 -37
- package/src/{vcs/vcm/util → util}/featureconverter/convert.js +94 -16
- package/src/util/featureconverter/extent3D.js +284 -0
- package/src/{vcs/vcm/util → util}/featureconverter/featureconverterHelper.js +253 -94
- package/src/util/featureconverter/lineStringToCesium.js +343 -0
- package/src/util/featureconverter/pointHelpers.js +413 -0
- package/src/{vcs/vcm/util → util}/featureconverter/pointToCesium.js +157 -107
- package/src/{vcs/vcm/util → util}/featureconverter/polygonToCesium.js +57 -24
- package/src/util/fetch.js +34 -0
- package/src/{vcs/vcm/util → util}/geometryHelpers.js +25 -17
- package/src/{vcs/vcm/util → util}/indexedCollection.js +27 -8
- package/src/{vcs/vcm/util → util}/isMobile.js +8 -2
- package/src/{vcs/vcm/util → util}/layerCollection.js +109 -19
- package/src/util/locale.js +12 -0
- package/src/{vcs/vcm/util → util}/mapCollection.js +170 -63
- package/src/util/math.js +193 -0
- package/src/util/overrideCollection.js +261 -0
- package/src/{vcs/vcm/util → util}/projection.js +23 -31
- package/src/{vcs/vcm/util → util}/urlHelpers.js +5 -3
- package/src/{vcs/vcm/util → util}/viewpoint.js +83 -57
- package/src/vcsApp.js +657 -0
- package/src/{vcs/vcm/event/vcsEvent.js → vcsEvent.js} +2 -3
- package/src/vcsModule.js +130 -0
- package/src/vcsModuleHelpers.js +136 -0
- package/src/{vcs/vcm/object.js → vcsObject.js} +3 -10
- package/tests/data/dynamicPointCzml.json +53 -0
- package/tests/data/oblique/imageData/imagev34.json +136 -0
- package/tests/data/oblique/imageData/imagev35.json +307 -0
- package/tests/data/oblique/imageData/imagev35PerImageSize.json +333 -0
- package/tests/data/oblique/tiledImageData/12/2199/1342.json +11056 -0
- package/tests/data/oblique/tiledImageData/12/2199/1343.json +11236 -0
- package/tests/data/oblique/tiledImageData/12/2199/1344.json +11077 -0
- package/tests/data/oblique/tiledImageData/12/2200/1342.json +11036 -0
- package/tests/data/oblique/tiledImageData/12/2200/1343.json +11277 -0
- package/tests/data/oblique/tiledImageData/12/2200/1344.json +11131 -0
- package/tests/data/oblique/tiledImageData/12/2201/1342.json +10870 -0
- package/tests/data/oblique/tiledImageData/12/2201/1343.json +11492 -0
- package/tests/data/oblique/tiledImageData/12/2201/1344.json +10909 -0
- package/tests/data/oblique/tiledImageData/image.json +70 -0
- package/tests/data/terrain/13/8800/6485.terrain +0 -0
- package/tests/data/terrain/13/8800/6486.terrain +0 -0
- package/tests/data/terrain/13/8801/6485.terrain +0 -0
- package/tests/data/terrain/13/8801/6486.terrain +0 -0
- package/tests/data/terrain/layer.json +127 -0
- package/tests/data/testGeoJSON.json +149 -0
- package/tests/data/tile.pbf +0 -0
- package/tests/unit/helpers/cesiumHelpers.js +326 -0
- package/tests/unit/helpers/getFileNameFromUrl.js +12 -0
- package/tests/unit/helpers/helpers.js +32 -0
- package/tests/unit/helpers/imageHelpers.js +24 -0
- package/tests/unit/helpers/importJSON.js +15 -0
- package/tests/unit/helpers/obliqueData.js +102 -0
- package/tests/unit/helpers/obliqueHelpers.js +115 -0
- package/tests/unit/helpers/openlayersHelpers.js +25 -0
- package/tests/unit/helpers/terrain/terrainData.js +45 -0
- package/src/vcs/vcm/classRegistry.js +0 -106
- package/src/vcs/vcm/globalCollections.js +0 -11
- package/src/vcs/vcm/interaction/featureProviderInteraction.js +0 -54
- package/src/vcs/vcm/layer/buildings.js +0 -17
- package/src/vcs/vcm/layer/cesium/openStreetMapCesium.js +0 -29
- package/src/vcs/vcm/layer/cesium/pointCloudCesium.js +0 -58
- package/src/vcs/vcm/layer/cesium/vectorContext.js +0 -167
- package/src/vcs/vcm/layer/openlayers/layerOpenlayers.js +0 -79
- package/src/vcs/vcm/layer/openlayers/openStreetMapOpenlayers.js +0 -27
- package/src/vcs/vcm/layer/openlayers/rasterLayerOpenlayers.js +0 -121
- package/src/vcs/vcm/layer/terrainHelpers.js +0 -119
- package/src/vcs/vcm/layer/tileProvider/staticGeojsonTileProvider.js +0 -67
- package/src/vcs/vcm/layer/tileProvider/tileProviderFactory.js +0 -28
- package/src/vcs/vcm/layer/vectorHelpers.js +0 -206
- package/src/vcs/vcm/util/dateTime.js +0 -60
- package/src/vcs/vcm/util/featureProvider/featureProviderHelpers.js +0 -51
- package/src/vcs/vcm/util/featureconverter/extent3d.js +0 -154
- package/src/vcs/vcm/util/featureconverter/lineStringToCesium.js +0 -171
- package/src/vcs/vcm/util/locale.js +0 -53
- package/src/vcs/vcm/util/math.js +0 -71
- package/src/vcs/vcm/util/splitScreen.js +0 -233
- package/src/vcs/vcm/util/style/styleFactory.js +0 -48
- package/src/vcs/vcm/util/style/styleItem.js +0 -243
- /package/src/{vcs/vcm/util/featureProvider → featureProvider}/featureProviderSymbols.js +0 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { LinearRing } from 'ol/geom.js';
|
|
2
|
+
import AbstractInteraction from '../../../interaction/abstractInteraction.js';
|
|
3
|
+
import {
|
|
4
|
+
EventType,
|
|
5
|
+
ModificationKeyType,
|
|
6
|
+
} from '../../../interaction/interactionType.js';
|
|
7
|
+
import { cartesian2DDistance } from '../../math.js';
|
|
8
|
+
import {
|
|
9
|
+
createVertex,
|
|
10
|
+
pointOnLine2D,
|
|
11
|
+
pointOnLine3D,
|
|
12
|
+
} from '../editorHelpers.js';
|
|
13
|
+
import VcsEvent from '../../../vcsEvent.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {Object} VertexInsertedEvent
|
|
17
|
+
* @property {import("@vcmap/core").Vertex} vertex
|
|
18
|
+
* @property {number} index
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @class
|
|
23
|
+
* @extends {AbstractInteraction}
|
|
24
|
+
*/
|
|
25
|
+
class InsertVertexInteraction extends AbstractInteraction {
|
|
26
|
+
/**
|
|
27
|
+
* @param {import("ol").Feature<import("ol/geom").LineString|import("ol/geom").Polygon>} feature
|
|
28
|
+
* @param {import("ol/geom").LineString|import("ol/geom").LinearRing} geometry
|
|
29
|
+
*/
|
|
30
|
+
constructor(feature, geometry) {
|
|
31
|
+
super(EventType.CLICK, ModificationKeyType.NONE);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @type {import("@vcmap/core").VcsEvent<VertexInsertedEvent>}
|
|
35
|
+
*/
|
|
36
|
+
this.vertexInserted = new VcsEvent();
|
|
37
|
+
/**
|
|
38
|
+
* @type {import("ol").Feature<import("ol/geom").LineString|import("ol/geom").Polygon>}
|
|
39
|
+
* @private
|
|
40
|
+
*/
|
|
41
|
+
this._feature = feature;
|
|
42
|
+
/**
|
|
43
|
+
* @type {import("ol/geom").LineString|import("ol/geom").LinearRing}
|
|
44
|
+
* @private
|
|
45
|
+
*/
|
|
46
|
+
this._geometry = geometry;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @type {boolean}
|
|
50
|
+
* @private
|
|
51
|
+
*/
|
|
52
|
+
this._isLinearRing = this._geometry instanceof LinearRing;
|
|
53
|
+
this.setActive();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @inheritDoc
|
|
58
|
+
* @param {InteractionEvent} event
|
|
59
|
+
* @returns {Promise<InteractionEvent>}
|
|
60
|
+
*/
|
|
61
|
+
async pipe(event) {
|
|
62
|
+
if (event.feature === this._feature) {
|
|
63
|
+
const lineCoords = this._geometry.getCoordinates();
|
|
64
|
+
const coordinate = event.positionOrPixel;
|
|
65
|
+
const closestCoord = this._geometry.getClosestPoint(coordinate);
|
|
66
|
+
|
|
67
|
+
if (this._isLinearRing) {
|
|
68
|
+
lineCoords.push(lineCoords[0]);
|
|
69
|
+
}
|
|
70
|
+
const distance = cartesian2DDistance(closestCoord, coordinate); // todo respect altitude mode here. e.g. distance3D
|
|
71
|
+
if (distance < event.map.getCurrentResolution(coordinate) * 5) {
|
|
72
|
+
const length = lineCoords.length - 1;
|
|
73
|
+
let i = 0;
|
|
74
|
+
for (i; i < length; i++) {
|
|
75
|
+
const onLine =
|
|
76
|
+
this._feature.get('olcs_altitudeMode') === 'clampToGround' // todo altitude mode
|
|
77
|
+
? pointOnLine2D(lineCoords[i], lineCoords[i + 1], closestCoord)
|
|
78
|
+
: pointOnLine3D(lineCoords[i], lineCoords[i + 1], closestCoord);
|
|
79
|
+
if (onLine) {
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let index = i + 1;
|
|
85
|
+
if (this._isLinearRing && index === lineCoords.length) {
|
|
86
|
+
index = 0;
|
|
87
|
+
}
|
|
88
|
+
this.vertexInserted.raiseEvent({
|
|
89
|
+
vertex: createVertex(closestCoord),
|
|
90
|
+
index,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return event;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
destroy() {
|
|
98
|
+
this.vertexInserted.destroy();
|
|
99
|
+
super.destroy();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export default InsertVertexInteraction;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import DragPan from 'ol/interaction/DragPan.js';
|
|
2
|
+
import {
|
|
3
|
+
EventType,
|
|
4
|
+
ModificationKeyType,
|
|
5
|
+
} from '../../../interaction/interactionType.js';
|
|
6
|
+
import { handlerSymbol, vertexSymbol } from '../editorSymbols.js';
|
|
7
|
+
import AbstractInteraction from '../../../interaction/abstractInteraction.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {import("@vcmap/core").BaseOLMap} map
|
|
11
|
+
* @returns {function():void}
|
|
12
|
+
*/
|
|
13
|
+
function suspendOpenlayerMap(map) {
|
|
14
|
+
const dragPan = /** @type {import("ol/interaction").DragPan} */ (
|
|
15
|
+
map.olMap
|
|
16
|
+
.getInteractions()
|
|
17
|
+
.getArray()
|
|
18
|
+
.find((i) => i instanceof DragPan)
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
if (dragPan) {
|
|
22
|
+
dragPan.setActive(false);
|
|
23
|
+
return () => {
|
|
24
|
+
dragPan.setActive(true);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return () => {};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {import("@vcmap/core").CesiumMap} map
|
|
32
|
+
* @returns {function():void}
|
|
33
|
+
*/
|
|
34
|
+
function suspendCesiumMap(map) {
|
|
35
|
+
function getOriginalEventTypes(types) {
|
|
36
|
+
if (Array.isArray(types)) {
|
|
37
|
+
return types.slice();
|
|
38
|
+
} else if (typeof types === 'object') {
|
|
39
|
+
return { ...types };
|
|
40
|
+
}
|
|
41
|
+
return types;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const originalScreenSpaceEvents = {};
|
|
45
|
+
const { screenSpaceCameraController } = map.getScene();
|
|
46
|
+
['lookEventTypes', 'tiltEventTypes', 'rotateEventTypes'].forEach(
|
|
47
|
+
(eventTypes) => {
|
|
48
|
+
if (screenSpaceCameraController != null) {
|
|
49
|
+
originalScreenSpaceEvents[eventTypes] = getOriginalEventTypes(
|
|
50
|
+
screenSpaceCameraController[eventTypes],
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
);
|
|
55
|
+
screenSpaceCameraController.lookEventTypes = undefined;
|
|
56
|
+
screenSpaceCameraController.tiltEventTypes = undefined;
|
|
57
|
+
screenSpaceCameraController.rotateEventTypes = undefined;
|
|
58
|
+
|
|
59
|
+
return () => {
|
|
60
|
+
screenSpaceCameraController.lookEventTypes =
|
|
61
|
+
originalScreenSpaceEvents.lookEventTypes;
|
|
62
|
+
screenSpaceCameraController.tiltEventTypes =
|
|
63
|
+
originalScreenSpaceEvents.tiltEventTypes;
|
|
64
|
+
screenSpaceCameraController.rotateEventTypes =
|
|
65
|
+
originalScreenSpaceEvents.rotateEventTypes;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* An interaction to suppress map interactions when handling editor features (e.g. dragPan)
|
|
71
|
+
*/
|
|
72
|
+
class MapInteractionController extends AbstractInteraction {
|
|
73
|
+
constructor() {
|
|
74
|
+
super(EventType.MOVE, ModificationKeyType.ALL);
|
|
75
|
+
/**
|
|
76
|
+
* @type {function():void}
|
|
77
|
+
* @private
|
|
78
|
+
*/
|
|
79
|
+
this._clear = () => {};
|
|
80
|
+
|
|
81
|
+
this.setActive();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @inheritDoc
|
|
86
|
+
* @param {InteractionEvent} event
|
|
87
|
+
* @returns {Promise<InteractionEvent>}
|
|
88
|
+
*/
|
|
89
|
+
async pipe(event) {
|
|
90
|
+
this.reset();
|
|
91
|
+
if (
|
|
92
|
+
event.feature &&
|
|
93
|
+
(event.feature[vertexSymbol] || event.feature[handlerSymbol])
|
|
94
|
+
) {
|
|
95
|
+
if (event.map.className === 'CesiumMap') {
|
|
96
|
+
this._clear = suspendCesiumMap(
|
|
97
|
+
/** @type {import("@vcmap/core").CesiumMap} */ (event.map),
|
|
98
|
+
);
|
|
99
|
+
} else {
|
|
100
|
+
this._clear = suspendOpenlayerMap(
|
|
101
|
+
/** @type {import("@vcmap/core").OpenlayersMap|import("@vcmap/core").ObliqueMap} */ (
|
|
102
|
+
event.map
|
|
103
|
+
),
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return event;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Resets the event handlers for the currently suspended map
|
|
112
|
+
*/
|
|
113
|
+
reset() {
|
|
114
|
+
this._clear();
|
|
115
|
+
this._clear = () => {};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export default MapInteractionController;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import AbstractInteraction from '../../../interaction/abstractInteraction.js';
|
|
2
|
+
import {
|
|
3
|
+
EventType,
|
|
4
|
+
ModificationKeyType,
|
|
5
|
+
} from '../../../interaction/interactionType.js';
|
|
6
|
+
import { vertexSymbol } from '../editorSymbols.js';
|
|
7
|
+
import VcsEvent from '../../../vcsEvent.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* This interaction will raise the passed in event for each feature clicked with the vertex symbol
|
|
11
|
+
* @class
|
|
12
|
+
* @extends {AbstractInteraction}
|
|
13
|
+
*/
|
|
14
|
+
class RemoveVertexInteraction extends AbstractInteraction {
|
|
15
|
+
constructor() {
|
|
16
|
+
super(EventType.CLICK, ModificationKeyType.SHIFT);
|
|
17
|
+
/**
|
|
18
|
+
* @type {import("@vcmap/core").VcsEvent<Vertex>}
|
|
19
|
+
*/
|
|
20
|
+
this.vertexRemoved = new VcsEvent();
|
|
21
|
+
this.setActive();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @inheritDoc
|
|
26
|
+
* @param {InteractionEvent} event
|
|
27
|
+
* @returns {Promise<InteractionEvent>}
|
|
28
|
+
*/
|
|
29
|
+
async pipe(event) {
|
|
30
|
+
if (event.feature && event.feature[vertexSymbol]) {
|
|
31
|
+
this.vertexRemoved.raiseEvent(/** @type {Vertex} */ (event.feature));
|
|
32
|
+
}
|
|
33
|
+
return event;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
destroy() {
|
|
37
|
+
this.vertexRemoved.destroy();
|
|
38
|
+
super.destroy();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export default RemoveVertexInteraction;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import AbstractInteraction from '../../../interaction/abstractInteraction.js';
|
|
2
|
+
import {
|
|
3
|
+
EventType,
|
|
4
|
+
ModificationKeyType,
|
|
5
|
+
} from '../../../interaction/interactionType.js';
|
|
6
|
+
import SelectMultiFeatureInteraction from './selectMultiFeatureInteraction.js';
|
|
7
|
+
import SelectSingleFeatureInteraction from './selectSingleFeatureInteraction.js';
|
|
8
|
+
import { cursorMap } from './editGeometryMouseOverInteraction.js';
|
|
9
|
+
import { vcsLayerName } from '../../../layer/layerSymbols.js';
|
|
10
|
+
import { mouseOverSymbol } from '../editorSymbols.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Enumeration of editor selection modes.
|
|
14
|
+
* @enum {string}
|
|
15
|
+
* @property {string} SINGLE
|
|
16
|
+
* @property {string} MULTI
|
|
17
|
+
*/
|
|
18
|
+
export const SelectionMode = {
|
|
19
|
+
SINGLE: 'single',
|
|
20
|
+
MULTI: 'multi',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A class to handle mouse over effects on features for select sessions.
|
|
25
|
+
* @class
|
|
26
|
+
* @extends {AbstractInteraction}
|
|
27
|
+
*/
|
|
28
|
+
class SelectFeatureMouseOverInteraction extends AbstractInteraction {
|
|
29
|
+
/**
|
|
30
|
+
* @param {string} layerName Name of the layer for which the mouse over effect should accur.
|
|
31
|
+
* @param {SelectSingleFeatureInteraction | SelectMultiFeatureInteraction} selectFeatureInteraction The select feature interaction that handles the feature selection. Supports both, single and multi selection.
|
|
32
|
+
*/
|
|
33
|
+
constructor(layerName, selectFeatureInteraction) {
|
|
34
|
+
let modkeys;
|
|
35
|
+
let selectionMode;
|
|
36
|
+
if (selectFeatureInteraction instanceof SelectSingleFeatureInteraction) {
|
|
37
|
+
modkeys = ModificationKeyType.NONE;
|
|
38
|
+
selectionMode = SelectionMode.SINGLE;
|
|
39
|
+
} else if (
|
|
40
|
+
selectFeatureInteraction instanceof SelectMultiFeatureInteraction
|
|
41
|
+
) {
|
|
42
|
+
modkeys = ModificationKeyType.NONE | ModificationKeyType.CTRL;
|
|
43
|
+
selectionMode = SelectionMode.MULTI;
|
|
44
|
+
} else {
|
|
45
|
+
throw new Error('This interaction is not supported');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
super(EventType.MOVE, modkeys);
|
|
49
|
+
/** @type {SelectSingleFeatureInteraction | SelectMultiFeatureInteraction} */
|
|
50
|
+
this._selectFeatureInteraction = selectFeatureInteraction;
|
|
51
|
+
/** @type {SelectionMode} */
|
|
52
|
+
this.selectionMode = selectionMode;
|
|
53
|
+
/**
|
|
54
|
+
* The feature that is currently hovered and belongs to the layer with the layerName.
|
|
55
|
+
* @type {import("ol").Feature|import("@vcmap-cesium/engine").Cesium3DTileFeature|import("@vcmap-cesium/engine").Cesium3DTilePointFeature|null}
|
|
56
|
+
* @private
|
|
57
|
+
*/
|
|
58
|
+
this._currentFeature = null;
|
|
59
|
+
/**
|
|
60
|
+
* The layer name to react to
|
|
61
|
+
* @type {string}
|
|
62
|
+
*/
|
|
63
|
+
this.layerName = layerName;
|
|
64
|
+
/**
|
|
65
|
+
* @type {CSSStyleDeclaration}
|
|
66
|
+
* @private
|
|
67
|
+
*/
|
|
68
|
+
this.cursorStyle = document.body.style;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @inheritDoc
|
|
73
|
+
* @param {InteractionEvent} event
|
|
74
|
+
* @returns {Promise<InteractionEvent>}
|
|
75
|
+
*/
|
|
76
|
+
async pipe(event) {
|
|
77
|
+
if (event.feature && event.feature[vcsLayerName] === this.layerName) {
|
|
78
|
+
this._currentFeature =
|
|
79
|
+
/** @type {import("ol").Feature|import("@vcmap-cesium/engine").Cesium3DTileFeature|import("@vcmap-cesium/engine").Cesium3DTilePointFeature} */
|
|
80
|
+
(event.feature);
|
|
81
|
+
} else {
|
|
82
|
+
this._currentFeature = null;
|
|
83
|
+
}
|
|
84
|
+
this._evaluate(event.key);
|
|
85
|
+
return event;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @inheritDoc
|
|
90
|
+
* @param {ModificationKeyType} modifier
|
|
91
|
+
*/
|
|
92
|
+
modifierChanged(modifier) {
|
|
93
|
+
this._evaluate(modifier);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @inheritDoc
|
|
98
|
+
* @param {(boolean|number)=} active
|
|
99
|
+
*/
|
|
100
|
+
setActive(active) {
|
|
101
|
+
super.setActive(active);
|
|
102
|
+
this.reset();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Reset the cursorStyle to auto
|
|
107
|
+
*/
|
|
108
|
+
reset() {
|
|
109
|
+
if (this.cursorStyle && this.cursorStyle.cursor) {
|
|
110
|
+
this.cursorStyle.cursor = cursorMap.auto;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @param {ModificationKeyType} modifier
|
|
116
|
+
* @private
|
|
117
|
+
*/
|
|
118
|
+
_evaluate(modifier) {
|
|
119
|
+
if (this._currentFeature) {
|
|
120
|
+
const isCtrlPressed =
|
|
121
|
+
this.selectionMode === SelectionMode.MULTI &&
|
|
122
|
+
modifier & ModificationKeyType.CTRL;
|
|
123
|
+
const isSelected = this._selectFeatureInteraction.hasFeatureId(
|
|
124
|
+
this._currentFeature.getId(),
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
if (isCtrlPressed) {
|
|
128
|
+
this.cursorStyle.cursor = isSelected
|
|
129
|
+
? cursorMap.removeFromSelection
|
|
130
|
+
: cursorMap.addToSelection;
|
|
131
|
+
} else {
|
|
132
|
+
this.cursorStyle.cursor = cursorMap.select;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
this.cursorStyle[mouseOverSymbol] = this.id;
|
|
136
|
+
} else if (this.cursorStyle?.[mouseOverSymbol] === this.id) {
|
|
137
|
+
this.cursorStyle.cursor = cursorMap.auto;
|
|
138
|
+
delete this.cursorStyle[mouseOverSymbol];
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @inheritDoc
|
|
144
|
+
*/
|
|
145
|
+
destroy() {
|
|
146
|
+
this.reset();
|
|
147
|
+
this.cursorStyle = null;
|
|
148
|
+
super.destroy();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export default SelectFeatureMouseOverInteraction;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import AbstractInteraction from '../../../interaction/abstractInteraction.js';
|
|
2
|
+
import {
|
|
3
|
+
EventType,
|
|
4
|
+
ModificationKeyType,
|
|
5
|
+
} from '../../../interaction/interactionType.js';
|
|
6
|
+
import VcsEvent from '../../../vcsEvent.js';
|
|
7
|
+
import { vcsLayerName } from '../../../layer/layerSymbols.js';
|
|
8
|
+
import { isTiledFeature } from '../../../layer/featureStoreLayer.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Interaction to create a selection set from the given layer.
|
|
12
|
+
* Will use CTRL modifier key to add more features to the set.
|
|
13
|
+
* Clears the set if not clicking a feature
|
|
14
|
+
* Creates a new set when clicking a feature
|
|
15
|
+
* FeatureStore features will be converted to their dynamic state on selection.
|
|
16
|
+
* @class
|
|
17
|
+
* @extends {AbstractInteraction}
|
|
18
|
+
* @implements {SelectFeatureInteraction}
|
|
19
|
+
*/
|
|
20
|
+
class SelectMultiFeatureInteraction extends AbstractInteraction {
|
|
21
|
+
/**
|
|
22
|
+
* @param {import("@vcmap/core").VectorLayer} layer
|
|
23
|
+
*/
|
|
24
|
+
constructor(layer) {
|
|
25
|
+
super(EventType.CLICK, ModificationKeyType.NONE | ModificationKeyType.CTRL);
|
|
26
|
+
/**
|
|
27
|
+
* @type {import("@vcmap/core").VectorLayer|import("@vcmap/core").FeatureStoreLayer}
|
|
28
|
+
* @private
|
|
29
|
+
*/
|
|
30
|
+
this._layer = layer;
|
|
31
|
+
/**
|
|
32
|
+
* @type {Map<string|number, import("ol").Feature>}
|
|
33
|
+
* @private
|
|
34
|
+
*/
|
|
35
|
+
this._selectedFeatures = new Map();
|
|
36
|
+
/**
|
|
37
|
+
* @type {VcsEvent<Array<import("ol").Feature>>}
|
|
38
|
+
* @private
|
|
39
|
+
*/
|
|
40
|
+
this._featuresChanged = new VcsEvent();
|
|
41
|
+
this.setActive();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Event raised when the feature selection changes. Will be called with an array of features or an empty array, when no feature is selected
|
|
46
|
+
* @type {VcsEvent<Array<import("ol").Feature>>}
|
|
47
|
+
* @readonly
|
|
48
|
+
*/
|
|
49
|
+
get featuresChanged() {
|
|
50
|
+
return this._featuresChanged;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @returns {Array<import("ol").Feature>}
|
|
55
|
+
*/
|
|
56
|
+
get selected() {
|
|
57
|
+
return [...this._selectedFeatures.values()];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Checks if a feature with a spicific id is selected.
|
|
62
|
+
* @param {string | number} id
|
|
63
|
+
* @returns {boolean}
|
|
64
|
+
*/
|
|
65
|
+
hasFeatureId(id) {
|
|
66
|
+
return this._selectedFeatures.has(id);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @inheritDoc
|
|
71
|
+
* @param {InteractionEvent} event
|
|
72
|
+
* @returns {Promise<InteractionEvent>}
|
|
73
|
+
*/
|
|
74
|
+
async pipe(event) {
|
|
75
|
+
if (event.feature && event.feature[vcsLayerName] === this._layer.name) {
|
|
76
|
+
if (event.key & ModificationKeyType.CTRL) {
|
|
77
|
+
event.stopPropagation = true;
|
|
78
|
+
await this._modifySelectionSet(event.feature);
|
|
79
|
+
} else if (
|
|
80
|
+
!this._selectedFeatures.has(event.feature.getId()) ||
|
|
81
|
+
(this._selectedFeatures.has(event.feature.getId()) &&
|
|
82
|
+
this._selectedFeatures.size > 1)
|
|
83
|
+
) {
|
|
84
|
+
event.stopPropagation = true;
|
|
85
|
+
await this.setSelected([event.feature]);
|
|
86
|
+
}
|
|
87
|
+
} else if (!(event.key & ModificationKeyType.CTRL)) {
|
|
88
|
+
this.clear();
|
|
89
|
+
}
|
|
90
|
+
return event;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @param {Array<import("ol").Feature|import("@vcmap-cesium/engine").Cesium3DTileFeature|import("@vcmap-cesium/engine").Cesium3DTilePointFeature|import("@vcmap-cesium/engine").Entity> | import("ol").Feature|import("@vcmap-cesium/engine").Cesium3DTileFeature|import("@vcmap-cesium/engine").Cesium3DTilePointFeature|import("@vcmap-cesium/engine").Entity} features
|
|
95
|
+
* @returns {Promise<void>}
|
|
96
|
+
*/
|
|
97
|
+
async setSelected(features) {
|
|
98
|
+
this._selectedFeatures.clear();
|
|
99
|
+
const featureArray = Array.isArray(features) ? features : [features];
|
|
100
|
+
const olFeatures = await Promise.all(
|
|
101
|
+
featureArray.map((f) => {
|
|
102
|
+
if (f[isTiledFeature]) {
|
|
103
|
+
return /** @type {import("@vcmap/core").FeatureStoreLayer} */ (
|
|
104
|
+
this._layer
|
|
105
|
+
).switchStaticFeatureToDynamic(f.getId());
|
|
106
|
+
}
|
|
107
|
+
return f;
|
|
108
|
+
}),
|
|
109
|
+
);
|
|
110
|
+
olFeatures.forEach(
|
|
111
|
+
/** @param {import("ol").Feature} f */ (f) => {
|
|
112
|
+
this._selectedFeatures.set(f.getId(), f);
|
|
113
|
+
},
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
this._featuresChanged.raiseEvent(this.selected);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @param {import("ol").Feature|import("@vcmap-cesium/engine").Cesium3DTileFeature|import("@vcmap-cesium/engine").Cesium3DTilePointFeature|import("@vcmap-cesium/engine").Entity} feature
|
|
121
|
+
* @returns {Promise<void>}
|
|
122
|
+
* @private
|
|
123
|
+
*/
|
|
124
|
+
async _modifySelectionSet(feature) {
|
|
125
|
+
const id = feature.getId();
|
|
126
|
+
if (this._selectedFeatures.has(id)) {
|
|
127
|
+
this._selectedFeatures.delete(id);
|
|
128
|
+
} else {
|
|
129
|
+
let olFeature = feature;
|
|
130
|
+
if (feature[isTiledFeature]) {
|
|
131
|
+
olFeature =
|
|
132
|
+
await /** @type {import("@vcmap/core").FeatureStoreLayer} */ (
|
|
133
|
+
this._layer
|
|
134
|
+
).switchStaticFeatureToDynamic(id);
|
|
135
|
+
}
|
|
136
|
+
this._selectedFeatures.set(
|
|
137
|
+
id,
|
|
138
|
+
/** @type {import("ol").Feature} */ (olFeature),
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
this._featuresChanged.raiseEvent(this.selected);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Clears the interaction, removing all features and calling the featureChange event with an empty array
|
|
147
|
+
*/
|
|
148
|
+
clear() {
|
|
149
|
+
if (this._selectedFeatures.size > 0) {
|
|
150
|
+
this._selectedFeatures.clear();
|
|
151
|
+
this._featuresChanged.raiseEvent([]);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* @inheritDoc
|
|
157
|
+
*/
|
|
158
|
+
destroy() {
|
|
159
|
+
this._selectedFeatures.clear();
|
|
160
|
+
this._featuresChanged.destroy();
|
|
161
|
+
super.destroy();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export default SelectMultiFeatureInteraction;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import AbstractInteraction from '../../../interaction/abstractInteraction.js';
|
|
2
|
+
import {
|
|
3
|
+
EventType,
|
|
4
|
+
ModificationKeyType,
|
|
5
|
+
} from '../../../interaction/interactionType.js';
|
|
6
|
+
import VcsEvent from '../../../vcsEvent.js';
|
|
7
|
+
import { vcsLayerName } from '../../../layer/layerSymbols.js';
|
|
8
|
+
import { isTiledFeature } from '../../../layer/featureStoreLayer.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Class to select features for editing.
|
|
12
|
+
* Static FeatureStore features will be converted into their dynamic form
|
|
13
|
+
* @class
|
|
14
|
+
* @extends {AbstractInteraction}
|
|
15
|
+
* @implements {SelectFeatureInteraction}
|
|
16
|
+
*/
|
|
17
|
+
class SelectSingleFeatureInteraction extends AbstractInteraction {
|
|
18
|
+
/**
|
|
19
|
+
* @param {import("@vcmap/core").VectorLayer} layer
|
|
20
|
+
*/
|
|
21
|
+
constructor(layer) {
|
|
22
|
+
super(EventType.CLICK, ModificationKeyType.NONE);
|
|
23
|
+
/**
|
|
24
|
+
* @type {import("@vcmap/core").VectorLayer|import("@vcmap/core").FeatureStoreLayer}
|
|
25
|
+
* @private
|
|
26
|
+
*/
|
|
27
|
+
this._layer = layer;
|
|
28
|
+
/**
|
|
29
|
+
* @type {import("ol").Feature|null}
|
|
30
|
+
* @private
|
|
31
|
+
*/
|
|
32
|
+
this._selectedFeature = null;
|
|
33
|
+
/**
|
|
34
|
+
* Event called when the feature changes. Called with null if the selection is cleared.
|
|
35
|
+
* @type {VcsEvent<import("ol").Feature|null>}
|
|
36
|
+
*/
|
|
37
|
+
this.featureChanged = new VcsEvent();
|
|
38
|
+
this.setActive();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @returns {Array<import("ol").Feature>}
|
|
43
|
+
*/
|
|
44
|
+
get selected() {
|
|
45
|
+
return this._selectedFeature ? [this._selectedFeature] : [];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @inheritDoc
|
|
50
|
+
* @param {InteractionEvent} event
|
|
51
|
+
* @returns {Promise<InteractionEvent>}
|
|
52
|
+
*/
|
|
53
|
+
async pipe(event) {
|
|
54
|
+
if (event.feature && event.feature[vcsLayerName] === this._layer.name) {
|
|
55
|
+
if (
|
|
56
|
+
!(
|
|
57
|
+
this._selectedFeature &&
|
|
58
|
+
event.feature.getId() === this._selectedFeature.getId()
|
|
59
|
+
)
|
|
60
|
+
) {
|
|
61
|
+
event.stopPropagation = true;
|
|
62
|
+
await this.setSelected(
|
|
63
|
+
/** @type {import("ol").Feature|import("@vcmap-cesium/engine").Cesium3DTileFeature|import("@vcmap-cesium/engine").Cesium3DTilePointFeature} */
|
|
64
|
+
(event.feature),
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
this.clear();
|
|
69
|
+
}
|
|
70
|
+
return event;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Selects the given feature. if passed in a tiled feature store feature, it will be converted. Do not pass in uneditable features (feature which do not
|
|
75
|
+
* belong to the layer for which this interaction was created)
|
|
76
|
+
* @param {Array<import("ol").Feature|import("@vcmap-cesium/engine").Cesium3DTileFeature|import("@vcmap-cesium/engine").Cesium3DTilePointFeature|import("@vcmap-cesium/engine").Entity> | import("ol").Feature|import("@vcmap-cesium/engine").Cesium3DTileFeature|import("@vcmap-cesium/engine").Cesium3DTilePointFeature|import("@vcmap-cesium/engine").Entity} feature
|
|
77
|
+
* @returns {Promise<void>}
|
|
78
|
+
*/
|
|
79
|
+
async setSelected(feature) {
|
|
80
|
+
let olFeature = Array.isArray(feature) ? feature[0] : feature;
|
|
81
|
+
if (feature[isTiledFeature]) {
|
|
82
|
+
olFeature = await /** @type {import("@vcmap/core").FeatureStoreLayer} */ (
|
|
83
|
+
this._layer
|
|
84
|
+
).switchStaticFeatureToDynamic(olFeature.getId());
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
this._selectedFeature = /** @type {import("ol").Feature} */ (olFeature);
|
|
88
|
+
this.featureChanged.raiseEvent(this._selectedFeature);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Checks if a feature with a spicific id is selected.
|
|
93
|
+
* @param {string | number} id
|
|
94
|
+
* @returns {boolean}
|
|
95
|
+
*/
|
|
96
|
+
hasFeatureId(id) {
|
|
97
|
+
return this._selectedFeature?.getId() === id;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Clears the current selection, if there is one.
|
|
102
|
+
*/
|
|
103
|
+
clear() {
|
|
104
|
+
if (this._selectedFeature) {
|
|
105
|
+
this._selectedFeature = null;
|
|
106
|
+
this.featureChanged.raiseEvent(null);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @inheritDoc
|
|
112
|
+
*/
|
|
113
|
+
destroy() {
|
|
114
|
+
this._selectedFeature = null;
|
|
115
|
+
this.featureChanged.destroy();
|
|
116
|
+
super.destroy();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export default SelectSingleFeatureInteraction;
|