@vcmap/core 5.0.0-rc.0
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 +21 -0
- package/README.md +44 -0
- package/build/postinstall.js +44 -0
- package/index.js +139 -0
- package/package.json +92 -0
- package/src/cesium/cesium3DTileFeature.js +9 -0
- package/src/cesium/cesium3DTilePointFeature.js +9 -0
- package/src/cesium/cesiumVcsCameraPrimitive.js +146 -0
- package/src/cesium/wallpaperMaterial.js +64 -0
- package/src/ol/feature.js +47 -0
- package/src/ol/geom/circle.js +24 -0
- package/src/ol/geom/geometryCollection.js +33 -0
- package/src/ol/render/canvas/canvasTileRenderer.js +179 -0
- package/src/ol/source/ClusterEnhancedVectorSource.js +39 -0
- package/src/ol/source/VcsCluster.js +37 -0
- package/src/vcs/vcm/classRegistry.js +106 -0
- package/src/vcs/vcm/event/vcsEvent.js +89 -0
- package/src/vcs/vcm/globalCollections.js +11 -0
- package/src/vcs/vcm/interaction/abstractInteraction.js +149 -0
- package/src/vcs/vcm/interaction/coordinateAtPixel.js +102 -0
- package/src/vcs/vcm/interaction/eventHandler.js +425 -0
- package/src/vcs/vcm/interaction/featureAtPixelInteraction.js +286 -0
- package/src/vcs/vcm/interaction/featureProviderInteraction.js +54 -0
- package/src/vcs/vcm/interaction/interactionChain.js +124 -0
- package/src/vcs/vcm/interaction/interactionType.js +114 -0
- package/src/vcs/vcm/layer/buildings.js +17 -0
- package/src/vcs/vcm/layer/cesium/cesiumTilesetCesium.js +359 -0
- package/src/vcs/vcm/layer/cesium/clusterContext.js +95 -0
- package/src/vcs/vcm/layer/cesium/dataSourceCesium.js +171 -0
- package/src/vcs/vcm/layer/cesium/openStreetMapCesium.js +29 -0
- package/src/vcs/vcm/layer/cesium/pointCloudCesium.js +58 -0
- package/src/vcs/vcm/layer/cesium/rasterLayerCesium.js +110 -0
- package/src/vcs/vcm/layer/cesium/singleImageCesium.js +49 -0
- package/src/vcs/vcm/layer/cesium/terrainCesium.js +80 -0
- package/src/vcs/vcm/layer/cesium/tmsCesium.js +54 -0
- package/src/vcs/vcm/layer/cesium/vectorCesium.js +255 -0
- package/src/vcs/vcm/layer/cesium/vectorContext.js +167 -0
- package/src/vcs/vcm/layer/cesium/vectorRasterTileCesium.js +116 -0
- package/src/vcs/vcm/layer/cesium/vectorTileImageryProvider.js +246 -0
- package/src/vcs/vcm/layer/cesium/wmsCesium.js +71 -0
- package/src/vcs/vcm/layer/cesium/wmtsCesium.js +101 -0
- package/src/vcs/vcm/layer/cesium/x3dmHelper.js +22 -0
- package/src/vcs/vcm/layer/cesiumTileset.js +376 -0
- package/src/vcs/vcm/layer/czml.js +141 -0
- package/src/vcs/vcm/layer/dataSource.js +259 -0
- package/src/vcs/vcm/layer/featureLayer.js +261 -0
- package/src/vcs/vcm/layer/featureStore.js +647 -0
- package/src/vcs/vcm/layer/featureStoreChanges.js +360 -0
- package/src/vcs/vcm/layer/featureStoreState.js +19 -0
- package/src/vcs/vcm/layer/featureVisibility.js +435 -0
- package/src/vcs/vcm/layer/geojson.js +185 -0
- package/src/vcs/vcm/layer/geojsonHelpers.js +450 -0
- package/src/vcs/vcm/layer/globalHider.js +157 -0
- package/src/vcs/vcm/layer/layer.js +752 -0
- package/src/vcs/vcm/layer/layerImplementation.js +102 -0
- package/src/vcs/vcm/layer/layerState.js +17 -0
- package/src/vcs/vcm/layer/layerSymbols.js +6 -0
- package/src/vcs/vcm/layer/oblique/layerOblique.js +76 -0
- package/src/vcs/vcm/layer/oblique/obliqueHelpers.js +175 -0
- package/src/vcs/vcm/layer/oblique/vectorOblique.js +469 -0
- package/src/vcs/vcm/layer/openStreetMap.js +194 -0
- package/src/vcs/vcm/layer/openlayers/layerOpenlayers.js +79 -0
- package/src/vcs/vcm/layer/openlayers/openStreetMapOpenlayers.js +27 -0
- package/src/vcs/vcm/layer/openlayers/rasterLayerOpenlayers.js +121 -0
- package/src/vcs/vcm/layer/openlayers/singleImageOpenlayers.js +49 -0
- package/src/vcs/vcm/layer/openlayers/tileDebugOpenlayers.js +39 -0
- package/src/vcs/vcm/layer/openlayers/tmsOpenlayers.js +62 -0
- package/src/vcs/vcm/layer/openlayers/vectorOpenlayers.js +118 -0
- package/src/vcs/vcm/layer/openlayers/vectorTileOpenlayers.js +177 -0
- package/src/vcs/vcm/layer/openlayers/wmsOpenlayers.js +55 -0
- package/src/vcs/vcm/layer/openlayers/wmtsOpenlayers.js +141 -0
- package/src/vcs/vcm/layer/pointCloud.js +162 -0
- package/src/vcs/vcm/layer/rasterLayer.js +294 -0
- package/src/vcs/vcm/layer/singleImage.js +119 -0
- package/src/vcs/vcm/layer/terrain.js +122 -0
- package/src/vcs/vcm/layer/terrainHelpers.js +123 -0
- package/src/vcs/vcm/layer/tileLoadedHelper.js +72 -0
- package/src/vcs/vcm/layer/tileProvider/mvtTileProvider.js +104 -0
- package/src/vcs/vcm/layer/tileProvider/staticGeojsonTileProvider.js +67 -0
- package/src/vcs/vcm/layer/tileProvider/tileProvider.js +584 -0
- package/src/vcs/vcm/layer/tileProvider/tileProviderFactory.js +28 -0
- package/src/vcs/vcm/layer/tileProvider/urlTemplateTileProvider.js +106 -0
- package/src/vcs/vcm/layer/tms.js +121 -0
- package/src/vcs/vcm/layer/vector.js +632 -0
- package/src/vcs/vcm/layer/vectorHelpers.js +206 -0
- package/src/vcs/vcm/layer/vectorProperties.js +1391 -0
- package/src/vcs/vcm/layer/vectorSymbols.js +40 -0
- package/src/vcs/vcm/layer/vectorTile.js +480 -0
- package/src/vcs/vcm/layer/wfs.js +165 -0
- package/src/vcs/vcm/layer/wms.js +270 -0
- package/src/vcs/vcm/layer/wmsHelpers.js +65 -0
- package/src/vcs/vcm/layer/wmts.js +235 -0
- package/src/vcs/vcm/maps/baseOLMap.js +257 -0
- package/src/vcs/vcm/maps/cameraLimiter.js +219 -0
- package/src/vcs/vcm/maps/cesium.js +1192 -0
- package/src/vcs/vcm/maps/map.js +511 -0
- package/src/vcs/vcm/maps/mapState.js +17 -0
- package/src/vcs/vcm/maps/oblique.js +536 -0
- package/src/vcs/vcm/maps/openlayers.js +205 -0
- package/src/vcs/vcm/object.js +92 -0
- package/src/vcs/vcm/oblique/ObliqueCollection.js +572 -0
- package/src/vcs/vcm/oblique/ObliqueDataSet.js +357 -0
- package/src/vcs/vcm/oblique/ObliqueImage.js +247 -0
- package/src/vcs/vcm/oblique/ObliqueImageMeta.js +126 -0
- package/src/vcs/vcm/oblique/ObliqueProvider.js +433 -0
- package/src/vcs/vcm/oblique/ObliqueView.js +130 -0
- package/src/vcs/vcm/oblique/ObliqueViewDirection.js +40 -0
- package/src/vcs/vcm/oblique/helpers.js +483 -0
- package/src/vcs/vcm/oblique/parseImageJson.js +248 -0
- package/src/vcs/vcm/util/clipping/clippingObject.js +386 -0
- package/src/vcs/vcm/util/clipping/clippingObjectManager.js +312 -0
- package/src/vcs/vcm/util/clipping/clippingPlaneHelper.js +413 -0
- package/src/vcs/vcm/util/collection.js +193 -0
- package/src/vcs/vcm/util/dateTime.js +60 -0
- package/src/vcs/vcm/util/exclusiveManager.js +135 -0
- package/src/vcs/vcm/util/extent.js +124 -0
- package/src/vcs/vcm/util/featureProvider/abstractFeatureProvider.js +196 -0
- package/src/vcs/vcm/util/featureProvider/featureProviderHelpers.js +51 -0
- package/src/vcs/vcm/util/featureProvider/featureProviderSymbols.js +11 -0
- package/src/vcs/vcm/util/featureProvider/tileProviderFeatureProvider.js +62 -0
- package/src/vcs/vcm/util/featureProvider/wmsFeatureProvider.js +280 -0
- package/src/vcs/vcm/util/featureconverter/circleToCesium.js +215 -0
- package/src/vcs/vcm/util/featureconverter/convert.js +83 -0
- package/src/vcs/vcm/util/featureconverter/extent3d.js +154 -0
- package/src/vcs/vcm/util/featureconverter/featureconverterHelper.js +591 -0
- package/src/vcs/vcm/util/featureconverter/lineStringToCesium.js +171 -0
- package/src/vcs/vcm/util/featureconverter/pointToCesium.js +359 -0
- package/src/vcs/vcm/util/featureconverter/polygonToCesium.js +229 -0
- package/src/vcs/vcm/util/geometryHelpers.js +172 -0
- package/src/vcs/vcm/util/indexedCollection.js +158 -0
- package/src/vcs/vcm/util/isMobile.js +12 -0
- package/src/vcs/vcm/util/layerCollection.js +216 -0
- package/src/vcs/vcm/util/locale.js +53 -0
- package/src/vcs/vcm/util/mapCollection.js +363 -0
- package/src/vcs/vcm/util/math.js +71 -0
- package/src/vcs/vcm/util/projection.js +348 -0
- package/src/vcs/vcm/util/splitScreen.js +233 -0
- package/src/vcs/vcm/util/style/declarativeStyleItem.js +631 -0
- package/src/vcs/vcm/util/style/shapesCategory.js +67 -0
- package/src/vcs/vcm/util/style/styleFactory.js +48 -0
- package/src/vcs/vcm/util/style/styleHelpers.js +555 -0
- package/src/vcs/vcm/util/style/styleItem.js +226 -0
- package/src/vcs/vcm/util/style/vectorStyleItem.js +927 -0
- package/src/vcs/vcm/util/style/writeStyle.js +48 -0
- package/src/vcs/vcm/util/urlHelpers.js +16 -0
- package/src/vcs/vcm/util/viewpoint.js +333 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import VcsObject from '../object.js';
|
|
2
|
+
import LayerState from './layerState.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* represents an implementation for a Layer for a specific Map
|
|
6
|
+
* @class
|
|
7
|
+
* @export
|
|
8
|
+
* @extends {VcsObject}
|
|
9
|
+
* @abstract
|
|
10
|
+
* @api
|
|
11
|
+
* @template {import("@vcmap/core").VcsMap} T
|
|
12
|
+
*/
|
|
13
|
+
class LayerImplementation extends VcsObject {
|
|
14
|
+
static get className() { return 'vcs.vcm.layer.LayerImplementation'; }
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {T} map
|
|
18
|
+
* @param {LayerImplementationOptions} options
|
|
19
|
+
*/
|
|
20
|
+
constructor(map, options) {
|
|
21
|
+
super(options);
|
|
22
|
+
/** @type {T} */
|
|
23
|
+
this.map = map;
|
|
24
|
+
/**
|
|
25
|
+
* @type {string}
|
|
26
|
+
*/
|
|
27
|
+
this.url = options.url;
|
|
28
|
+
/**
|
|
29
|
+
* The current active state of the implementation
|
|
30
|
+
* @type {LayerState}
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
33
|
+
this._state = LayerState.INACTIVE;
|
|
34
|
+
/**
|
|
35
|
+
* @type {boolean}
|
|
36
|
+
* @private
|
|
37
|
+
*/
|
|
38
|
+
this._initialized = false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Whether this implementation has been initialized (e.g. activated at least once)
|
|
43
|
+
* @type {boolean}
|
|
44
|
+
* @readonly
|
|
45
|
+
*/
|
|
46
|
+
get initialized() { return this._initialized; }
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @type {boolean}
|
|
50
|
+
* @api
|
|
51
|
+
*/
|
|
52
|
+
get active() { return this._state === LayerState.ACTIVE; }
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @type {boolean}
|
|
56
|
+
* @api
|
|
57
|
+
*/
|
|
58
|
+
get loading() { return this._state === LayerState.LOADING; }
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* interface to initialize this implementation, is used to setup elements which have to be created only once.
|
|
62
|
+
* Has to set this.initialized = true;
|
|
63
|
+
* @returns {Promise<void>}
|
|
64
|
+
*/
|
|
65
|
+
async initialize() {
|
|
66
|
+
this._initialized = true;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* activates the implementation, if the map is also active. calls initialize (only use internally)
|
|
71
|
+
* Once the promise resolves, the layer can still be inactive, if deactivate was called while initializing the layer.
|
|
72
|
+
* @returns {Promise<void>}
|
|
73
|
+
*/
|
|
74
|
+
async activate() {
|
|
75
|
+
if (this.map.active && !this.active) {
|
|
76
|
+
this._state = LayerState.LOADING;
|
|
77
|
+
await this.initialize();
|
|
78
|
+
if (this.loading) {
|
|
79
|
+
this._state = LayerState.ACTIVE;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* deactivates the implementation (only use internally)
|
|
86
|
+
*/
|
|
87
|
+
deactivate() {
|
|
88
|
+
this._state = LayerState.INACTIVE;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* destroys this implementation, after destroying the implementation cannot be used anymore.
|
|
93
|
+
*/
|
|
94
|
+
destroy() {
|
|
95
|
+
this._initialized = false;
|
|
96
|
+
this._state = LayerState.INACTIVE;
|
|
97
|
+
this.map = null;
|
|
98
|
+
super.destroy();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export default LayerImplementation;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enumeration of possible layer states.
|
|
3
|
+
* State machine: inactive <-> loading -> active -> inactive
|
|
4
|
+
* @enum {number}
|
|
5
|
+
* @export
|
|
6
|
+
* @api
|
|
7
|
+
* @property {number} INACTIVE
|
|
8
|
+
* @property {number} ACTIVE
|
|
9
|
+
* @property {number} LOADING
|
|
10
|
+
*/
|
|
11
|
+
const LayerState = {
|
|
12
|
+
INACTIVE: 1,
|
|
13
|
+
ACTIVE: 2,
|
|
14
|
+
LOADING: 4,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default LayerState;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import LayerImplementation from '../layerImplementation.js';
|
|
2
|
+
import { vcsLayerName } from '../layerSymbols.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @class
|
|
6
|
+
* @extends {LayerImplementation<import("@vcmap/core").Oblique>}}
|
|
7
|
+
* @abstract
|
|
8
|
+
*/
|
|
9
|
+
class LayerOblique extends LayerImplementation {
|
|
10
|
+
/**
|
|
11
|
+
* @param {import("@vcmap/core").Oblique} map
|
|
12
|
+
* @param {LayerImplementationOptions} options
|
|
13
|
+
*/
|
|
14
|
+
constructor(map, options) {
|
|
15
|
+
super(map, options);
|
|
16
|
+
/**
|
|
17
|
+
* @type {import("ol/layer").Layer<import("ol/source/Source").default>|null}
|
|
18
|
+
*/
|
|
19
|
+
this.olLayer = null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @inheritDoc
|
|
24
|
+
* @returns {Promise<void>}
|
|
25
|
+
*/
|
|
26
|
+
initialize() {
|
|
27
|
+
if (!this.initialized) {
|
|
28
|
+
this.olLayer = this.getOLLayer();
|
|
29
|
+
this.olLayer[vcsLayerName] = this.name;
|
|
30
|
+
this.map.addOLLayer(this.olLayer);
|
|
31
|
+
}
|
|
32
|
+
return super.initialize();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @inheritDoc
|
|
37
|
+
* @returns {Promise<void>}
|
|
38
|
+
*/
|
|
39
|
+
async activate() {
|
|
40
|
+
await super.activate();
|
|
41
|
+
if (this.active) {
|
|
42
|
+
this.olLayer.setVisible(true);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @inheritDoc
|
|
48
|
+
*/
|
|
49
|
+
deactivate() {
|
|
50
|
+
super.deactivate();
|
|
51
|
+
if (this.olLayer) {
|
|
52
|
+
this.olLayer.setVisible(false);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// eslint-disable-next-line jsdoc/require-returns-check
|
|
57
|
+
/**
|
|
58
|
+
* returns the ol Layer
|
|
59
|
+
* @returns {import("ol/layer").Layer<import("ol/source/Source").default>}
|
|
60
|
+
*/
|
|
61
|
+
// eslint-disable-next-line class-methods-use-this
|
|
62
|
+
getOLLayer() { throw new Error(); }
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @inheritDoc
|
|
66
|
+
*/
|
|
67
|
+
destroy() {
|
|
68
|
+
if (this.olLayer) {
|
|
69
|
+
this.map.removeOLLayer(this.olLayer);
|
|
70
|
+
}
|
|
71
|
+
this.olLayer = null;
|
|
72
|
+
super.destroy();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export default LayerOblique;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import Circle from 'ol/geom/Circle.js';
|
|
2
|
+
import { fromCircle } from 'ol/geom/Polygon.js';
|
|
3
|
+
import { getTransform } from 'ol/proj.js';
|
|
4
|
+
import { Cartographic, sampleTerrainMostDetailed } from '@vcmap/cesium';
|
|
5
|
+
import { cartesian2DDistance } from '../../util/math.js';
|
|
6
|
+
import Projection, { mercatorProjection, wgs84Projection } from '../../util/projection.js';
|
|
7
|
+
import { actuallyIsCircle, alreadyTransformedToImage, obliqueGeometry } from '../vectorSymbols.js';
|
|
8
|
+
import { convertGeometryToPolygon, getFlatCoordinatesFromGeometry } from '../../util/geometryHelpers.js';
|
|
9
|
+
import { transformFromImage } from '../../oblique/helpers.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {Object} TransformationOptions
|
|
13
|
+
* @property {boolean|undefined} dontUseTerrain - whether to use the terrain or not
|
|
14
|
+
* @property {import("@vcmap/core").ObliqueImage|undefined} image - the image to use, instead of the current image
|
|
15
|
+
* @property {import("ol/proj/Projection").default|undefined} dataProjection - the projection of the input/output coordinates, assumes wgs84
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @param {Array<import("ol/coordinate").Coordinate>} coordinates
|
|
20
|
+
* @returns {number}
|
|
21
|
+
*/
|
|
22
|
+
export function getLongestSide(coordinates) {
|
|
23
|
+
let side = 0;
|
|
24
|
+
for (let i = 0; i < coordinates.length; i++) {
|
|
25
|
+
let j = i + 1;
|
|
26
|
+
if (j >= coordinates.length) {
|
|
27
|
+
j = 0;
|
|
28
|
+
}
|
|
29
|
+
const point1 = coordinates[i];
|
|
30
|
+
const point2 = coordinates[j];
|
|
31
|
+
const currentSide = cartesian2DDistance(point1, point2);
|
|
32
|
+
if (currentSide > side) {
|
|
33
|
+
side = currentSide;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return side;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param {import("ol/Map").default} olMap
|
|
41
|
+
* @param {import("@vcmap/core").ObliqueImage} image
|
|
42
|
+
* @returns {{size: {height: number, width: number}, fovy: number, metersPerUnit: number}}
|
|
43
|
+
*/
|
|
44
|
+
export function getResolutionOptions(olMap, image) {
|
|
45
|
+
const longestSide = getLongestSide(image.groundCoordinates);
|
|
46
|
+
const fov = Math.PI / 3.0;
|
|
47
|
+
const viewport = /** @type {HTMLElement} */ (olMap.getViewport());
|
|
48
|
+
const size = {
|
|
49
|
+
height: viewport.offsetHeight || 1,
|
|
50
|
+
width: viewport.offsetWidth || 1,
|
|
51
|
+
};
|
|
52
|
+
const aspectRatio = size.width / size.height;
|
|
53
|
+
const fovy = Math.atan(Math.tan(fov * 0.5) / aspectRatio) * 2.0;
|
|
54
|
+
|
|
55
|
+
const [imageSizeX, imageSizeY] = image.meta.size;
|
|
56
|
+
const longestImageSize = imageSizeX > imageSizeY ? imageSizeX : imageSizeY;
|
|
57
|
+
const metersPerUnit = longestSide / longestImageSize;
|
|
58
|
+
return {
|
|
59
|
+
size,
|
|
60
|
+
fovy,
|
|
61
|
+
metersPerUnit,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @param {import("ol/Map").default} olMap
|
|
67
|
+
* @param {import("@vcmap/core").ObliqueImage} image
|
|
68
|
+
* @param {number} distance
|
|
69
|
+
* @returns {number}
|
|
70
|
+
*/
|
|
71
|
+
export function getZoom(olMap, image, distance) {
|
|
72
|
+
const { size, fovy, metersPerUnit } = getResolutionOptions(olMap, image);
|
|
73
|
+
const visibleMeters = 2 * distance * Math.tan(fovy / 2);
|
|
74
|
+
const visibleMapUnits = visibleMeters / metersPerUnit;
|
|
75
|
+
const resolution = visibleMapUnits / size.height;
|
|
76
|
+
return olMap.getView().getZoomForResolution(resolution);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* converts a geometry in mercator format to image coordinates
|
|
82
|
+
* @param {import("ol/geom/Geometry").default} inputSourceGeometry
|
|
83
|
+
* @param {import("ol/geom/Geometry").default} destinationGeometry
|
|
84
|
+
* @param {import("@vcmap/core").ObliqueImage} image
|
|
85
|
+
* @returns {Promise<import("ol/geom/Geometry").default>}
|
|
86
|
+
*/
|
|
87
|
+
export async function mercatorGeometryToImageGeometry(inputSourceGeometry, destinationGeometry, image) {
|
|
88
|
+
const sourceGeometry = inputSourceGeometry instanceof Circle ?
|
|
89
|
+
fromCircle(inputSourceGeometry) :
|
|
90
|
+
inputSourceGeometry;
|
|
91
|
+
const coordinates = sourceGeometry.getCoordinates();
|
|
92
|
+
/** type {Array.<import("ol/coordinate").Coordinate>} */
|
|
93
|
+
const flattenCoordinates = getFlatCoordinatesFromGeometry(sourceGeometry, coordinates);
|
|
94
|
+
let transformer = getTransform(mercatorProjection.proj, image.meta.projection);
|
|
95
|
+
|
|
96
|
+
let updatedPositions = [];
|
|
97
|
+
if (image.meta.terrainProvider) {
|
|
98
|
+
const cartographicCoordinates = flattenCoordinates.map((coord) => {
|
|
99
|
+
Projection.mercatorToWgs84(coord, true);
|
|
100
|
+
return Cartographic.fromDegrees(coord[0], coord[1]);
|
|
101
|
+
});
|
|
102
|
+
transformer = getTransform(wgs84Projection.proj, image.meta.projection);
|
|
103
|
+
updatedPositions = await sampleTerrainMostDetailed(image.meta.terrainProvider, cartographicCoordinates);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
flattenCoordinates.forEach((coord, index) => {
|
|
107
|
+
transformer(coord, coord, 3);
|
|
108
|
+
const exactHeight = updatedPositions[index] ? updatedPositions[index].height : null;
|
|
109
|
+
const imageCoords = image.transformRealWorld2Image(coord, exactHeight || coord[2] || image.averageHeight);
|
|
110
|
+
flattenCoordinates[index][0] = imageCoords[0];
|
|
111
|
+
flattenCoordinates[index][1] = imageCoords[1];
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
destinationGeometry.setCoordinates(coordinates);
|
|
115
|
+
return destinationGeometry;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* returns a cloned geometry geometry with coordinates to format to image coordinates
|
|
120
|
+
* @param {import("ol/geom/Geometry").default} sourceGeometry
|
|
121
|
+
* @param {import("ol/geom/Geometry").default} destinationGeometry
|
|
122
|
+
* @param {import("@vcmap/core").ObliqueImage} image
|
|
123
|
+
* @returns {Promise<import("ol/geom/Geometry").default>}
|
|
124
|
+
*/
|
|
125
|
+
export function imageGeometryToMercatorGeometry(sourceGeometry, destinationGeometry, image) {
|
|
126
|
+
const coordinates = sourceGeometry.getCoordinates();
|
|
127
|
+
/** type {Array.<import("ol/coordinate").Coordinate>} */
|
|
128
|
+
const flattenCoordinates = getFlatCoordinatesFromGeometry(sourceGeometry, coordinates);
|
|
129
|
+
const promises = flattenCoordinates.map(coord => transformFromImage(image, coord)
|
|
130
|
+
.then((coords) => {
|
|
131
|
+
coord[0] = coords.coords[0];
|
|
132
|
+
coord[1] = coords.coords[1];
|
|
133
|
+
coord[2] = coords.coords[2];
|
|
134
|
+
}));
|
|
135
|
+
return Promise.all(promises)
|
|
136
|
+
.then(() => {
|
|
137
|
+
destinationGeometry.setCoordinates(coordinates);
|
|
138
|
+
return destinationGeometry;
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @param {import("ol").Feature<import("ol/geom/Geometry").default>} feature
|
|
144
|
+
* @param {boolean} [retainRectangle=false]
|
|
145
|
+
* @returns {import("ol/geom/Geometry").default}
|
|
146
|
+
*/
|
|
147
|
+
export function getPolygonizedGeometry(feature, retainRectangle = false) {
|
|
148
|
+
const geom = feature.getGeometry();
|
|
149
|
+
const isRectangle = geom.get('_vcsGeomType') === 'bbox' || geom.get('_vcsGeomType') === 'rectangle';
|
|
150
|
+
if (isRectangle && retainRectangle) {
|
|
151
|
+
return geom;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const isCircle = geom instanceof Circle;
|
|
155
|
+
const converted = convertGeometryToPolygon(geom);
|
|
156
|
+
converted[actuallyIsCircle] = isCircle;
|
|
157
|
+
return converted;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* sets the geometry from the originalfeature to the oblique feature
|
|
162
|
+
* @param {import("ol").Feature<import("ol/geom/Geometry").default>} originalFeature
|
|
163
|
+
* @param {import("ol").Feature<import("ol/geom/Geometry").default>} obliqueFeature
|
|
164
|
+
*/
|
|
165
|
+
export function setNewGeometry(originalFeature, obliqueFeature) {
|
|
166
|
+
const originalGeometry = originalFeature.getGeometry();
|
|
167
|
+
const originalGeometryClone = originalFeature.getGeometry().clone();
|
|
168
|
+
obliqueFeature.setGeometry(!originalGeometry[alreadyTransformedToImage] ?
|
|
169
|
+
convertGeometryToPolygon(originalGeometryClone) :
|
|
170
|
+
originalGeometryClone);
|
|
171
|
+
if (originalGeometry[alreadyTransformedToImage]) { // TODO handle UI for bbox and rectangle
|
|
172
|
+
obliqueFeature.getGeometry().setProperties(originalFeature.getGeometry().getProperties(), false);
|
|
173
|
+
}
|
|
174
|
+
originalFeature[obliqueGeometry] = obliqueFeature.getGeometry();
|
|
175
|
+
}
|