@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,631 @@
|
|
|
1
|
+
import { Color, ConditionsExpression, Expression, Cesium3DTileStyle } from '@vcmap/cesium';
|
|
2
|
+
import Style from 'ol/style/Style.js';
|
|
3
|
+
import Stroke from 'ol/style/Stroke.js';
|
|
4
|
+
import Icon from 'ol/style/Icon.js';
|
|
5
|
+
import Circle from 'ol/style/Circle.js';
|
|
6
|
+
import OLText from 'ol/style/Text.js';
|
|
7
|
+
import Fill from 'ol/style/Fill.js';
|
|
8
|
+
|
|
9
|
+
import StyleItem, { StyleType } from './styleItem.js';
|
|
10
|
+
import {
|
|
11
|
+
cesiumColorToColor,
|
|
12
|
+
emptyStyle,
|
|
13
|
+
getDefaultCondition,
|
|
14
|
+
whiteColor,
|
|
15
|
+
} from './styleHelpers.js';
|
|
16
|
+
import { originalFeatureSymbol } from '../../layer/vectorSymbols.js';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {Object} DeclarativeStyleItemConditions
|
|
20
|
+
* @property {Array<Array<string>|string>} conditions
|
|
21
|
+
* @api
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @typedef {Object} DeclarativeStyleOptions
|
|
26
|
+
* @property {Object|undefined} defines
|
|
27
|
+
* @property {DeclarativeStyleItemConditions|string|boolean|undefined} show
|
|
28
|
+
* @property {DeclarativeStyleItemConditions|string|undefined} color
|
|
29
|
+
* @property {DeclarativeStyleItemConditions|string|undefined} strokeColor - custom 2D ol condition
|
|
30
|
+
* @property {DeclarativeStyleItemConditions|string|undefined} strokeWidth - custom 2D ol condition
|
|
31
|
+
* @property {DeclarativeStyleItemConditions|string|undefined} scale
|
|
32
|
+
* @property {DeclarativeStyleItemConditions|string|undefined} pointOutlineWidth
|
|
33
|
+
* @property {DeclarativeStyleItemConditions|string|undefined} pointOutlineColor
|
|
34
|
+
* @property {DeclarativeStyleItemConditions|string|undefined} pointSize
|
|
35
|
+
* @property {DeclarativeStyleItemConditions|string|undefined} image - this should be an icon url
|
|
36
|
+
* @property {DeclarativeStyleItemConditions|string|undefined} font - a css font string
|
|
37
|
+
* @property {DeclarativeStyleItemConditions|string|undefined} labelStyle
|
|
38
|
+
* @property {DeclarativeStyleItemConditions|string|undefined} labelText
|
|
39
|
+
* @property {DeclarativeStyleItemConditions|string|undefined} labelColor
|
|
40
|
+
* @property {DeclarativeStyleItemConditions|string|undefined} labelOutlineWidth
|
|
41
|
+
* @property {DeclarativeStyleItemConditions|string|undefined} labelOutlineColor
|
|
42
|
+
* @property {DeclarativeStyleItemConditions|string|undefined} anchorLineEnabled
|
|
43
|
+
* @property {DeclarativeStyleItemConditions|string|undefined} anchorLineColor
|
|
44
|
+
* @property {DeclarativeStyleItemConditions|string|undefined} heightOffset
|
|
45
|
+
* @property {DeclarativeStyleItemConditions|string|undefined} verticalOrigin
|
|
46
|
+
* @property {DeclarativeStyleItemConditions|string|undefined} horizontalOrigin
|
|
47
|
+
* @property {DeclarativeStyleItemConditions|string|undefined} labelHorizontalOrigin
|
|
48
|
+
* @property {DeclarativeStyleItemConditions|string|undefined} labelVerticalOrigin
|
|
49
|
+
* @api
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @typedef {StyleItemOptions} DeclarativeStyleItemOptions
|
|
54
|
+
* @property {DeclarativeStyleOptions|undefined} declarativeStyle
|
|
55
|
+
* @api
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @typedef {StyleItemSections} DeclarativeStyleItemSections
|
|
60
|
+
* @property {boolean|undefined} defaults
|
|
61
|
+
* @property {boolean|undefined} declarativeStyle
|
|
62
|
+
* @api
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
/** @type {import("@vcmap/cesium").Color} */
|
|
66
|
+
const scratchColor = new Color();
|
|
67
|
+
|
|
68
|
+
const defaultText = new OLText({
|
|
69
|
+
font: '30px sans-serif',
|
|
70
|
+
fill: new Fill({ color: whiteColor }),
|
|
71
|
+
textAlign: 'left',
|
|
72
|
+
offsetY: -15,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @param {import("@vcmap/cesium").Cesium3DTileStyle} style
|
|
77
|
+
* @param {string} key
|
|
78
|
+
* @param {DeclarativeStyleOptions} options
|
|
79
|
+
*/
|
|
80
|
+
function addCustomProperty(style, key, options) {
|
|
81
|
+
if (options[key].conditions) {
|
|
82
|
+
style[key] = new ConditionsExpression(
|
|
83
|
+
options[key],
|
|
84
|
+
options.defines,
|
|
85
|
+
);
|
|
86
|
+
} else {
|
|
87
|
+
style[key] = new Expression(options[key], options.defines);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Style Object {@see https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/Styling}
|
|
93
|
+
* @class
|
|
94
|
+
* @export
|
|
95
|
+
* @extends {StyleItem}
|
|
96
|
+
* @api stable
|
|
97
|
+
*/
|
|
98
|
+
class DeclarativeStyleItem extends StyleItem {
|
|
99
|
+
static get className() { return 'vcs.vcm.util.style.DeclarativeStyleItem'; }
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @param {DeclarativeStyleItemOptions} options
|
|
103
|
+
*/
|
|
104
|
+
constructor(options) {
|
|
105
|
+
super(options);
|
|
106
|
+
|
|
107
|
+
const declarativeStyle = options.declarativeStyle || {};
|
|
108
|
+
declarativeStyle.show = declarativeStyle.show != null ? declarativeStyle.show : true;
|
|
109
|
+
|
|
110
|
+
/** @type {import("@vcmap/cesium").Cesium3DTileStyle} */
|
|
111
|
+
this.cesiumStyle = new Cesium3DTileStyle(declarativeStyle);
|
|
112
|
+
|
|
113
|
+
this._style = this._styleFunction.bind(this);
|
|
114
|
+
|
|
115
|
+
if (declarativeStyle.strokeColor) {
|
|
116
|
+
addCustomProperty(this.cesiumStyle, 'strokeColor', declarativeStyle);
|
|
117
|
+
}
|
|
118
|
+
if (declarativeStyle.strokeWidth) {
|
|
119
|
+
addCustomProperty(this.cesiumStyle, 'strokeWidth', declarativeStyle);
|
|
120
|
+
}
|
|
121
|
+
/** @type {DeclarativeStyleOptions} */
|
|
122
|
+
this._styleOptions = declarativeStyle;
|
|
123
|
+
|
|
124
|
+
/** @type {Map<string,import("ol/style/Circle").default>} */
|
|
125
|
+
this._circleCache = new Map();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @param {DeclarativeStyleItemSections=} sections
|
|
130
|
+
* @returns {DeclarativeStyleItemOptions}
|
|
131
|
+
* @api
|
|
132
|
+
*/
|
|
133
|
+
getOptions(sections) {
|
|
134
|
+
const options = /** @type {DeclarativeStyleItemOptions} */ (super.getOptions(sections));
|
|
135
|
+
options.type = StyleType.DECLARATIVE;
|
|
136
|
+
const usedSections = sections || {
|
|
137
|
+
declarativeStyle: true,
|
|
138
|
+
defaults: true,
|
|
139
|
+
};
|
|
140
|
+
if (usedSections.declarativeStyle) {
|
|
141
|
+
options.declarativeStyle = this.cesiumStyle.style;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return options;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* @param {DeclarativeStyleItem=} result
|
|
149
|
+
* @returns {DeclarativeStyleItem}
|
|
150
|
+
* @api
|
|
151
|
+
*/
|
|
152
|
+
clone(result) {
|
|
153
|
+
if (result) {
|
|
154
|
+
return result.assign(this);
|
|
155
|
+
}
|
|
156
|
+
return new DeclarativeStyleItem(this.getOptions());
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* @param {DeclarativeStyleItem} styleItem
|
|
161
|
+
* @returns {DeclarativeStyleItem}
|
|
162
|
+
* @api
|
|
163
|
+
*/
|
|
164
|
+
assign(styleItem) {
|
|
165
|
+
this.cesiumStyle = styleItem.cesiumStyle;
|
|
166
|
+
this._styleOptions = this.cesiumStyle.style;
|
|
167
|
+
return this;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* @param {import("ol").Feature<import("ol/geom/Geometry").default>} feature
|
|
172
|
+
* @returns {import("ol/style/Style").default}
|
|
173
|
+
* @private
|
|
174
|
+
*/
|
|
175
|
+
_styleFunction(feature) {
|
|
176
|
+
const actualFeature = feature[originalFeatureSymbol] || feature;
|
|
177
|
+
if (!this.cesiumStyle.show.evaluate(actualFeature)) {
|
|
178
|
+
return emptyStyle;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const geometryType = actualFeature.getGeometry().getType();
|
|
182
|
+
|
|
183
|
+
if (geometryType === 'Point') {
|
|
184
|
+
return this._stylePoint(actualFeature);
|
|
185
|
+
}
|
|
186
|
+
if (geometryType === 'Polygon') {
|
|
187
|
+
return this._stylePolygon(actualFeature);
|
|
188
|
+
}
|
|
189
|
+
if (geometryType === 'LineString') {
|
|
190
|
+
return this._styleLineString(actualFeature);
|
|
191
|
+
}
|
|
192
|
+
if (geometryType === 'Circle') {
|
|
193
|
+
return this._stylePolygon(actualFeature);
|
|
194
|
+
}
|
|
195
|
+
if (geometryType === 'MultiPoint') {
|
|
196
|
+
return this._stylePoint(actualFeature);
|
|
197
|
+
}
|
|
198
|
+
if (geometryType === 'MultiPolygon') {
|
|
199
|
+
return this._stylePolygon(actualFeature);
|
|
200
|
+
}
|
|
201
|
+
if (geometryType === 'MultiLineString') {
|
|
202
|
+
return this._styleLineString(actualFeature);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
this.getLogger().warning(`could not style geometry type: ${geometryType}`);
|
|
206
|
+
return emptyStyle;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* @param {import("ol").Feature<import("ol/geom/Geometry").default>} feature
|
|
211
|
+
* @returns {import("ol/style/Style").default}
|
|
212
|
+
* @private
|
|
213
|
+
*/
|
|
214
|
+
_stylePolygon(feature) {
|
|
215
|
+
const style = new Style({});
|
|
216
|
+
const color = this.cesiumStyle.color ?
|
|
217
|
+
// @ts-ignore
|
|
218
|
+
this.cesiumStyle.color.evaluate(feature, scratchColor) :
|
|
219
|
+
Color.WHITE;
|
|
220
|
+
if (color) {
|
|
221
|
+
style.setFill(new Fill({ color: cesiumColorToColor(/** @type {import("@vcmap/cesium").Color} */ (color)) }));
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
this._evaluateStroke(feature, style);
|
|
225
|
+
return style;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* @param {import("ol").Feature<import("ol/geom/Geometry").default>} feature
|
|
230
|
+
* @returns {import("ol/style/Style").default}
|
|
231
|
+
* @private
|
|
232
|
+
*/
|
|
233
|
+
_styleLineString(feature) {
|
|
234
|
+
const style = new Style({});
|
|
235
|
+
const isExtruded = feature.get('olcs_extrudedHeight') ||
|
|
236
|
+
(feature.get('olcs_storeyHeight') && feature.get('olcs_storeyNumber'));
|
|
237
|
+
const color = this.cesiumStyle.color ?
|
|
238
|
+
// @ts-ignore
|
|
239
|
+
this.cesiumStyle.color.evaluate(feature, scratchColor) :
|
|
240
|
+
Color.WHITE;
|
|
241
|
+
if (color) {
|
|
242
|
+
if (isExtruded) {
|
|
243
|
+
style.setFill(new Fill({ color: cesiumColorToColor(/** @type {import("@vcmap/cesium").Color} */(color)) }));
|
|
244
|
+
} else {
|
|
245
|
+
const strokeWidth = this.cesiumStyle.strokeWidth ?
|
|
246
|
+
this.cesiumStyle.strokeWidth.evaluate(feature) :
|
|
247
|
+
1;
|
|
248
|
+
style.setStroke(new Stroke({
|
|
249
|
+
width: Number.isFinite(strokeWidth) ? strokeWidth : 1,
|
|
250
|
+
color: cesiumColorToColor(/** @type {import("@vcmap/cesium").Color} */ (color)),
|
|
251
|
+
}));
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (isExtruded) {
|
|
256
|
+
this._evaluateStroke(feature, style);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return style;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* @param {import("ol").Feature<import("ol/geom/Geometry").default>} feature
|
|
264
|
+
* @returns {import("ol/style/Style").default}
|
|
265
|
+
* @private
|
|
266
|
+
*/
|
|
267
|
+
_stylePoint(feature) {
|
|
268
|
+
const style = new Style({});
|
|
269
|
+
|
|
270
|
+
if (this.cesiumStyle.labelText) {
|
|
271
|
+
// @ts-ignore
|
|
272
|
+
const text = this.cesiumStyle.labelText.evaluate(feature);
|
|
273
|
+
if (text) {
|
|
274
|
+
const textStyle = defaultText.clone();
|
|
275
|
+
textStyle.setText(text.toString());
|
|
276
|
+
if (this.cesiumStyle.font) {
|
|
277
|
+
// @ts-ignore
|
|
278
|
+
const font = this.cesiumStyle.font.evaluate(feature);
|
|
279
|
+
if (font) {
|
|
280
|
+
textStyle.setFont(font);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (this.cesiumStyle.labelColor) {
|
|
284
|
+
// @ts-ignore
|
|
285
|
+
const textColor = this.cesiumStyle.labelColor.evaluateColor(feature, scratchColor);
|
|
286
|
+
if (textColor) {
|
|
287
|
+
textStyle.getFill().setColor(cesiumColorToColor(textColor));
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (this.cesiumStyle.labelOutlineColor) {
|
|
291
|
+
// @ts-ignore
|
|
292
|
+
const outlineColor = this.cesiumStyle.labelOutlineColor.evaluate(feature, scratchColor);
|
|
293
|
+
if (outlineColor) {
|
|
294
|
+
const outlineWidth = this.cesiumStyle.labelOutlineWidth ?
|
|
295
|
+
// @ts-ignore
|
|
296
|
+
this.cesiumStyle.labelOutlineWidth.evaluate(feature) :
|
|
297
|
+
1;
|
|
298
|
+
textStyle.setStroke(new Stroke({
|
|
299
|
+
color: cesiumColorToColor(/** @type {import("@vcmap/cesium").Color} */ (outlineColor)),
|
|
300
|
+
width: outlineWidth,
|
|
301
|
+
}));
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
style.setText(textStyle);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (this.cesiumStyle.image) {
|
|
309
|
+
// @ts-ignore
|
|
310
|
+
const src = this.cesiumStyle.image.evaluate(feature);
|
|
311
|
+
if (src) {
|
|
312
|
+
style.setImage(new Icon({ src }));
|
|
313
|
+
}
|
|
314
|
+
} else {
|
|
315
|
+
const color = this.cesiumStyle.color ?
|
|
316
|
+
// @ts-ignore
|
|
317
|
+
this.cesiumStyle.color.evaluate(feature, scratchColor) :
|
|
318
|
+
Color.WHITE;
|
|
319
|
+
|
|
320
|
+
let radius = 4;
|
|
321
|
+
if (this.cesiumStyle.pointSize) {
|
|
322
|
+
// @ts-ignore
|
|
323
|
+
const size = this.cesiumStyle.pointSize.evaluate(feature);
|
|
324
|
+
radius = size / 2;
|
|
325
|
+
}
|
|
326
|
+
const width = this.cesiumStyle.pointOutlineWidth ?
|
|
327
|
+
// @ts-ignore
|
|
328
|
+
this.cesiumStyle.pointOutlineWidth.evaluate(feature) :
|
|
329
|
+
0;
|
|
330
|
+
|
|
331
|
+
let pointOutlineColor = Color.BLACK;
|
|
332
|
+
if (width) {
|
|
333
|
+
if (this.cesiumStyle.pointOutlineColor) {
|
|
334
|
+
// @ts-ignore
|
|
335
|
+
pointOutlineColor = this.cesiumStyle.pointOutlineColor.evaluateColor(feature, scratchColor);
|
|
336
|
+
}
|
|
337
|
+
radius += width / 2;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const circleCacheKey = `${radius}${color}${width}${pointOutlineColor}`;
|
|
341
|
+
if (!this._circleCache.has(circleCacheKey)) {
|
|
342
|
+
const circleOptions = {
|
|
343
|
+
radius,
|
|
344
|
+
fill: new Fill({ color: cesiumColorToColor(/** @type {import("@vcmap/cesium").Color} */ (color)) }),
|
|
345
|
+
};
|
|
346
|
+
if (width) {
|
|
347
|
+
circleOptions.stroke = new Stroke({
|
|
348
|
+
color: cesiumColorToColor(pointOutlineColor),
|
|
349
|
+
width,
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
this._circleCache.set(circleCacheKey, new Circle(circleOptions));
|
|
353
|
+
}
|
|
354
|
+
style.setImage(this._circleCache.get(circleCacheKey));
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (this.cesiumStyle.scale && style.getImage()) {
|
|
358
|
+
const scale = this.cesiumStyle.scale.evaluate(feature);
|
|
359
|
+
if (Number.isFinite(scale)) {
|
|
360
|
+
style.getImage().setScale(scale);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
this._evaluateStroke(feature, style);
|
|
365
|
+
return style;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* @param {import("ol").Feature<import("ol/geom/Geometry").default>} feature
|
|
370
|
+
* @param {import("ol/style/Style").default} style
|
|
371
|
+
* @private
|
|
372
|
+
*/
|
|
373
|
+
_evaluateStroke(feature, style) {
|
|
374
|
+
if (this.cesiumStyle.strokeColor) {
|
|
375
|
+
// @ts-ignore
|
|
376
|
+
const strokeColor = this.cesiumStyle.strokeColor.evaluateColor(feature, scratchColor);
|
|
377
|
+
if (strokeColor) {
|
|
378
|
+
const strokeWidth = this.cesiumStyle.strokeWidth ?
|
|
379
|
+
this.cesiumStyle.strokeWidth.evaluate(feature) :
|
|
380
|
+
1;
|
|
381
|
+
style.setStroke(new Stroke({
|
|
382
|
+
width: Number.isFinite(strokeWidth) ? strokeWidth : 1,
|
|
383
|
+
color: cesiumColorToColor(strokeColor),
|
|
384
|
+
}));
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* @type {DeclarativeStyleItemConditions|string|boolean|undefined}
|
|
391
|
+
* @api
|
|
392
|
+
*/
|
|
393
|
+
get show() {
|
|
394
|
+
return this._styleOptions.show;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* @param {DeclarativeStyleItemConditions|string|boolean|undefined} show
|
|
399
|
+
*/
|
|
400
|
+
set show(show) {
|
|
401
|
+
this._styleOptions.show = show;
|
|
402
|
+
// @ts-ignore setter != getter
|
|
403
|
+
this.cesiumStyle.show = show;
|
|
404
|
+
this._styleChanged();
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* @type {DeclarativeStyleItemConditions|string|undefined}
|
|
409
|
+
* @api
|
|
410
|
+
*/
|
|
411
|
+
get color() {
|
|
412
|
+
return this._styleOptions.color;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* @param {DeclarativeStyleItemConditions|string|undefined} color
|
|
417
|
+
*/
|
|
418
|
+
set color(color) {
|
|
419
|
+
this._styleOptions.color = color;
|
|
420
|
+
// @ts-ignore setter != getter
|
|
421
|
+
this.cesiumStyle.color = color;
|
|
422
|
+
this._styleChanged();
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* @type {DeclarativeStyleItemConditions|string|undefined}
|
|
427
|
+
* @api
|
|
428
|
+
*/
|
|
429
|
+
get strokeColor() {
|
|
430
|
+
return this._styleOptions.strokeColor;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* @param {DeclarativeStyleItemConditions|string|undefined} color
|
|
435
|
+
*/
|
|
436
|
+
set strokeColor(color) {
|
|
437
|
+
this._styleOptions.strokeColor = color;
|
|
438
|
+
// @ts-ignore setter != getter
|
|
439
|
+
this.cesiumStyle.strokeColor = color;
|
|
440
|
+
this._styleChanged();
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* @type {DeclarativeStyleItemConditions|string|undefined}
|
|
445
|
+
* @api
|
|
446
|
+
*/
|
|
447
|
+
get strokeWidth() {
|
|
448
|
+
return this._styleOptions.strokeWidth;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* @param {DeclarativeStyleItemConditions|string|undefined} width
|
|
453
|
+
*/
|
|
454
|
+
set strokeWidth(width) {
|
|
455
|
+
this._styleOptions.strokeWidth = width;
|
|
456
|
+
// @ts-ignore setter != getter
|
|
457
|
+
this.cesiumStyle.strokeWidth = width;
|
|
458
|
+
this._styleChanged();
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* @type {DeclarativeStyleItemConditions|string|undefined}
|
|
463
|
+
* @api
|
|
464
|
+
*/
|
|
465
|
+
get image() {
|
|
466
|
+
return this._styleOptions.image;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* @param {DeclarativeStyleItemConditions|string|undefined} src
|
|
471
|
+
*/
|
|
472
|
+
set image(src) {
|
|
473
|
+
this._styleOptions.image = src;
|
|
474
|
+
// @ts-ignore setter != getter
|
|
475
|
+
this.cesiumStyle.image = src;
|
|
476
|
+
this._styleChanged();
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* @type {DeclarativeStyleItemConditions|string|undefined}
|
|
481
|
+
* @api
|
|
482
|
+
*/
|
|
483
|
+
get labelText() {
|
|
484
|
+
return this._styleOptions.labelText;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* @param {DeclarativeStyleItemConditions|string|undefined} text
|
|
489
|
+
*/
|
|
490
|
+
set labelText(text) {
|
|
491
|
+
this._styleOptions.labelText = text;
|
|
492
|
+
// @ts-ignore setter != getter
|
|
493
|
+
this.cesiumStyle.labelText = text;
|
|
494
|
+
this._styleChanged();
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* @type {DeclarativeStyleItemConditions|string|undefined}
|
|
499
|
+
* @api
|
|
500
|
+
*/
|
|
501
|
+
get labelColor() {
|
|
502
|
+
return this._styleOptions.labelColor;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* @param {DeclarativeStyleItemConditions|string|undefined} color
|
|
507
|
+
*/
|
|
508
|
+
set labelColor(color) {
|
|
509
|
+
this._styleOptions.labelColor = color;
|
|
510
|
+
// @ts-ignore setter != getter
|
|
511
|
+
this.cesiumStyle.labelColor = color;
|
|
512
|
+
this._styleChanged();
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* @type {DeclarativeStyleItemConditions|string|undefined}
|
|
517
|
+
* @api
|
|
518
|
+
*/
|
|
519
|
+
get font() {
|
|
520
|
+
return this._styleOptions.font;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* @param {DeclarativeStyleItemConditions|string|undefined} font
|
|
525
|
+
*/
|
|
526
|
+
set font(font) {
|
|
527
|
+
this._styleOptions.font = font;
|
|
528
|
+
// @ts-ignore setter != getter
|
|
529
|
+
this.cesiumStyle.font = font;
|
|
530
|
+
this._styleChanged();
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* @type {DeclarativeStyleItemConditions|string|undefined}
|
|
535
|
+
* @api
|
|
536
|
+
*/
|
|
537
|
+
get pointSize() {
|
|
538
|
+
return this._styleOptions.pointSize;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* @param {DeclarativeStyleItemConditions|string|undefined} pointSize
|
|
543
|
+
*/
|
|
544
|
+
set pointSize(pointSize) {
|
|
545
|
+
this._styleOptions.pointSize = pointSize;
|
|
546
|
+
// @ts-ignore setter != getter
|
|
547
|
+
this.cesiumStyle.pointSize = pointSize;
|
|
548
|
+
this._styleChanged();
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* @inheritDoc
|
|
553
|
+
*/
|
|
554
|
+
destroy() {
|
|
555
|
+
this._circleCache.clear();
|
|
556
|
+
super.destroy();
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
export default DeclarativeStyleItem;
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* @type {DeclarativeStyleItem}
|
|
564
|
+
*/
|
|
565
|
+
export const defaultDeclarativeStyle = new DeclarativeStyleItem({
|
|
566
|
+
declarativeStyle: {
|
|
567
|
+
show: true,
|
|
568
|
+
color: {
|
|
569
|
+
conditions: getDefaultCondition('olcs_color', true),
|
|
570
|
+
},
|
|
571
|
+
scale: {
|
|
572
|
+
conditions: getDefaultCondition('olcs_scale'),
|
|
573
|
+
},
|
|
574
|
+
pointOutlineWidth: {
|
|
575
|
+
conditions: getDefaultCondition('olcs_outlineWidth'),
|
|
576
|
+
},
|
|
577
|
+
pointOutlineColor: {
|
|
578
|
+
conditions: getDefaultCondition('olcs_outlineColor', true),
|
|
579
|
+
},
|
|
580
|
+
pointSize: {
|
|
581
|
+
conditions: getDefaultCondition('olcs_pointSize'),
|
|
582
|
+
},
|
|
583
|
+
image: {
|
|
584
|
+
conditions: getDefaultCondition('olcs_image'),
|
|
585
|
+
},
|
|
586
|
+
font: {
|
|
587
|
+
conditions: getDefaultCondition('olcs_font'),
|
|
588
|
+
},
|
|
589
|
+
labelStyle: '2',
|
|
590
|
+
labelText: {
|
|
591
|
+
conditions: getDefaultCondition('olcs_labelText'),
|
|
592
|
+
},
|
|
593
|
+
labelColor: {
|
|
594
|
+
conditions: getDefaultCondition('olcs_fontColor', true),
|
|
595
|
+
},
|
|
596
|
+
labelOutlineWidth: {
|
|
597
|
+
conditions: getDefaultCondition('olcs_fontOutlineWidth'),
|
|
598
|
+
},
|
|
599
|
+
labelOutlineColor: {
|
|
600
|
+
conditions: getDefaultCondition('olcs_fontOutlineColor', true),
|
|
601
|
+
},
|
|
602
|
+
/*
|
|
603
|
+
anchorLineEnabled: {
|
|
604
|
+
conditions: [
|
|
605
|
+
[
|
|
606
|
+
defaultExtrudedHeightCondition,
|
|
607
|
+
'true',
|
|
608
|
+
],
|
|
609
|
+
['true', 'false'],
|
|
610
|
+
],
|
|
611
|
+
},
|
|
612
|
+
anchorLineColor: {
|
|
613
|
+
conditions: getDefaultCondition('olcs_anchorLineColor', true),
|
|
614
|
+
},
|
|
615
|
+
heightOffset: {
|
|
616
|
+
conditions: [
|
|
617
|
+
[
|
|
618
|
+
defaultExtrudedHeightCondition,
|
|
619
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
620
|
+
'${attributes.olcs_extrudedHeight}',
|
|
621
|
+
],
|
|
622
|
+
['true', '0'],
|
|
623
|
+
],
|
|
624
|
+
},
|
|
625
|
+
*/
|
|
626
|
+
verticalOrigin: '1',
|
|
627
|
+
horizontalOrigin: '0',
|
|
628
|
+
labelHorizontalOrigin: '0',
|
|
629
|
+
labelVerticalOrigin: '1',
|
|
630
|
+
},
|
|
631
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import Fill from 'ol/style/Fill.js';
|
|
2
|
+
import Stroke from 'ol/style/Stroke.js';
|
|
3
|
+
import RegularShape from 'ol/style/RegularShape.js';
|
|
4
|
+
import Circle from 'ol/style/Circle.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {VectorStyleItemImage} options
|
|
8
|
+
* @returns {import("ol/style/RegularShape").default|import("ol/style/Circle").default}
|
|
9
|
+
* @export
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export function getShapeFromOptions(options) {
|
|
13
|
+
if (options.fill && !(options.fill instanceof Fill)) {
|
|
14
|
+
options.fill = new Fill(options.fill);
|
|
15
|
+
}
|
|
16
|
+
if (options.stroke && !(options.stroke instanceof Stroke)) {
|
|
17
|
+
options.stroke = new Stroke(options.stroke);
|
|
18
|
+
}
|
|
19
|
+
return options.points ?
|
|
20
|
+
new RegularShape(/** @type {import("ol/style/RegularShape").Options} */ (options)) :
|
|
21
|
+
new Circle(/** @type {import("ol/style/Circle").Options} */ (options));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @class
|
|
26
|
+
*/
|
|
27
|
+
class ShapeCategory {
|
|
28
|
+
constructor() {
|
|
29
|
+
/** @type {Array<VectorStyleItemImage>} */
|
|
30
|
+
this.shapes = [];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @param {VectorStyleItemImage} options
|
|
35
|
+
*/
|
|
36
|
+
addImage(options) {
|
|
37
|
+
const shape = getShapeFromOptions({ ...options });
|
|
38
|
+
|
|
39
|
+
const canvas = /** @type {HTMLCanvasElement} */ (shape.getImage(1));
|
|
40
|
+
options.src = canvas.toDataURL();
|
|
41
|
+
this.shapes.push(options);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @export
|
|
47
|
+
* TODO refactor to getdefaultShapeCategory...
|
|
48
|
+
*/
|
|
49
|
+
export const shapeCategory = new ShapeCategory();
|
|
50
|
+
const defaultShapeOptions = {
|
|
51
|
+
fill: new Fill({ color: [255, 255, 255, 1] }),
|
|
52
|
+
stroke: new Stroke({ color: [0, 0, 0, 1], width: 1 }),
|
|
53
|
+
radius: 16,
|
|
54
|
+
};
|
|
55
|
+
[
|
|
56
|
+
null,
|
|
57
|
+
{ points: 3 },
|
|
58
|
+
{ points: 3, angle: Math.PI },
|
|
59
|
+
{ points: 4, angle: Math.PI / 4 },
|
|
60
|
+
{ points: 6 },
|
|
61
|
+
].forEach((additionalOptions) => {
|
|
62
|
+
const shapeOptions = additionalOptions ?
|
|
63
|
+
Object.assign(additionalOptions, defaultShapeOptions) :
|
|
64
|
+
defaultShapeOptions;
|
|
65
|
+
|
|
66
|
+
shapeCategory.addImage(shapeOptions);
|
|
67
|
+
});
|