@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,48 @@
|
|
|
1
|
+
import { getLogger as getLoggerByName } from '@vcsuite/logger';
|
|
2
|
+
import StyleItem, { StyleType } from './styleItem.js';
|
|
3
|
+
import DeclarativeStyleItem, { defaultDeclarativeStyle } from './declarativeStyleItem.js';
|
|
4
|
+
import VectorStyleItem from './vectorStyleItem.js';
|
|
5
|
+
import { styleCollection } from '../../globalCollections.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @returns {import("@vcsuite/logger").Logger}
|
|
9
|
+
*/
|
|
10
|
+
function getLogger() {
|
|
11
|
+
return getLoggerByName('vcs.vcm.util.style.styleFactory');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @param {(Reference|DeclarativeStyleItemOptions|VectorStyleItemOptions|StyleItem|string)=} styleOptions
|
|
16
|
+
* @param {(VectorStyleItem|DeclarativeStyleItem)=} defaultStyle
|
|
17
|
+
* @returns {StyleItem}
|
|
18
|
+
*/
|
|
19
|
+
// eslint-disable-next-line import/prefer-default-export
|
|
20
|
+
export function getStyleOrDefaultStyle(styleOptions, defaultStyle) {
|
|
21
|
+
if (typeof styleOptions === 'string') {
|
|
22
|
+
const styleItem = styleCollection.getByKey(styleOptions);
|
|
23
|
+
if (styleItem) {
|
|
24
|
+
return styleItem;
|
|
25
|
+
}
|
|
26
|
+
getLogger().warning(`could not find style with name ${styleOptions}`);
|
|
27
|
+
} else if (styleOptions && (styleOptions instanceof StyleItem)) {
|
|
28
|
+
return styleOptions;
|
|
29
|
+
} else if (styleOptions) { // DeclarativeStyleItemOptions || VectorStyleItemOptions || ClusterStyleItemOptions
|
|
30
|
+
if (
|
|
31
|
+
/** @type {DeclarativeStyleItemOptions} */ (styleOptions).type === StyleType.DECLARATIVE ||
|
|
32
|
+
/** @type {DeclarativeStyleItemOptions} */ (styleOptions).declarativeStyle) {
|
|
33
|
+
return new DeclarativeStyleItem(/** @type {DeclarativeStyleItemOptions} */ (styleOptions));
|
|
34
|
+
} else if (/** @type {Reference} */ (styleOptions).type === StyleType.REFERENCE) {
|
|
35
|
+
const { name } = /** @type {Reference} */ (styleOptions);
|
|
36
|
+
const styleItem = styleCollection.getByKey(name);
|
|
37
|
+
if (styleItem) {
|
|
38
|
+
return styleItem;
|
|
39
|
+
}
|
|
40
|
+
getLogger().warning(`could not find style with name ${name}`);
|
|
41
|
+
} else {
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
const vectorStyle = new VectorStyleItem(/** @type {VectorStyleItemOptions} */ styleOptions);
|
|
44
|
+
return defaultStyle instanceof VectorStyleItem ? defaultStyle.assign(vectorStyle) : vectorStyle;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return defaultStyle || defaultDeclarativeStyle.clone();
|
|
48
|
+
}
|
|
@@ -0,0 +1,555 @@
|
|
|
1
|
+
import { DEVICE_PIXEL_RATIO } from 'ol/has.js';
|
|
2
|
+
import Fill from 'ol/style/Fill.js';
|
|
3
|
+
import Stroke from 'ol/style/Stroke.js';
|
|
4
|
+
import OLText from 'ol/style/Text.js';
|
|
5
|
+
import Style from 'ol/style/Style.js';
|
|
6
|
+
import { Color } from '@vcmap/cesium';
|
|
7
|
+
|
|
8
|
+
import { getLogger as getLoggerByName } from '@vcsuite/logger';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @returns {import("@vcsuite/logger").Logger}
|
|
12
|
+
*/
|
|
13
|
+
function getLogger() {
|
|
14
|
+
return getLoggerByName('vcs.vcm.util.style.StyleHelpers');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @typedef {Object} FontObject
|
|
19
|
+
* @property {string} fontStyle
|
|
20
|
+
* @property {string} fontSize
|
|
21
|
+
* @property {string} fontFamily
|
|
22
|
+
* @property {string} fontWeight
|
|
23
|
+
* @property {string} fontVariant
|
|
24
|
+
* @property {string} lineHeight
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @enum {number}
|
|
29
|
+
* @const
|
|
30
|
+
* @export
|
|
31
|
+
* @property {number} NWSE
|
|
32
|
+
* @property {number} SWNE
|
|
33
|
+
* @property {number} DIAGONALCROSS
|
|
34
|
+
* @property {number} NS
|
|
35
|
+
* @property {number} WE
|
|
36
|
+
* @property {number} CROSS
|
|
37
|
+
* @api
|
|
38
|
+
*/
|
|
39
|
+
export const PatternType = {
|
|
40
|
+
NWSE: 1,
|
|
41
|
+
SWNE: 2,
|
|
42
|
+
DIAGONALCROSS: 3,
|
|
43
|
+
NS: 4,
|
|
44
|
+
WE: 5,
|
|
45
|
+
CROSS: 6,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Converts HEX colors to RGB
|
|
50
|
+
* @param {string} h
|
|
51
|
+
* @param {number=} opacity
|
|
52
|
+
* @returns {import("ol/color").Color}
|
|
53
|
+
* @export
|
|
54
|
+
*/
|
|
55
|
+
export function hexToOlColor(h, opacity) {
|
|
56
|
+
let hex = h.substring(1);
|
|
57
|
+
if (hex.length === 3) {
|
|
58
|
+
hex = hex.replace(/([\w\d])/g, '$1$1');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return [
|
|
62
|
+
parseInt(hex.substring(0, 2), 16),
|
|
63
|
+
parseInt(hex.substring(2, 4), 16),
|
|
64
|
+
parseInt(hex.substring(4, 6), 16),
|
|
65
|
+
opacity != null ? opacity : 1.0,
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @param {import("@vcmap/cesium").Color} cesiumColor
|
|
71
|
+
* @returns {import("ol/color").Color}
|
|
72
|
+
*/
|
|
73
|
+
export function cesiumColorToColor(cesiumColor) {
|
|
74
|
+
const color = cesiumColor.toBytes();
|
|
75
|
+
color[3] /= 255;
|
|
76
|
+
return /** @type {import("ol/color").Color} */ (color);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* converts an openlayers color to a cesium Color
|
|
81
|
+
* @param {import("ol/color").Color} olColor
|
|
82
|
+
* @returns {import("@vcmap/cesium").Color}
|
|
83
|
+
* @api
|
|
84
|
+
* @export
|
|
85
|
+
*/
|
|
86
|
+
export function olColorToCesiumColor(olColor) {
|
|
87
|
+
return Color.fromBytes(olColor[0], olColor[1], olColor[2], olColor[3] * 255);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* parses a color to an openlayers color
|
|
92
|
+
* @param {import("ol/color").Color|import("ol/colorlike").ColorLike|Array<number>} color
|
|
93
|
+
* @param {import("ol/color").Color=} defaultColor
|
|
94
|
+
* @returns {import("ol/color").Color}
|
|
95
|
+
* @api
|
|
96
|
+
* @export
|
|
97
|
+
*/
|
|
98
|
+
export function parseColor(color, defaultColor) {
|
|
99
|
+
if (Array.isArray(color)) {
|
|
100
|
+
if (color.length === 3) {
|
|
101
|
+
color.push(1.0);
|
|
102
|
+
}
|
|
103
|
+
return /** @type {import("ol/color").Color} */ (color);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (typeof color === 'string') {
|
|
107
|
+
if (/^#/.test(color)) {
|
|
108
|
+
return hexToOlColor(color);
|
|
109
|
+
}
|
|
110
|
+
if (/^rgba?\((\d+(,\s?)?){3}((0|1)(\.\d+)?)?\)/.test(color)) {
|
|
111
|
+
const output = color
|
|
112
|
+
.replace(/^rgba?\(([\s\S]+?)\)/, '$1')
|
|
113
|
+
.replace(/\s/, '')
|
|
114
|
+
.split(',')
|
|
115
|
+
.map(n => Number(n));
|
|
116
|
+
|
|
117
|
+
if (output.length === 3) {
|
|
118
|
+
output.push(1.0);
|
|
119
|
+
}
|
|
120
|
+
return /** @type {import("ol/color").Color} */ (output);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (color instanceof CanvasPattern) {
|
|
125
|
+
return [255, 255, 255, 0.4];
|
|
126
|
+
}
|
|
127
|
+
if (defaultColor) {
|
|
128
|
+
return defaultColor;
|
|
129
|
+
}
|
|
130
|
+
throw new Error(`Cannot parse color ${color}`);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
*
|
|
135
|
+
* @param {import("ol/color").Color|import("ol/colorlike").ColorLike} color
|
|
136
|
+
* @param {import("ol/color").Color} defaultColor
|
|
137
|
+
* @returns {import("@vcmap/cesium").Color}
|
|
138
|
+
* @export
|
|
139
|
+
*/
|
|
140
|
+
export function getCesiumColor(color, defaultColor) {
|
|
141
|
+
const olColor = parseColor(color, defaultColor);
|
|
142
|
+
return Color.fromBytes(olColor[0], olColor[1], olColor[2], olColor[3] * 255);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* @param {import("ol/color").Color|Array<number>|import("ol/colorlike").ColorLike} color
|
|
147
|
+
* @returns {string}
|
|
148
|
+
* @export
|
|
149
|
+
*/
|
|
150
|
+
export function getStringColor(color) {
|
|
151
|
+
return `rgba(${parseColor(color).join(',')})`;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* @param {VectorStyleItemFill} options
|
|
156
|
+
* @param {HTMLCanvasElement=} optCanvas
|
|
157
|
+
* @returns {CanvasPattern}
|
|
158
|
+
* @export
|
|
159
|
+
*/
|
|
160
|
+
export function createPattern(options, optCanvas) {
|
|
161
|
+
const pixelRatio = DEVICE_PIXEL_RATIO;
|
|
162
|
+
|
|
163
|
+
const canvas = optCanvas || document.createElement('canvas');
|
|
164
|
+
if (!optCanvas || !canvas.width) {
|
|
165
|
+
canvas.width = (options.pattern.size || 10) * pixelRatio;
|
|
166
|
+
canvas.height = (options.pattern.size || 10) * pixelRatio;
|
|
167
|
+
}
|
|
168
|
+
const ctx = canvas.getContext('2d');
|
|
169
|
+
const size = canvas.width;
|
|
170
|
+
|
|
171
|
+
ctx.fillStyle = getStringColor(options.color);
|
|
172
|
+
ctx.fillRect(0, 0, size, size);
|
|
173
|
+
|
|
174
|
+
function drawLineOnCanvas(start, end) {
|
|
175
|
+
ctx.strokeStyle = getStringColor(options.pattern.color);
|
|
176
|
+
ctx.lineWidth = options.pattern.width;
|
|
177
|
+
ctx.lineCap = 'square';
|
|
178
|
+
ctx.beginPath();
|
|
179
|
+
ctx.moveTo(start[0], start[1]);
|
|
180
|
+
ctx.lineTo(end[0], end[1]);
|
|
181
|
+
ctx.stroke();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
switch (options.pattern.type) {
|
|
185
|
+
case 1:
|
|
186
|
+
drawLineOnCanvas([size / 2, size], [size, size / 2]);
|
|
187
|
+
drawLineOnCanvas([0, size / 2], [size / 2, 0]);
|
|
188
|
+
break;
|
|
189
|
+
case 2:
|
|
190
|
+
drawLineOnCanvas([size / 2, size], [0, size / 2]);
|
|
191
|
+
drawLineOnCanvas([size, size / 2], [size / 2, 0]);
|
|
192
|
+
break;
|
|
193
|
+
case 3:
|
|
194
|
+
drawLineOnCanvas([size / 2, size], [size, size / 2]);
|
|
195
|
+
drawLineOnCanvas([0, size / 2], [size / 2, 0]);
|
|
196
|
+
drawLineOnCanvas([size / 2, size], [0, size / 2]);
|
|
197
|
+
drawLineOnCanvas([size, size / 2], [size / 2, 0]);
|
|
198
|
+
break;
|
|
199
|
+
case 4:
|
|
200
|
+
drawLineOnCanvas([size / 2, 0], [size / 2, size]);
|
|
201
|
+
break;
|
|
202
|
+
case 5:
|
|
203
|
+
drawLineOnCanvas([0, size / 2], [size, size / 2]);
|
|
204
|
+
break;
|
|
205
|
+
case 6:
|
|
206
|
+
drawLineOnCanvas([size / 2, 0], [size / 2, size]);
|
|
207
|
+
drawLineOnCanvas([0, size / 2], [size, size / 2]);
|
|
208
|
+
break;
|
|
209
|
+
default:
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
return ctx.createPattern(canvas, 'repeat');
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* @param {import("ol/color").Color} color
|
|
217
|
+
* @returns {string}
|
|
218
|
+
* @export
|
|
219
|
+
*/
|
|
220
|
+
export function olColorToHex(color) {
|
|
221
|
+
function componentHex(c) {
|
|
222
|
+
const hex = c.toString(16);
|
|
223
|
+
return hex.length === 1 ? `0${hex}` : hex;
|
|
224
|
+
}
|
|
225
|
+
return color
|
|
226
|
+
.slice(0, 3)
|
|
227
|
+
.reduce((prev, val) => `${prev}${componentHex(val)}`, '#');
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* @param {string} colorValue
|
|
232
|
+
* @returns {boolean}
|
|
233
|
+
* @export
|
|
234
|
+
*/
|
|
235
|
+
export function validateHexColor(colorValue) {
|
|
236
|
+
return /^#[0-9a-f]{6}$/.test(colorValue);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* @param {string|FontObject} font
|
|
241
|
+
* @returns {FontObject}
|
|
242
|
+
* @export
|
|
243
|
+
*/
|
|
244
|
+
export function parseFont(font) {
|
|
245
|
+
if (typeof font !== 'string') {
|
|
246
|
+
return font;
|
|
247
|
+
}
|
|
248
|
+
let fontFamily = null;
|
|
249
|
+
let fontSize = null;
|
|
250
|
+
let fontStyle = 'normal';
|
|
251
|
+
let fontWeight = 'normal';
|
|
252
|
+
let fontVariant = 'normal';
|
|
253
|
+
let lineHeight = 'normal';
|
|
254
|
+
|
|
255
|
+
font.split(/\s+/).forEach((element) => {
|
|
256
|
+
switch (element) {
|
|
257
|
+
case 'normal':
|
|
258
|
+
break;
|
|
259
|
+
|
|
260
|
+
case 'italic':
|
|
261
|
+
case 'oblique':
|
|
262
|
+
fontStyle = element;
|
|
263
|
+
break;
|
|
264
|
+
|
|
265
|
+
case 'small-caps':
|
|
266
|
+
fontVariant = element;
|
|
267
|
+
break;
|
|
268
|
+
|
|
269
|
+
case 'bold':
|
|
270
|
+
case 'bolder':
|
|
271
|
+
case 'lighter':
|
|
272
|
+
case '100':
|
|
273
|
+
case '200':
|
|
274
|
+
case '300':
|
|
275
|
+
case '400':
|
|
276
|
+
case '500':
|
|
277
|
+
case '600':
|
|
278
|
+
case '700':
|
|
279
|
+
case '800':
|
|
280
|
+
case '900':
|
|
281
|
+
fontWeight = element;
|
|
282
|
+
break;
|
|
283
|
+
|
|
284
|
+
default:
|
|
285
|
+
if (!fontSize) {
|
|
286
|
+
const parts = element.split('/');
|
|
287
|
+
fontSize = parts[0];
|
|
288
|
+
if (parts.length > 1) lineHeight = parts[1];
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
if (!fontFamily) {
|
|
292
|
+
fontFamily = element;
|
|
293
|
+
} else {
|
|
294
|
+
fontFamily = `${fontFamily} ${element}`;
|
|
295
|
+
}
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
return {
|
|
301
|
+
fontStyle,
|
|
302
|
+
fontVariant,
|
|
303
|
+
fontWeight,
|
|
304
|
+
fontSize,
|
|
305
|
+
lineHeight,
|
|
306
|
+
fontFamily,
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* @param {FontObject} fontObject
|
|
312
|
+
* @returns {string}
|
|
313
|
+
* @export
|
|
314
|
+
*/
|
|
315
|
+
export function combineFont(fontObject) {
|
|
316
|
+
const order = [
|
|
317
|
+
'fontStyle',
|
|
318
|
+
'fontVariant',
|
|
319
|
+
'fontWeight',
|
|
320
|
+
'fontSize',
|
|
321
|
+
'fontFamily',
|
|
322
|
+
];
|
|
323
|
+
let font = null;
|
|
324
|
+
Object.entries(fontObject)
|
|
325
|
+
.filter(e => e[1] !== 'normal' && e[0] !== 'lineWeight')
|
|
326
|
+
.sort((a, b) => {
|
|
327
|
+
const indexA = order.indexOf(a[0]);
|
|
328
|
+
const indexB = order.indexOf(b[0]);
|
|
329
|
+
if (indexA < indexB) {
|
|
330
|
+
return -1;
|
|
331
|
+
}
|
|
332
|
+
if (indexA > indexB) {
|
|
333
|
+
return 1;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
return 0;
|
|
337
|
+
})
|
|
338
|
+
.forEach((e) => {
|
|
339
|
+
if (!font) {
|
|
340
|
+
font = e[1];
|
|
341
|
+
} else {
|
|
342
|
+
font = `${font} ${e[1]}`;
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
return font || '';
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* tints the given canvas to the specified color
|
|
351
|
+
* @param {CanvasRenderingContext2D} canvasContext
|
|
352
|
+
* @param {import("ol/color").Color} color
|
|
353
|
+
* @param {import("ol/size").Size} size
|
|
354
|
+
* @param {import("ol/size").Size} [optOrigin=[0, 0]]
|
|
355
|
+
*/
|
|
356
|
+
export function colorInCanvas(canvasContext, color, size, optOrigin) {
|
|
357
|
+
const origin = optOrigin || [0, 0];
|
|
358
|
+
const imgData = canvasContext.getImageData(origin[0], origin[1], size[0], size[1]);
|
|
359
|
+
const { data } = imgData;
|
|
360
|
+
const [r, g, b] = color;
|
|
361
|
+
const ii = data.length;
|
|
362
|
+
|
|
363
|
+
for (let i = 0; i < ii; i += 4) {
|
|
364
|
+
data[i] = r;
|
|
365
|
+
data[i + 1] = g;
|
|
366
|
+
data[i + 2] = b;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
canvasContext.putImageData(imgData, origin[0], origin[1]);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* @param {import("ol/style/Text").default|import("ol/style/RegularShape").default} item
|
|
374
|
+
* @returns {import("ol/style/Fill").Options|undefined} // XXX FillOptions?
|
|
375
|
+
*/
|
|
376
|
+
export function getFillOptions(item) {
|
|
377
|
+
if (item.getFill()) {
|
|
378
|
+
let color = item.getFill().getColor();
|
|
379
|
+
try {
|
|
380
|
+
color = /** @type {import("ol/color").Color} */ (parseColor(color).slice());
|
|
381
|
+
} catch (e) {
|
|
382
|
+
getLogger().warning(e.message);
|
|
383
|
+
}
|
|
384
|
+
return { color };
|
|
385
|
+
}
|
|
386
|
+
return undefined;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* @param {import("ol/style/Stroke").default} stroke
|
|
391
|
+
* @returns {import("ol/style/Stroke").Options}
|
|
392
|
+
*/
|
|
393
|
+
export function getStrokeOptions(stroke) {
|
|
394
|
+
let color = stroke.getColor();
|
|
395
|
+
if (color) {
|
|
396
|
+
try {
|
|
397
|
+
color = /** @type {import("ol/color").Color} */ (parseColor(color).slice());
|
|
398
|
+
} catch (e) {
|
|
399
|
+
getLogger().warning(e.message);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
return {
|
|
403
|
+
color,
|
|
404
|
+
width: stroke.getWidth(),
|
|
405
|
+
lineDash: stroke.getLineDash(),
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* @param {import("ol/style/Text").default} text
|
|
411
|
+
* @returns {VectorStyleItemText}
|
|
412
|
+
*/
|
|
413
|
+
export function getTextOptions(text) {
|
|
414
|
+
return {
|
|
415
|
+
font: text.getFont(),
|
|
416
|
+
fill: getFillOptions(text),
|
|
417
|
+
stroke: text.getStroke() ? getStrokeOptions(text.getStroke()) : undefined,
|
|
418
|
+
textBaseline: text.getTextBaseline(),
|
|
419
|
+
offsetY: text.getOffsetY(),
|
|
420
|
+
offsetX: text.getOffsetX(),
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* @param {VectorStyleItemText} options
|
|
426
|
+
* @returns {import("ol/style/Text").default}
|
|
427
|
+
*/
|
|
428
|
+
export function getTextFromOptions(options) {
|
|
429
|
+
const textOptions = { ...options };
|
|
430
|
+
if (textOptions.fill && !(textOptions.fill instanceof Fill)) {
|
|
431
|
+
textOptions.fill = new Fill(textOptions.fill);
|
|
432
|
+
}
|
|
433
|
+
if (textOptions.stroke && !(textOptions.stroke instanceof Stroke)) {
|
|
434
|
+
textOptions.stroke = new Stroke(textOptions.stroke);
|
|
435
|
+
}
|
|
436
|
+
if (textOptions.font && typeof textOptions.font !== 'string') {
|
|
437
|
+
textOptions.font = combineFont(textOptions.font);
|
|
438
|
+
}
|
|
439
|
+
return new OLText(/** @type {import("ol/style/Text").Options} */ (textOptions));
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* @param {import("ol/style/Text").default} textStyle
|
|
444
|
+
* @returns {{font: string, textShadow: string|undefined, color: string|undefined}}
|
|
445
|
+
*/
|
|
446
|
+
export function getCssStyleFromTextStyle(textStyle) {
|
|
447
|
+
const style = {
|
|
448
|
+
font: textStyle.getFont(),
|
|
449
|
+
textShadow: undefined,
|
|
450
|
+
color: undefined,
|
|
451
|
+
};
|
|
452
|
+
if (textStyle.getStroke()) {
|
|
453
|
+
let width = textStyle.getStroke().getWidth();
|
|
454
|
+
width = width > 1 ? 1 : width;
|
|
455
|
+
const color = olColorToHex(parseColor(textStyle.getStroke().getColor()));
|
|
456
|
+
style.textShadow = `-${width}px ${width}px 0 ${color},${width}px ${width}px 0 ${color},${width}px -${width}px 0 ${color},-${width}px -${width}px 0 ${color}`;
|
|
457
|
+
}
|
|
458
|
+
if (textStyle.getFill()) {
|
|
459
|
+
style.color = olColorToHex(parseColor(textStyle.getFill().getColor()));
|
|
460
|
+
}
|
|
461
|
+
return style;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/** @type {import("ol/style/Style").default} */
|
|
465
|
+
export const emptyStyle = new Style({});
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* @type {import("ol/color").Color}
|
|
469
|
+
*/
|
|
470
|
+
export const emptyColor = [0, 0, 0, 0];
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* @type {import("ol/color").Color}
|
|
474
|
+
*/
|
|
475
|
+
export const whiteColor = [255, 255, 255, 1];
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* @type {import("ol/color").Color}
|
|
479
|
+
*/
|
|
480
|
+
export const blackColor = [0, 0, 0, 1];
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* @returns {VectorStyleItemOptions}
|
|
484
|
+
*/
|
|
485
|
+
export function getDefaultVectorStyleItemOptions() {
|
|
486
|
+
return {
|
|
487
|
+
image: {
|
|
488
|
+
fill: {
|
|
489
|
+
color: [255, 255, 255, 0.4],
|
|
490
|
+
},
|
|
491
|
+
stroke: {
|
|
492
|
+
color: blackColor,
|
|
493
|
+
width: 1,
|
|
494
|
+
},
|
|
495
|
+
radius: 5,
|
|
496
|
+
},
|
|
497
|
+
stroke: {
|
|
498
|
+
color: [51, 153, 204, 1],
|
|
499
|
+
width: 1.25,
|
|
500
|
+
},
|
|
501
|
+
fill: {
|
|
502
|
+
color: [255, 255, 255, 0.4],
|
|
503
|
+
},
|
|
504
|
+
text: {
|
|
505
|
+
font: 'bold 18px sans-serif',
|
|
506
|
+
textBaseline: 'bottom',
|
|
507
|
+
offsetY: -15,
|
|
508
|
+
offsetX: 0,
|
|
509
|
+
},
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* default Values @see https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/3d-tiles-next/Styling
|
|
516
|
+
* @type {Object<string,string>}
|
|
517
|
+
*/
|
|
518
|
+
const default3DTileStyleValues = {
|
|
519
|
+
olcs_color: getStringColor(whiteColor),
|
|
520
|
+
olcs_scale: '1.0',
|
|
521
|
+
olcs_outlineWidth: '0.0',
|
|
522
|
+
olcs_outlineColor: getStringColor(blackColor),
|
|
523
|
+
olcs_pointSize: '8.0',
|
|
524
|
+
olcs_image: undefined,
|
|
525
|
+
olcs_font: `'${getDefaultVectorStyleItemOptions().text.font}'`,
|
|
526
|
+
olcs_fontColor: getStringColor(blackColor),
|
|
527
|
+
olcs_fontOutlineWidth: '1.0',
|
|
528
|
+
olcs_fontOutlineColor: getStringColor(whiteColor),
|
|
529
|
+
olcs_labelText: undefined,
|
|
530
|
+
olcs_anchorLineColor: getStringColor(whiteColor),
|
|
531
|
+
};
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* returns the cesium3DTilesetStyle Condition with the value as the given Attribute
|
|
536
|
+
* The condition checks for undefined and null
|
|
537
|
+
* @param {string} attribute
|
|
538
|
+
* @param {boolean=} isColor
|
|
539
|
+
* @returns {Array<Array<string>>}
|
|
540
|
+
*/
|
|
541
|
+
export function getDefaultCondition(attribute, isColor) {
|
|
542
|
+
const condition = `Boolean(\${${attribute}})===true`;
|
|
543
|
+
const value = isColor ? `color(\${${attribute}})` : `\${${attribute}}`;
|
|
544
|
+
return [
|
|
545
|
+
[condition, value],
|
|
546
|
+
['true', default3DTileStyleValues[attribute]],
|
|
547
|
+
];
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* @type {string}
|
|
552
|
+
*/
|
|
553
|
+
export const defaultExtrudedHeightCondition =
|
|
554
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
555
|
+
'${attributes} !== undefined && ${attributes} !== null && ${attributes.olcs_extrudedHeight} !== undefined && ${attributes.olcs_extrudedHeight}!==null';
|