@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.
Files changed (146) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +44 -0
  3. package/build/postinstall.js +44 -0
  4. package/index.js +139 -0
  5. package/package.json +92 -0
  6. package/src/cesium/cesium3DTileFeature.js +9 -0
  7. package/src/cesium/cesium3DTilePointFeature.js +9 -0
  8. package/src/cesium/cesiumVcsCameraPrimitive.js +146 -0
  9. package/src/cesium/wallpaperMaterial.js +64 -0
  10. package/src/ol/feature.js +47 -0
  11. package/src/ol/geom/circle.js +24 -0
  12. package/src/ol/geom/geometryCollection.js +33 -0
  13. package/src/ol/render/canvas/canvasTileRenderer.js +179 -0
  14. package/src/ol/source/ClusterEnhancedVectorSource.js +39 -0
  15. package/src/ol/source/VcsCluster.js +37 -0
  16. package/src/vcs/vcm/classRegistry.js +106 -0
  17. package/src/vcs/vcm/event/vcsEvent.js +89 -0
  18. package/src/vcs/vcm/globalCollections.js +11 -0
  19. package/src/vcs/vcm/interaction/abstractInteraction.js +149 -0
  20. package/src/vcs/vcm/interaction/coordinateAtPixel.js +102 -0
  21. package/src/vcs/vcm/interaction/eventHandler.js +425 -0
  22. package/src/vcs/vcm/interaction/featureAtPixelInteraction.js +286 -0
  23. package/src/vcs/vcm/interaction/featureProviderInteraction.js +54 -0
  24. package/src/vcs/vcm/interaction/interactionChain.js +124 -0
  25. package/src/vcs/vcm/interaction/interactionType.js +114 -0
  26. package/src/vcs/vcm/layer/buildings.js +17 -0
  27. package/src/vcs/vcm/layer/cesium/cesiumTilesetCesium.js +359 -0
  28. package/src/vcs/vcm/layer/cesium/clusterContext.js +95 -0
  29. package/src/vcs/vcm/layer/cesium/dataSourceCesium.js +171 -0
  30. package/src/vcs/vcm/layer/cesium/openStreetMapCesium.js +29 -0
  31. package/src/vcs/vcm/layer/cesium/pointCloudCesium.js +58 -0
  32. package/src/vcs/vcm/layer/cesium/rasterLayerCesium.js +110 -0
  33. package/src/vcs/vcm/layer/cesium/singleImageCesium.js +49 -0
  34. package/src/vcs/vcm/layer/cesium/terrainCesium.js +80 -0
  35. package/src/vcs/vcm/layer/cesium/tmsCesium.js +54 -0
  36. package/src/vcs/vcm/layer/cesium/vectorCesium.js +255 -0
  37. package/src/vcs/vcm/layer/cesium/vectorContext.js +167 -0
  38. package/src/vcs/vcm/layer/cesium/vectorRasterTileCesium.js +116 -0
  39. package/src/vcs/vcm/layer/cesium/vectorTileImageryProvider.js +246 -0
  40. package/src/vcs/vcm/layer/cesium/wmsCesium.js +71 -0
  41. package/src/vcs/vcm/layer/cesium/wmtsCesium.js +101 -0
  42. package/src/vcs/vcm/layer/cesium/x3dmHelper.js +22 -0
  43. package/src/vcs/vcm/layer/cesiumTileset.js +376 -0
  44. package/src/vcs/vcm/layer/czml.js +141 -0
  45. package/src/vcs/vcm/layer/dataSource.js +259 -0
  46. package/src/vcs/vcm/layer/featureLayer.js +261 -0
  47. package/src/vcs/vcm/layer/featureStore.js +647 -0
  48. package/src/vcs/vcm/layer/featureStoreChanges.js +360 -0
  49. package/src/vcs/vcm/layer/featureStoreState.js +19 -0
  50. package/src/vcs/vcm/layer/featureVisibility.js +435 -0
  51. package/src/vcs/vcm/layer/geojson.js +185 -0
  52. package/src/vcs/vcm/layer/geojsonHelpers.js +450 -0
  53. package/src/vcs/vcm/layer/globalHider.js +157 -0
  54. package/src/vcs/vcm/layer/layer.js +752 -0
  55. package/src/vcs/vcm/layer/layerImplementation.js +102 -0
  56. package/src/vcs/vcm/layer/layerState.js +17 -0
  57. package/src/vcs/vcm/layer/layerSymbols.js +6 -0
  58. package/src/vcs/vcm/layer/oblique/layerOblique.js +76 -0
  59. package/src/vcs/vcm/layer/oblique/obliqueHelpers.js +175 -0
  60. package/src/vcs/vcm/layer/oblique/vectorOblique.js +469 -0
  61. package/src/vcs/vcm/layer/openStreetMap.js +194 -0
  62. package/src/vcs/vcm/layer/openlayers/layerOpenlayers.js +79 -0
  63. package/src/vcs/vcm/layer/openlayers/openStreetMapOpenlayers.js +27 -0
  64. package/src/vcs/vcm/layer/openlayers/rasterLayerOpenlayers.js +121 -0
  65. package/src/vcs/vcm/layer/openlayers/singleImageOpenlayers.js +49 -0
  66. package/src/vcs/vcm/layer/openlayers/tileDebugOpenlayers.js +39 -0
  67. package/src/vcs/vcm/layer/openlayers/tmsOpenlayers.js +62 -0
  68. package/src/vcs/vcm/layer/openlayers/vectorOpenlayers.js +118 -0
  69. package/src/vcs/vcm/layer/openlayers/vectorTileOpenlayers.js +177 -0
  70. package/src/vcs/vcm/layer/openlayers/wmsOpenlayers.js +55 -0
  71. package/src/vcs/vcm/layer/openlayers/wmtsOpenlayers.js +141 -0
  72. package/src/vcs/vcm/layer/pointCloud.js +162 -0
  73. package/src/vcs/vcm/layer/rasterLayer.js +294 -0
  74. package/src/vcs/vcm/layer/singleImage.js +119 -0
  75. package/src/vcs/vcm/layer/terrain.js +122 -0
  76. package/src/vcs/vcm/layer/terrainHelpers.js +123 -0
  77. package/src/vcs/vcm/layer/tileLoadedHelper.js +72 -0
  78. package/src/vcs/vcm/layer/tileProvider/mvtTileProvider.js +104 -0
  79. package/src/vcs/vcm/layer/tileProvider/staticGeojsonTileProvider.js +67 -0
  80. package/src/vcs/vcm/layer/tileProvider/tileProvider.js +584 -0
  81. package/src/vcs/vcm/layer/tileProvider/tileProviderFactory.js +28 -0
  82. package/src/vcs/vcm/layer/tileProvider/urlTemplateTileProvider.js +106 -0
  83. package/src/vcs/vcm/layer/tms.js +121 -0
  84. package/src/vcs/vcm/layer/vector.js +632 -0
  85. package/src/vcs/vcm/layer/vectorHelpers.js +206 -0
  86. package/src/vcs/vcm/layer/vectorProperties.js +1391 -0
  87. package/src/vcs/vcm/layer/vectorSymbols.js +40 -0
  88. package/src/vcs/vcm/layer/vectorTile.js +480 -0
  89. package/src/vcs/vcm/layer/wfs.js +165 -0
  90. package/src/vcs/vcm/layer/wms.js +270 -0
  91. package/src/vcs/vcm/layer/wmsHelpers.js +65 -0
  92. package/src/vcs/vcm/layer/wmts.js +235 -0
  93. package/src/vcs/vcm/maps/baseOLMap.js +257 -0
  94. package/src/vcs/vcm/maps/cameraLimiter.js +219 -0
  95. package/src/vcs/vcm/maps/cesium.js +1192 -0
  96. package/src/vcs/vcm/maps/map.js +511 -0
  97. package/src/vcs/vcm/maps/mapState.js +17 -0
  98. package/src/vcs/vcm/maps/oblique.js +536 -0
  99. package/src/vcs/vcm/maps/openlayers.js +205 -0
  100. package/src/vcs/vcm/object.js +92 -0
  101. package/src/vcs/vcm/oblique/ObliqueCollection.js +572 -0
  102. package/src/vcs/vcm/oblique/ObliqueDataSet.js +357 -0
  103. package/src/vcs/vcm/oblique/ObliqueImage.js +247 -0
  104. package/src/vcs/vcm/oblique/ObliqueImageMeta.js +126 -0
  105. package/src/vcs/vcm/oblique/ObliqueProvider.js +433 -0
  106. package/src/vcs/vcm/oblique/ObliqueView.js +130 -0
  107. package/src/vcs/vcm/oblique/ObliqueViewDirection.js +40 -0
  108. package/src/vcs/vcm/oblique/helpers.js +483 -0
  109. package/src/vcs/vcm/oblique/parseImageJson.js +248 -0
  110. package/src/vcs/vcm/util/clipping/clippingObject.js +386 -0
  111. package/src/vcs/vcm/util/clipping/clippingObjectManager.js +312 -0
  112. package/src/vcs/vcm/util/clipping/clippingPlaneHelper.js +413 -0
  113. package/src/vcs/vcm/util/collection.js +193 -0
  114. package/src/vcs/vcm/util/dateTime.js +60 -0
  115. package/src/vcs/vcm/util/exclusiveManager.js +135 -0
  116. package/src/vcs/vcm/util/extent.js +124 -0
  117. package/src/vcs/vcm/util/featureProvider/abstractFeatureProvider.js +196 -0
  118. package/src/vcs/vcm/util/featureProvider/featureProviderHelpers.js +51 -0
  119. package/src/vcs/vcm/util/featureProvider/featureProviderSymbols.js +11 -0
  120. package/src/vcs/vcm/util/featureProvider/tileProviderFeatureProvider.js +62 -0
  121. package/src/vcs/vcm/util/featureProvider/wmsFeatureProvider.js +280 -0
  122. package/src/vcs/vcm/util/featureconverter/circleToCesium.js +215 -0
  123. package/src/vcs/vcm/util/featureconverter/convert.js +83 -0
  124. package/src/vcs/vcm/util/featureconverter/extent3d.js +154 -0
  125. package/src/vcs/vcm/util/featureconverter/featureconverterHelper.js +591 -0
  126. package/src/vcs/vcm/util/featureconverter/lineStringToCesium.js +171 -0
  127. package/src/vcs/vcm/util/featureconverter/pointToCesium.js +359 -0
  128. package/src/vcs/vcm/util/featureconverter/polygonToCesium.js +229 -0
  129. package/src/vcs/vcm/util/geometryHelpers.js +172 -0
  130. package/src/vcs/vcm/util/indexedCollection.js +158 -0
  131. package/src/vcs/vcm/util/isMobile.js +12 -0
  132. package/src/vcs/vcm/util/layerCollection.js +216 -0
  133. package/src/vcs/vcm/util/locale.js +53 -0
  134. package/src/vcs/vcm/util/mapCollection.js +363 -0
  135. package/src/vcs/vcm/util/math.js +71 -0
  136. package/src/vcs/vcm/util/projection.js +348 -0
  137. package/src/vcs/vcm/util/splitScreen.js +233 -0
  138. package/src/vcs/vcm/util/style/declarativeStyleItem.js +631 -0
  139. package/src/vcs/vcm/util/style/shapesCategory.js +67 -0
  140. package/src/vcs/vcm/util/style/styleFactory.js +48 -0
  141. package/src/vcs/vcm/util/style/styleHelpers.js +555 -0
  142. package/src/vcs/vcm/util/style/styleItem.js +226 -0
  143. package/src/vcs/vcm/util/style/vectorStyleItem.js +927 -0
  144. package/src/vcs/vcm/util/style/writeStyle.js +48 -0
  145. package/src/vcs/vcm/util/urlHelpers.js +16 -0
  146. package/src/vcs/vcm/util/viewpoint.js +333 -0
@@ -0,0 +1,167 @@
1
+ import { PrimitiveCollection, BillboardCollection, LabelCollection } from '@vcmap/cesium';
2
+
3
+ /**
4
+ * @typedef {Object} VectorContextFeatureCache
5
+ * @property {Array<import("@vcmap/cesium").Primitive|import("@vcmap/cesium").GroundPrimitive|import("@vcmap/cesium").GroundPolylinePrimitive|import("@vcmap/cesium").ClassificationPrimitive|import("@vcmap/cesium").Model>|undefined} primitives
6
+ * @property {Array<import("@vcmap/cesium").Billboard|import("@vcmap/cesium").Entity>|undefined} billboards
7
+ * @property {Array<import("@vcmap/cesium").Label|import("@vcmap/cesium").Entity>|undefined} labels
8
+ */
9
+
10
+ /**
11
+ * @param {import("ol").Feature<import("ol/geom/Geometry").default>} feature
12
+ * @param {import("@vcmap/cesium").Primitive|import("@vcmap/cesium").GroundPrimitive|import("@vcmap/cesium").GroundPolylinePrimitive|import("@vcmap/cesium").ClassificationPrimitive|import("@vcmap/cesium").Label|import("@vcmap/cesium").Billboard|import("@vcmap/cesium").Entity|import("@vcmap/cesium").Model} primitive
13
+ */
14
+ export function setReferenceForPicking(feature, primitive) {
15
+ primitive.olFeature = feature;
16
+ }
17
+
18
+ /**
19
+ * @param {import("@vcmap/cesium").PrimitiveCollection|import("@vcmap/cesium").BillboardCollection|import("@vcmap/cesium").LabelCollection|import("@vcmap/cesium").EntityCollection=} collection
20
+ * @param {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>=} array
21
+ */
22
+ export function removeArrayFromCollection(collection, array) {
23
+ if (array) {
24
+ array.forEach((primitive) => {
25
+ collection.remove(primitive);
26
+ });
27
+ }
28
+ }
29
+
30
+ /**
31
+ * @param {import("ol").Feature<import("ol/geom/Geometry").default>} feature
32
+ * @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
+ * @param {import("@vcmap/cesium").PrimitiveCollection|import("@vcmap/cesium").BillboardCollection|import("@vcmap/cesium").LabelCollection|import("@vcmap/cesium").EntityCollection} primitiveCollection
34
+ */
35
+ export function removeFeatureFromMap(feature, featuresMap, primitiveCollection) {
36
+ removeArrayFromCollection(primitiveCollection, featuresMap.get(feature));
37
+ featuresMap.delete(feature);
38
+ }
39
+
40
+ /**
41
+ * @param {Array<import("@vcmap/cesium").Primitive|import("@vcmap/cesium").GroundPrimitive|import("@vcmap/cesium").GroundPolylinePrimitive|import("@vcmap/cesium").ClassificationPrimitive|import("@vcmap/cesium").Entity.ConstructorOptions|import("@vcmap/cesium").Model|Object>} primitives
42
+ * @param {import("ol").Feature<import("ol/geom/Geometry").default>} feature
43
+ * @param {boolean} allowPicking
44
+ * @param {import("@vcmap/cesium").BillboardCollection|import("@vcmap/cesium").LabelCollection|import("@vcmap/cesium").PrimitiveCollection|import("@vcmap/cesium").EntityCollection} primitiveCollection
45
+ * @param {Map<import("ol").Feature<import("ol/geom/Geometry").default>, Array<import("@vcmap/cesium").Billboard|import("@vcmap/cesium").Label|import("@vcmap/cesium").Primitive|import("@vcmap/cesium").GroundPrimitive|import("@vcmap/cesium").GroundPolylinePrimitive|import("@vcmap/cesium").ClassificationPrimitive|import("@vcmap/cesium").Entity|import("@vcmap/cesium").Model>>} featureMap
46
+ */
47
+ export function addPrimitiveToContext(primitives, feature, allowPicking, primitiveCollection, featureMap) {
48
+ if (primitives.length) {
49
+ const cesiumPrimitives = primitives.map((primitiveOptions) => {
50
+ const primitive = primitiveCollection.add(primitiveOptions);
51
+ if (allowPicking) {
52
+ setReferenceForPicking(feature, primitive);
53
+ }
54
+ return primitive;
55
+ });
56
+ if (!featureMap.has(feature)) {
57
+ featureMap.set(feature, cesiumPrimitives);
58
+ } else {
59
+ featureMap.get(feature).push(...cesiumPrimitives);
60
+ }
61
+ }
62
+ }
63
+
64
+ /**
65
+ * @class
66
+ */
67
+ class VectorContext {
68
+ /**
69
+ * @param {import("@vcmap/cesium").Scene} scene
70
+ * @param {import("@vcmap/cesium").PrimitiveCollection} rootCollection
71
+ */
72
+ constructor(scene, rootCollection) {
73
+ /** @type {import("@vcmap/cesium").PrimitiveCollection} */
74
+ this.primitives = new PrimitiveCollection();
75
+ /** @type {import("@vcmap/cesium").BillboardCollection} */
76
+ this.billboards = new BillboardCollection({ scene });
77
+ /** @type {import("@vcmap/cesium").LabelCollection} */
78
+ this.labels = new LabelCollection({ scene });
79
+ /** @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
+ this.featureToPrimitiveMap = new Map();
81
+ /** @type {Map<import("ol").Feature<import("ol/geom/Geometry").default>, Array<import("@vcmap/cesium").Billboard>>} */
82
+ this.featureToBillboardMap = new Map();
83
+ /** @type {Map<import("ol").Feature<import("ol/geom/Geometry").default>, Array<import("@vcmap/cesium").Label>>} */
84
+ this.featureToLabelMap = new Map();
85
+
86
+ rootCollection.add(this.primitives);
87
+ rootCollection.add(this.billboards);
88
+ rootCollection.add(this.labels);
89
+ }
90
+
91
+ /**
92
+ * @param {Array<import("@vcmap/cesium").Primitive|import("@vcmap/cesium").GroundPrimitive|import("@vcmap/cesium").GroundPolylinePrimitive|import("@vcmap/cesium").ClassificationPrimitive|import("@vcmap/cesium").Model>} primitives
93
+ * @param {import("ol").Feature<import("ol/geom/Geometry").default>} feature
94
+ * @param {boolean=} allowPicking
95
+ */
96
+ addPrimitives(primitives, feature, allowPicking) {
97
+ addPrimitiveToContext(primitives, feature, allowPicking, this.primitives, this.featureToPrimitiveMap);
98
+ }
99
+
100
+ /**
101
+ * @param {Array<Object>} billboardOptions
102
+ * @param {import("ol").Feature<import("ol/geom/Geometry").default>} feature
103
+ * @param {boolean=} allowPicking
104
+ */
105
+ addBillboards(billboardOptions, feature, allowPicking) {
106
+ addPrimitiveToContext(billboardOptions, feature, allowPicking, this.billboards, this.featureToBillboardMap);
107
+ }
108
+
109
+ /**
110
+ * @param {Array<Object>} labelOptions
111
+ * @param {import("ol").Feature<import("ol/geom/Geometry").default>} feature
112
+ * @param {boolean=} allowPicking
113
+ */
114
+ addLabels(labelOptions, feature, allowPicking) {
115
+ addPrimitiveToContext(labelOptions, feature, allowPicking, this.labels, this.featureToLabelMap);
116
+ }
117
+
118
+ /**
119
+ * @param {import("ol").Feature<import("ol/geom/Geometry").default>} feature
120
+ */
121
+ removeFeature(feature) {
122
+ removeFeatureFromMap(feature, this.featureToPrimitiveMap, this.primitives);
123
+ removeFeatureFromMap(feature, this.featureToBillboardMap, this.billboards);
124
+ removeFeatureFromMap(feature, this.featureToLabelMap, this.labels);
125
+ }
126
+
127
+ /**
128
+ * Caches the current cesium resources for a feature, removing them from the feature map
129
+ * @param {import("ol").Feature<import("ol/geom/Geometry").default>}feature
130
+ * @returns {VectorContextFeatureCache}
131
+ */
132
+ createFeatureCache(feature) {
133
+ /** @type {VectorContextFeatureCache} */
134
+ const cache = {};
135
+ cache.primitives = this.featureToPrimitiveMap.get(feature);
136
+ this.featureToPrimitiveMap.delete(feature);
137
+ cache.billboards = this.featureToBillboardMap.get(feature);
138
+ this.featureToBillboardMap.delete(feature);
139
+ cache.labels = this.featureToLabelMap.get(feature);
140
+ this.featureToLabelMap.delete(feature);
141
+ return cache;
142
+ }
143
+
144
+ /**
145
+ * @param {VectorContextFeatureCache} cache
146
+ */
147
+ clearFeatureCache(cache) {
148
+ removeArrayFromCollection(this.primitives, cache.primitives);
149
+ removeArrayFromCollection(this.billboards, cache.billboards);
150
+ removeArrayFromCollection(this.labels, cache.labels);
151
+ }
152
+
153
+ /**
154
+ * Clears all collections and maps
155
+ * @api
156
+ */
157
+ clear() {
158
+ this.primitives.removeAll();
159
+ this.billboards.removeAll();
160
+ this.labels.removeAll();
161
+ this.featureToBillboardMap.clear();
162
+ this.featureToLabelMap.clear();
163
+ this.featureToPrimitiveMap.clear();
164
+ }
165
+ }
166
+
167
+ export default VectorContext;
@@ -0,0 +1,116 @@
1
+ import { ImageryLayer as CesiumImageryLayer, Rectangle } from '@vcmap/cesium';
2
+ import VectorTileImageryProvider from './vectorTileImageryProvider.js';
3
+ import RasterLayerCesium from './rasterLayerCesium.js';
4
+ import { wgs84Projection } from '../../util/projection.js';
5
+
6
+ /**
7
+ * represents a rasterized tiled vector layer implementation for cesium.
8
+ * @class
9
+ * @export
10
+ * @extends {RasterLayerCesium}
11
+ * @implements {VectorTileImplementation}
12
+ */
13
+ class VectorRasterTileCesium extends RasterLayerCesium {
14
+ static get className() {
15
+ return 'vcs.vcm.layer.cesium.VectorRasterTileCesium';
16
+ }
17
+
18
+ /**
19
+ * @param {import("@vcmap/core").CesiumMap} map
20
+ * @param {VectorTileImplementationOptions} options
21
+ */
22
+ constructor(map, options) {
23
+ /** @type {RasterLayerImplementationOptions} */
24
+ const rasterLayerOptions = {
25
+ ...options,
26
+ tilingSchema: 'mercator',
27
+ splitDirection: undefined,
28
+ opacity: undefined,
29
+ };
30
+ super(map, rasterLayerOptions);
31
+ /** @type {import("@vcmap/core").TileProvider} */
32
+ this.tileProvider = options.tileProvider;
33
+
34
+ /**
35
+ * @type {import("ol/size").Size}
36
+ */
37
+ this.tileSize = options.tileSize;
38
+
39
+ /**
40
+ * @type {number|null}
41
+ * @private
42
+ */
43
+ this._reloadTimeout = null;
44
+
45
+ /**
46
+ * @type {VectorTileImageryProvider}
47
+ */
48
+ this.imageryProvider = null;
49
+ }
50
+
51
+ /**
52
+ * @returns {import("@vcmap/cesium").ImageryLayer}
53
+ */
54
+ getCesiumLayer() {
55
+ this.imageryProvider = new VectorTileImageryProvider({
56
+ tileProvider: this.tileProvider,
57
+ tileSize: this.tileSize,
58
+ });
59
+
60
+ const layerOptions = {
61
+ alpha: this.opacity,
62
+ splitDirection: this.splitDirection,
63
+ minimumTerrainLevel: this.minLevel,
64
+ maximumTerrainLevel: this.maxLevel,
65
+ };
66
+ if (this.extent && this.extent.isValid()) {
67
+ const extent = this.extent.getCoordinatesInProjection(wgs84Projection);
68
+ layerOptions.rectangle = Rectangle.fromDegrees(extent[0], extent[1], extent[2], extent[3]);
69
+ }
70
+ // @ts-ignore
71
+ const imageryLayer = new CesiumImageryLayer(this.imageryProvider, layerOptions);
72
+ return imageryLayer;
73
+ }
74
+
75
+
76
+ /**
77
+ * reloads the tiles
78
+ * @private
79
+ */
80
+ _reloadTiles() {
81
+ window.clearTimeout(this._reloadTimeout);
82
+ // eslint-disable-next-line no-underscore-dangle
83
+ if (this.imageryProvider && this.imageryProvider._reload) {
84
+ this._reloadTimeout = window.setTimeout(() => {
85
+ // todo find a way to reload specific tiles
86
+ // eslint-disable-next-line no-underscore-dangle
87
+ this.imageryProvider._reload();
88
+ this._reloadTimeout = null;
89
+ });
90
+ }
91
+ }
92
+
93
+ /**
94
+ * rerenders the specified tiles
95
+ * rendering happens async
96
+ * @param {Array<string>} tileIds
97
+ * @api
98
+ */
99
+ updateTiles(tileIds) {
100
+ if (tileIds.length > 0) {
101
+ this._reloadTiles();
102
+ }
103
+ }
104
+
105
+ /**
106
+ * @param {import("@vcmap/core").StyleItem} style
107
+ * @param {boolean=} silent
108
+ * @api
109
+ */
110
+ // eslint-disable-next-line no-unused-vars
111
+ updateStyle(style, silent) {
112
+ this._reloadTiles();
113
+ }
114
+ }
115
+
116
+ export default VectorRasterTileCesium;
@@ -0,0 +1,246 @@
1
+ import { Event as CesiumEvent, Rectangle, Math as CesiumMath } from '@vcmap/cesium';
2
+ import { compose, create as createTransform, scale as scaleTransform } from 'ol/transform.js';
3
+ import { rectangleToExtent } from '../tileProvider/tileProvider.js';
4
+ import { wgs84ToMercatorTransformer } from '../../util/projection.js';
5
+ import CanvasTileRenderer from '../../../../ol/render/canvas/canvasTileRenderer.js';
6
+
7
+ /**
8
+ * @param {import("ol/extent").Extent} extent
9
+ * @param {import("ol/coordinate").Coordinate} center
10
+ * @param {Object} context
11
+ * @param {import("ol/size").Size} tileSize
12
+ * @returns {import("ol").CanvasTileRenderer}
13
+ */
14
+ export function toContext(extent, center, context, tileSize) {
15
+ const { canvas } = context;
16
+ canvas.width = tileSize[0];
17
+ canvas.height = tileSize[1];
18
+ canvas.style.width = `${tileSize[0] }px`;
19
+ canvas.style.height = `${tileSize[1] }px`;
20
+ const scaleY = (extent[2] - extent[0]) / (extent[3] - extent[1]);
21
+ const sx = 1 / ((extent[2] - extent[0]) / 256);
22
+ const sy = -1 / ((extent[3] - extent[1]) / 256);
23
+ const transform = scaleTransform(createTransform(), 1, 1);
24
+ const newTransform = compose(transform, 128, 128, sx, sy, 0, -center[0], -center[1]);
25
+ // @ts-ignore
26
+ return new CanvasTileRenderer(context, 1, extent, newTransform, 0, null, null, scaleY);
27
+ }
28
+
29
+
30
+ /**
31
+ * creates a canvas and draws the features on the canvas;
32
+ * @param {Array<import("ol").Feature<import("ol/geom/Geometry").default>>} features
33
+ * @param {import("ol/extent").Extent} extent
34
+ * @param {import("@vcmap/cesium").Cartographic} center
35
+ * @param {import("ol/size").Size} tileSize
36
+ * @returns {HTMLCanvasElement}
37
+ */
38
+ export function getCanvasFromFeatures(features, extent, center, tileSize) {
39
+ const canvas = document.createElement('canvas');
40
+ canvas.width = tileSize[0];
41
+ canvas.height = tileSize[0];
42
+ const centerMercator =
43
+ wgs84ToMercatorTransformer([CesiumMath.toDegrees(center.longitude), CesiumMath.toDegrees(center.latitude)]);
44
+ const vectorContext = toContext(extent, centerMercator, canvas.getContext('2d'), tileSize);
45
+
46
+ features.forEach((feature) => {
47
+ const styleFunction = feature.getStyleFunction();
48
+ const featureStyles = /** @type {Array<import("ol/style/Style").default>} */(styleFunction(feature, 1));
49
+ featureStyles.forEach((styleToUse) => {
50
+ // @ts-ignore
51
+ vectorContext.drawFeature(feature, styleToUse);
52
+ });
53
+ });
54
+ return canvas;
55
+ }
56
+
57
+ /**
58
+ * @typedef {Object} VectorTileImageryProviderOptions
59
+ * @property {import("@vcmap/core").TileProvider} tileProvider
60
+ * @property {import("ol/size").Size} tileSize
61
+ * @api
62
+ */
63
+
64
+ /**
65
+ * implementation of Cesium ImageryProvider Interface
66
+ * @class
67
+ * @export
68
+ */
69
+ class VectorTileImageryProvider {
70
+ /**
71
+ * @param {VectorTileImageryProviderOptions} options
72
+ */
73
+ constructor(options) {
74
+ /**
75
+ * @type {import("@vcmap/core").TileProvider}
76
+ */
77
+ this.tileProvider = options.tileProvider;
78
+
79
+ /**
80
+ * @type {import("@vcmap/cesium").WebMercatorTilingScheme}
81
+ * @private
82
+ */
83
+ this._tilingScheme = this.tileProvider.tilingScheme;
84
+
85
+ /**
86
+ * @type {import("ol/size").Size}
87
+ * @private
88
+ */
89
+ this._tileSize = options.tileSize;
90
+
91
+ /**
92
+ * @type {import("@vcmap/cesium").Event}
93
+ * @private
94
+ */
95
+ this._errorEvent = new CesiumEvent();
96
+
97
+ /**
98
+ * @type {Promise<boolean>}
99
+ * @private
100
+ */
101
+ this._readyPromise = Promise.resolve(true);
102
+
103
+ /**
104
+ * @type {HTMLCanvasElement}
105
+ */
106
+ this.emptyCanvas = document.createElement('canvas');
107
+ this.emptyCanvas.width = this.tileWidth;
108
+ this.emptyCanvas.height = this.tileHeight;
109
+
110
+
111
+ /**
112
+ * @type {number}
113
+ */
114
+ this.minLevel = 0;
115
+ /**
116
+ * @type {number}
117
+ */
118
+ this.maxLevel = 26;
119
+
120
+ /**
121
+ * @type {Function}
122
+ */
123
+ this._reload = undefined;
124
+
125
+ // Necessary to satisfy Cesium ImageryProvider Interface
126
+ this.defaultAlpha = undefined;
127
+ this.defaultNightAlpha = undefined;
128
+ this.defaultDayAlpha = undefined;
129
+ this.defaultBrightness = undefined;
130
+ this.defaultContrast = undefined;
131
+ this.defaultHue = undefined;
132
+ this.defaultSaturation = undefined;
133
+ this.defaultGamma = undefined;
134
+ this.defaultMinificationFilter = undefined;
135
+ this.defaultMagnificationFilter = undefined;
136
+ }
137
+
138
+ /**
139
+ * @returns {boolean}
140
+ */
141
+ // eslint-disable-next-line class-methods-use-this
142
+ get ready() {
143
+ return true;
144
+ }
145
+
146
+ /**
147
+ * @returns {Promise<boolean>}
148
+ */
149
+ get readyPromise() {
150
+ return this._readyPromise;
151
+ }
152
+
153
+ /**
154
+ * @returns {import("@vcmap/cesium").Rectangle}
155
+ */
156
+ get rectangle() {
157
+ return this._tilingScheme.rectangle;
158
+ }
159
+
160
+ /**
161
+ * @returns {number}
162
+ */
163
+ get tileWidth() {
164
+ return this._tileSize[0];
165
+ }
166
+
167
+ /**
168
+ * @returns {number}
169
+ */
170
+ get tileHeight() {
171
+ return this._tileSize[1];
172
+ }
173
+
174
+ /**
175
+ * @returns {number}
176
+ */
177
+ get maximumLevel() {
178
+ return this.maxLevel;
179
+ }
180
+
181
+ /**
182
+ * @returns {number}
183
+ */
184
+ get minimumLevel() {
185
+ return this.minLevel;
186
+ }
187
+
188
+ /**
189
+ * @returns {import("@vcmap/cesium").TilingScheme}
190
+ */
191
+ get tilingScheme() {
192
+ return this._tilingScheme;
193
+ }
194
+
195
+ // eslint-disable-next-line class-methods-use-this
196
+ get tileDiscardPolicy() {
197
+ return undefined;
198
+ }
199
+
200
+ /**
201
+ * @returns {import("@vcmap/cesium").Event}
202
+ */
203
+ get errorEvent() {
204
+ return this._errorEvent;
205
+ }
206
+
207
+ // eslint-disable-next-line class-methods-use-this
208
+ get credit() {
209
+ return undefined;
210
+ }
211
+
212
+ // eslint-disable-next-line class-methods-use-this
213
+ get proxy() {
214
+ return undefined;
215
+ }
216
+
217
+ // eslint-disable-next-line class-methods-use-this
218
+ get hasAlphaChannel() {
219
+ return true;
220
+ }
221
+
222
+ /**
223
+ * Requests the image for a given tile. This function should
224
+ * not be called before {@link TileCoordinatesImageryProvider#ready} returns true.
225
+ *
226
+ * @param {number} x The tile X coordinate.
227
+ * @param {number} y The tile Y coordinate.
228
+ * @param {number} level The tile level.
229
+ * @returns {Promise<HTMLImageElement|HTMLCanvasElement>} A promise for the image that will resolve when the image is available, or
230
+ * undefined if there are too many active requests to the server, and the request
231
+ * should be retried later. The resolved image may be either an
232
+ * Image or a Canvas DOM object.
233
+ */
234
+ async requestImage(x, y, level) {
235
+ const features = await this.tileProvider.getFeaturesForTile(x, y, level);
236
+ if (features.length === 0) {
237
+ return this.emptyCanvas;
238
+ }
239
+ const rectangle = this.tileProvider.tilingScheme.tileXYToRectangle(x, y, level);
240
+ const extent = rectangleToExtent(rectangle);
241
+ const center = Rectangle.center(rectangle);
242
+ return getCanvasFromFeatures(features, extent, center, this._tileSize);
243
+ }
244
+ }
245
+
246
+ export default VectorTileImageryProvider;
@@ -0,0 +1,71 @@
1
+ import { ImageryLayer as CesiumImageryLayer, Rectangle, WebMercatorTilingScheme, WebMapServiceImageryProvider } from '@vcmap/cesium';
2
+
3
+ import RasterLayerCesium from './rasterLayerCesium.js';
4
+ import { wgs84Projection } from '../../util/projection.js';
5
+
6
+ /**
7
+ * represents a specific Cesium WMSCesium Layer class.
8
+ * @class
9
+ * @export
10
+ * @extends {RasterLayerCesium}
11
+ */
12
+ class WMSCesium extends RasterLayerCesium {
13
+ static get className() { return 'vcs.vcm.layer.cesium.WMSCesium'; }
14
+
15
+ /**
16
+ * @param {import("@vcmap/core").CesiumMap} map
17
+ * @param {WMSImplementationOptions} options
18
+ */
19
+ constructor(map, options) {
20
+ super(map, options);
21
+ /**
22
+ * @type {Object<string, *>}
23
+ */
24
+ this.parameters = options.parameters;
25
+ /**
26
+ * @type {boolean}
27
+ */
28
+ this.highResolution = options.highResolution;
29
+ /**
30
+ * @type {import("ol/size").Size}
31
+ */
32
+ this.tileSize = options.tileSize;
33
+ }
34
+
35
+ getCesiumLayer() {
36
+ const parameters = { ...this.parameters };
37
+ if (this.highResolution) {
38
+ parameters.width = this.tileSize[0] * 2;
39
+ parameters.height = this.tileSize[1] * 2;
40
+ }
41
+ const options = {
42
+ url: this.url,
43
+ layers: parameters.LAYERS,
44
+ minimumLevel: this.minLevel,
45
+ maximumLevel: this.maxLevel,
46
+ show: false,
47
+ parameters,
48
+ tileWidth: this.tileSize[0],
49
+ tileHeight: this.tileSize[1],
50
+ };
51
+
52
+ if (this.extent && this.extent.isValid()) {
53
+ const extent = this.extent.getCoordinatesInProjection(wgs84Projection);
54
+ if (extent) {
55
+ options.rectangle = Rectangle.fromDegrees(extent[0], extent[1], extent[2], extent[3]);
56
+ }
57
+ }
58
+ if (this.tilingSchema === 'mercator') {
59
+ options.tilingScheme = new WebMercatorTilingScheme();
60
+ }
61
+
62
+ const imageryProvider = new WebMapServiceImageryProvider(options);
63
+ const layerOptions = {
64
+ alpha: this.opacity,
65
+ splitDirection: this.splitDirection,
66
+ };
67
+ return new CesiumImageryLayer(imageryProvider, layerOptions);
68
+ }
69
+ }
70
+
71
+ export default WMSCesium;
@@ -0,0 +1,101 @@
1
+ import { Rectangle, WebMapTileServiceImageryProvider, ImageryLayer as CesiumImageryLayer } from '@vcmap/cesium';
2
+ import RasterLayerCesium from './rasterLayerCesium.js';
3
+ import { wgs84Projection } from '../../util/projection.js';
4
+ import { getTilingScheme } from '../rasterLayer.js';
5
+
6
+ /**
7
+ * represents a specific WMTS Implementation for {@link CesiumMap}.
8
+ * @class
9
+ * @export
10
+ * @extends {RasterLayerCesium}
11
+ */
12
+ class WMTSCesium extends RasterLayerCesium {
13
+ static get className() { return 'vcs.vcm.layer.cesium.WMTSCesium'; }
14
+
15
+ /**
16
+ * @param {import("@vcmap/core").CesiumMap} map
17
+ * @param {WMTSImplementationOptions} options
18
+ */
19
+ constructor(map, options) {
20
+ super(map, options);
21
+
22
+ /**
23
+ * @type {string}
24
+ */
25
+ this.layer = options.layer;
26
+
27
+ /**
28
+ * @type {string}
29
+ */
30
+ this.style = options.style;
31
+
32
+ /**
33
+ * @type {string}
34
+ */
35
+ this.format = options.format;
36
+
37
+ /**
38
+ * @type {string}
39
+ */
40
+ this.tileMatrixSetID = options.tileMatrixSetID;
41
+
42
+ /**
43
+ * @type {import("ol/size").Size}
44
+ */
45
+ this.tileSize = options.tileSize;
46
+
47
+ /**
48
+ * @type {number}
49
+ */
50
+ this.numberOfLevelZeroTilesX = options.numberOfLevelZeroTilesX;
51
+
52
+ /**
53
+ * @type {number}
54
+ */
55
+ this.numberOfLevelZeroTilesY = options.numberOfLevelZeroTilesY;
56
+
57
+ /**
58
+ * @type {Array<string>}
59
+ */
60
+ this.matrixIds = options.matrixIds;
61
+ }
62
+
63
+
64
+ /**
65
+ * @returns {import("@vcmap/cesium").ImageryLayer}
66
+ */
67
+ getCesiumLayer() {
68
+ // This is a bug in Cesium, they cant cope with {Layer} placeholder..
69
+ const url = this.url.indexOf('{Layer}') !== -1 ? this.url.replace('{Layer}', this.layer) : this.url;
70
+ const extent = this.extent.getCoordinatesInProjection(wgs84Projection);
71
+ const options = {
72
+ url,
73
+ layer: this.layer,
74
+ style: this.style,
75
+ format: this.format,
76
+ tileMatrixSetID: this.tileMatrixSetID,
77
+ maximumLevel: this.maxLevel,
78
+ rectangle: Rectangle.fromDegrees(extent[0], extent[1], extent[2], extent[3]),
79
+ tileWidth: this.tileSize[0],
80
+ tileHeight: this.tileSize[1],
81
+ };
82
+
83
+
84
+ options.tilingScheme = getTilingScheme({
85
+ tilingSchema: this.tilingSchema,
86
+ numberOfLevelZeroTilesX: this.numberOfLevelZeroTilesX,
87
+ numberOfLevelZeroTilesY: this.numberOfLevelZeroTilesY,
88
+ });
89
+
90
+ options.tileMatrixLabels = this.matrixIds;
91
+
92
+ const imageryProvider = new WebMapTileServiceImageryProvider(options);
93
+ const layerOptions = {
94
+ alpha: this.opacity,
95
+ splitDirection: this.splitDirection,
96
+ };
97
+ return new CesiumImageryLayer(imageryProvider, layerOptions);
98
+ }
99
+ }
100
+
101
+ export default WMTSCesium;