itowns 2.44.3-next.9 → 2.45.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/README.md +3 -129
- package/examples/3dtiles_loader.html +20 -6
- package/examples/config.json +1 -0
- package/examples/copc_simple_loader.html +15 -5
- package/examples/effects_stereo.html +2 -2
- package/examples/entwine_3d_loader.html +3 -1
- package/examples/entwine_simple_loader.html +1 -1
- package/examples/images/itowns_logo.svg +123 -0
- package/examples/js/plugins/COGParser.js +1 -1
- package/examples/jsm/OGC3DTilesHelper.js +6 -1
- package/examples/layers/JSONLayers/GeoidMNT.json +3 -1
- package/examples/misc_collada.html +2 -2
- package/examples/source_file_geojson_3d.html +0 -1
- package/examples/source_file_kml_raster_usgs.html +0 -1
- package/examples/source_stream_wfs_raster.html +0 -7
- package/examples/vector_tile_mapbox_raster.html +91 -0
- package/examples/view_3d_map_webxr.html +3 -1
- package/examples/view_multi_25d.html +2 -2
- package/package.json +21 -75
- package/CODING.md +0 -120
- package/CONTRIBUTING.md +0 -150
- package/CONTRIBUTORS.md +0 -55
- package/LICENSE.md +0 -44
- package/changelog.md +0 -1361
- package/dist/455.js +0 -2
- package/dist/455.js.map +0 -1
- package/dist/debug.js +0 -3
- package/dist/debug.js.LICENSE.txt +0 -13
- package/dist/debug.js.map +0 -1
- package/dist/itowns.js +0 -3
- package/dist/itowns.js.LICENSE.txt +0 -7
- package/dist/itowns.js.map +0 -1
- package/dist/itowns_lasparser.js +0 -2
- package/dist/itowns_lasparser.js.map +0 -1
- package/dist/itowns_lasworker.js +0 -2
- package/dist/itowns_lasworker.js.map +0 -1
- package/dist/itowns_potree2worker.js +0 -2
- package/dist/itowns_potree2worker.js.map +0 -1
- package/dist/itowns_widgets.js +0 -2
- package/dist/itowns_widgets.js.map +0 -1
- package/examples/.eslintrc.cjs +0 -35
- package/examples/jsm/.eslintrc.cjs +0 -38
- package/lib/Controls/FirstPersonControls.js +0 -308
- package/lib/Controls/FlyControls.js +0 -175
- package/lib/Controls/GlobeControls.js +0 -1162
- package/lib/Controls/PlanarControls.js +0 -1025
- package/lib/Controls/StateControl.js +0 -429
- package/lib/Controls/StreetControls.js +0 -392
- package/lib/Converter/Feature2Mesh.js +0 -615
- package/lib/Converter/Feature2Texture.js +0 -170
- package/lib/Converter/convertToTile.js +0 -75
- package/lib/Converter/textureConverter.js +0 -44
- package/lib/Core/3DTiles/C3DTBatchTable.js +0 -131
- package/lib/Core/3DTiles/C3DTBatchTableHierarchyExtension.js +0 -96
- package/lib/Core/3DTiles/C3DTBoundingVolume.js +0 -157
- package/lib/Core/3DTiles/C3DTExtensions.js +0 -97
- package/lib/Core/3DTiles/C3DTFeature.js +0 -110
- package/lib/Core/3DTiles/C3DTilesEnums.js +0 -20
- package/lib/Core/3DTiles/C3DTileset.js +0 -99
- package/lib/Core/3DTiles/utils/BinaryPropertyAccessor.js +0 -100
- package/lib/Core/AnimationPlayer.js +0 -142
- package/lib/Core/CopcNode.js +0 -174
- package/lib/Core/Deprecated/Undeprecator.js +0 -75
- package/lib/Core/EntwinePointTileNode.js +0 -126
- package/lib/Core/Feature.js +0 -490
- package/lib/Core/Geographic/CoordStars.js +0 -80
- package/lib/Core/Geographic/Coordinates.js +0 -320
- package/lib/Core/Geographic/Crs.js +0 -175
- package/lib/Core/Geographic/Extent.js +0 -534
- package/lib/Core/Geographic/GeoidGrid.js +0 -109
- package/lib/Core/Label.js +0 -222
- package/lib/Core/MainLoop.js +0 -211
- package/lib/Core/Math/Ellipsoid.js +0 -144
- package/lib/Core/Picking.js +0 -255
- package/lib/Core/PointCloudNode.js +0 -42
- package/lib/Core/Potree2Node.js +0 -206
- package/lib/Core/Potree2PointAttributes.js +0 -139
- package/lib/Core/PotreeNode.js +0 -101
- package/lib/Core/Prefab/Globe/Atmosphere.js +0 -299
- package/lib/Core/Prefab/Globe/BuilderEllipsoidTile.js +0 -110
- package/lib/Core/Prefab/Globe/GlobeLayer.js +0 -145
- package/lib/Core/Prefab/Globe/SkyShader.js +0 -78
- package/lib/Core/Prefab/GlobeView.js +0 -161
- package/lib/Core/Prefab/Planar/PlanarLayer.js +0 -53
- package/lib/Core/Prefab/Planar/PlanarTileBuilder.js +0 -72
- package/lib/Core/Prefab/PlanarView.js +0 -62
- package/lib/Core/Prefab/TileBuilder.js +0 -80
- package/lib/Core/Prefab/computeBufferTileGeometry.js +0 -183
- package/lib/Core/Scheduler/Cache.js +0 -256
- package/lib/Core/Scheduler/CancelledCommandException.js +0 -15
- package/lib/Core/Scheduler/Scheduler.js +0 -294
- package/lib/Core/Style.js +0 -1121
- package/lib/Core/System/Capabilities.js +0 -63
- package/lib/Core/Tile/Tile.js +0 -219
- package/lib/Core/Tile/TileGrid.js +0 -46
- package/lib/Core/TileGeometry.js +0 -40
- package/lib/Core/TileMesh.js +0 -109
- package/lib/Core/View.js +0 -1109
- package/lib/Layer/C3DTilesLayer.js +0 -456
- package/lib/Layer/ColorLayer.js +0 -128
- package/lib/Layer/CopcLayer.js +0 -58
- package/lib/Layer/ElevationLayer.js +0 -107
- package/lib/Layer/EntwinePointTileLayer.js +0 -64
- package/lib/Layer/FeatureGeometryLayer.js +0 -63
- package/lib/Layer/GeoidLayer.js +0 -80
- package/lib/Layer/GeometryLayer.js +0 -202
- package/lib/Layer/InfoLayer.js +0 -64
- package/lib/Layer/LabelLayer.js +0 -456
- package/lib/Layer/Layer.js +0 -304
- package/lib/Layer/LayerUpdateState.js +0 -89
- package/lib/Layer/LayerUpdateStrategy.js +0 -80
- package/lib/Layer/OGC3DTilesLayer.js +0 -412
- package/lib/Layer/OrientedImageLayer.js +0 -222
- package/lib/Layer/PointCloudLayer.js +0 -359
- package/lib/Layer/Potree2Layer.js +0 -164
- package/lib/Layer/PotreeLayer.js +0 -65
- package/lib/Layer/RasterLayer.js +0 -27
- package/lib/Layer/ReferencingLayerProperties.js +0 -62
- package/lib/Layer/TiledGeometryLayer.js +0 -403
- package/lib/Loader/LASLoader.js +0 -193
- package/lib/Loader/Potree2BrotliLoader.js +0 -261
- package/lib/Loader/Potree2Loader.js +0 -207
- package/lib/Main.js +0 -115
- package/lib/MainBundle.js +0 -4
- package/lib/Parser/B3dmParser.js +0 -174
- package/lib/Parser/CameraCalibrationParser.js +0 -94
- package/lib/Parser/GDFParser.js +0 -72
- package/lib/Parser/GTXParser.js +0 -75
- package/lib/Parser/GeoJsonParser.js +0 -212
- package/lib/Parser/GpxParser.js +0 -25
- package/lib/Parser/ISGParser.js +0 -71
- package/lib/Parser/KMLParser.js +0 -25
- package/lib/Parser/LASParser.js +0 -137
- package/lib/Parser/MapBoxUrlParser.js +0 -83
- package/lib/Parser/PntsParser.js +0 -131
- package/lib/Parser/Potree2BinParser.js +0 -92
- package/lib/Parser/PotreeBinParser.js +0 -106
- package/lib/Parser/PotreeCinParser.js +0 -29
- package/lib/Parser/ShapefileParser.js +0 -78
- package/lib/Parser/VectorTileParser.js +0 -202
- package/lib/Parser/XbilParser.js +0 -119
- package/lib/Parser/deprecated/LegacyGLTFLoader.js +0 -1386
- package/lib/Parser/iGLTFLoader.js +0 -168
- package/lib/Process/3dTilesProcessing.js +0 -304
- package/lib/Process/FeatureProcessing.js +0 -76
- package/lib/Process/LayeredMaterialNodeProcessing.js +0 -221
- package/lib/Process/ObjectRemovalHelper.js +0 -97
- package/lib/Process/handlerNodeError.js +0 -23
- package/lib/Provider/3dTilesProvider.js +0 -149
- package/lib/Provider/DataSourceProvider.js +0 -8
- package/lib/Provider/Fetcher.js +0 -229
- package/lib/Provider/PointCloudProvider.js +0 -45
- package/lib/Provider/TileProvider.js +0 -16
- package/lib/Provider/URLBuilder.js +0 -116
- package/lib/Renderer/Camera.js +0 -281
- package/lib/Renderer/Color.js +0 -56
- package/lib/Renderer/ColorLayersOrdering.js +0 -115
- package/lib/Renderer/CommonMaterial.js +0 -31
- package/lib/Renderer/Label2DRenderer.js +0 -190
- package/lib/Renderer/LayeredMaterial.js +0 -243
- package/lib/Renderer/OBB.js +0 -153
- package/lib/Renderer/OrientedImageCamera.js +0 -118
- package/lib/Renderer/OrientedImageMaterial.js +0 -167
- package/lib/Renderer/PointsMaterial.js +0 -485
- package/lib/Renderer/RasterTile.js +0 -209
- package/lib/Renderer/RenderMode.js +0 -31
- package/lib/Renderer/Shader/ShaderChunk.js +0 -160
- package/lib/Renderer/Shader/ShaderUtils.js +0 -47
- package/lib/Renderer/SphereHelper.js +0 -23
- package/lib/Renderer/WebXR.js +0 -51
- package/lib/Renderer/c3DEngine.js +0 -214
- package/lib/Source/C3DTilesGoogleSource.js +0 -74
- package/lib/Source/C3DTilesIonSource.js +0 -54
- package/lib/Source/C3DTilesSource.js +0 -30
- package/lib/Source/CopcSource.js +0 -115
- package/lib/Source/EntwinePointTileSource.js +0 -62
- package/lib/Source/FileSource.js +0 -189
- package/lib/Source/OGC3DTilesGoogleSource.js +0 -29
- package/lib/Source/OGC3DTilesIonSource.js +0 -34
- package/lib/Source/OGC3DTilesSource.js +0 -21
- package/lib/Source/OrientedImageSource.js +0 -59
- package/lib/Source/Potree2Source.js +0 -167
- package/lib/Source/PotreeSource.js +0 -82
- package/lib/Source/Source.js +0 -223
- package/lib/Source/TMSSource.js +0 -145
- package/lib/Source/VectorTilesSource.js +0 -178
- package/lib/Source/WFSSource.js +0 -168
- package/lib/Source/WMSSource.js +0 -133
- package/lib/Source/WMTSSource.js +0 -86
- package/lib/ThreeExtended/capabilities/WebGL.js +0 -69
- package/lib/ThreeExtended/libs/ktx-parse.module.js +0 -470
- package/lib/ThreeExtended/libs/zstddec.module.js +0 -29
- package/lib/ThreeExtended/loaders/DDSLoader.js +0 -200
- package/lib/ThreeExtended/loaders/DRACOLoader.js +0 -399
- package/lib/ThreeExtended/loaders/GLTFLoader.js +0 -2876
- package/lib/ThreeExtended/loaders/KTX2Loader.js +0 -625
- package/lib/ThreeExtended/utils/BufferGeometryUtils.js +0 -846
- package/lib/ThreeExtended/utils/WorkerPool.js +0 -70
- package/lib/Utils/CameraUtils.js +0 -555
- package/lib/Utils/DEMUtils.js +0 -350
- package/lib/Utils/FeaturesUtils.js +0 -156
- package/lib/Utils/Gradients.js +0 -16
- package/lib/Utils/OrientationUtils.js +0 -457
- package/lib/Utils/ThreeUtils.js +0 -115
- package/lib/Utils/gui/C3DTilesStyle.js +0 -215
- package/lib/Utils/gui/Main.js +0 -7
- package/lib/Utils/gui/Minimap.js +0 -154
- package/lib/Utils/gui/Navigation.js +0 -245
- package/lib/Utils/gui/Scale.js +0 -107
- package/lib/Utils/gui/Searchbar.js +0 -234
- package/lib/Utils/gui/Widget.js +0 -80
- package/lib/Utils/placeObjectOnGround.js +0 -137
- package/lib/Worker/LASLoaderWorker.js +0 -19
- package/lib/Worker/Potree2Worker.js +0 -21
package/lib/Core/Style.js
DELETED
|
@@ -1,1121 +0,0 @@
|
|
|
1
|
-
import { FEATURE_TYPES } from "./Feature.js";
|
|
2
|
-
import Cache from "./Scheduler/Cache.js";
|
|
3
|
-
import Fetcher from "../Provider/Fetcher.js";
|
|
4
|
-
import * as mapbox from '@mapbox/mapbox-gl-style-spec';
|
|
5
|
-
import { Color } from 'three';
|
|
6
|
-
import { deltaE } from "../Renderer/Color.js";
|
|
7
|
-
import Coordinates from "./Geographic/Coordinates.js";
|
|
8
|
-
/* babel-plugin-inline-import './StyleChunk/itowns_stroke_single_before.css' */
|
|
9
|
-
const itowns_stroke_single_before = ".itowns-stroke-single:before {\n display: var(--text_stroke_display);\n content: attr(data-before);\n opacity: 1;\n position: absolute;\n -webkit-text-stroke-width: var(--text_stroke_width);\n -webkit-text-stroke-color: var(--text_stroke_color);\n left: 0;\n right: 0;\n bottom: 0;\n top: 0;\n z-index: -1;\n white-space: inherit;\n overflow-wrap: inherit;\n letter-spacing: inherit;\n text-align: inherit;\n padding: inherit;\n font-family: inherit;\n text-transform: inherit;\n max-width: inherit;\n font-size: inherit;\n}\n";
|
|
10
|
-
const cacheStyle = new Cache();
|
|
11
|
-
const matrix = document.createElementNS('http://www.w3.org/2000/svg', 'svg').createSVGMatrix();
|
|
12
|
-
const canvas = document.createElement('canvas');
|
|
13
|
-
const inv255 = 1 / 255;
|
|
14
|
-
function baseAltitudeDefault(properties, ctx) {
|
|
15
|
-
return ctx?.coordinates?.z || 0;
|
|
16
|
-
}
|
|
17
|
-
export function readExpression(property, ctx) {
|
|
18
|
-
if (property.expression) {
|
|
19
|
-
return property.expression.evaluate(ctx);
|
|
20
|
-
}
|
|
21
|
-
if (property.stops) {
|
|
22
|
-
const stops = property.stops;
|
|
23
|
-
property = property.stops[0][1];
|
|
24
|
-
for (let i = stops.length - 1; i >= 0; i--) {
|
|
25
|
-
const stop = stops[i];
|
|
26
|
-
if (ctx.zoom >= stop[0]) {
|
|
27
|
-
property = stop[1];
|
|
28
|
-
break;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
if (typeof property === 'string' || property instanceof String) {
|
|
33
|
-
return property.replace(/\{(.+?)\}/g, (a, b) => ctx.properties[b] || '').trim();
|
|
34
|
-
}
|
|
35
|
-
if (property instanceof Function) {
|
|
36
|
-
// TOBREAK: Pass the current `context` as a unique parameter.
|
|
37
|
-
// In this proposal, metadata will be accessed in the callee by the
|
|
38
|
-
// `context.properties` property.
|
|
39
|
-
return property(ctx.properties, ctx);
|
|
40
|
-
}
|
|
41
|
-
return property;
|
|
42
|
-
}
|
|
43
|
-
function rgba2rgb(orig) {
|
|
44
|
-
if (!orig) {
|
|
45
|
-
return {};
|
|
46
|
-
} else if (orig.stops || orig.expression) {
|
|
47
|
-
return {
|
|
48
|
-
color: orig
|
|
49
|
-
};
|
|
50
|
-
} else if (typeof orig == 'string') {
|
|
51
|
-
const result = orig.match(/(?:((hsl|rgb)a? *\(([\d.%]+(?:deg|g?rad|turn)?)[ ,]*([\d.%]+)[ ,]*([\d.%]+)[ ,/]*([\d.%]*)\))|(#((?:[\d\w]{3}){1,2})([\d\w]{1,2})?))/i);
|
|
52
|
-
if (result === null) {
|
|
53
|
-
return {
|
|
54
|
-
color: orig,
|
|
55
|
-
opacity: 1.0
|
|
56
|
-
};
|
|
57
|
-
} else if (result[7]) {
|
|
58
|
-
let opacity = 1.0;
|
|
59
|
-
if (result[9]) {
|
|
60
|
-
opacity = parseInt(result[9].length == 1 ? `${result[9]}${result[9]}` : result[9], 16) * inv255;
|
|
61
|
-
}
|
|
62
|
-
return {
|
|
63
|
-
color: `#${result[8]}`,
|
|
64
|
-
opacity
|
|
65
|
-
};
|
|
66
|
-
} else if (result[1]) {
|
|
67
|
-
return {
|
|
68
|
-
color: `${result[2]}(${result[3]},${result[4]},${result[5]})`,
|
|
69
|
-
opacity: result[6] ? Number(result[6]) : 1.0
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
function readVectorProperty(property, options) {
|
|
75
|
-
if (property != undefined) {
|
|
76
|
-
if (mapbox.expression.isExpression(property)) {
|
|
77
|
-
return mapbox.expression.createExpression(property, options).value;
|
|
78
|
-
} else {
|
|
79
|
-
return property;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
async function loadImage(source) {
|
|
84
|
-
let promise = cacheStyle.get(source, 'null');
|
|
85
|
-
if (!promise) {
|
|
86
|
-
promise = Fetcher.texture(source, {
|
|
87
|
-
crossOrigin: 'anonymous'
|
|
88
|
-
});
|
|
89
|
-
cacheStyle.set(promise, source, 'null');
|
|
90
|
-
}
|
|
91
|
-
return (await promise).image;
|
|
92
|
-
}
|
|
93
|
-
function cropImage(img) {
|
|
94
|
-
let cropValues = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
95
|
-
width: img.naturalWidth,
|
|
96
|
-
height: img.naturalHeight
|
|
97
|
-
};
|
|
98
|
-
canvas.width = cropValues.width;
|
|
99
|
-
canvas.height = cropValues.height;
|
|
100
|
-
const ctx = canvas.getContext('2d', {
|
|
101
|
-
willReadFrequently: true
|
|
102
|
-
});
|
|
103
|
-
ctx.drawImage(img, cropValues.x || 0, cropValues.y || 0, cropValues.width, cropValues.height, 0, 0, cropValues.width, cropValues.height);
|
|
104
|
-
return ctx.getImageData(0, 0, cropValues.width, cropValues.height);
|
|
105
|
-
}
|
|
106
|
-
function replaceWhitePxl(imgd, color, id) {
|
|
107
|
-
if (!color) {
|
|
108
|
-
return imgd;
|
|
109
|
-
}
|
|
110
|
-
const imgdColored = cacheStyle.get(id, color);
|
|
111
|
-
if (!imgdColored) {
|
|
112
|
-
const pix = imgd.data;
|
|
113
|
-
const newColor = new Color(color);
|
|
114
|
-
const colorToChange = new Color('white');
|
|
115
|
-
for (let i = 0, n = pix.length; i < n; i += 4) {
|
|
116
|
-
const d = deltaE(pix.slice(i, i + 3), colorToChange) / 100;
|
|
117
|
-
pix[i] = pix[i] * d + newColor.r * 255 * (1 - d);
|
|
118
|
-
pix[i + 1] = pix[i + 1] * d + newColor.g * 255 * (1 - d);
|
|
119
|
-
pix[i + 2] = pix[i + 2] * d + newColor.b * 255 * (1 - d);
|
|
120
|
-
}
|
|
121
|
-
cacheStyle.set(imgd, id, color);
|
|
122
|
-
return imgd;
|
|
123
|
-
}
|
|
124
|
-
return imgdColored;
|
|
125
|
-
}
|
|
126
|
-
const textAnchorPosition = {
|
|
127
|
-
left: [0, -0.5],
|
|
128
|
-
right: [-1, -0.5],
|
|
129
|
-
top: [-0.5, 0],
|
|
130
|
-
bottom: [-0.5, -1],
|
|
131
|
-
'top-right': [-1, 0],
|
|
132
|
-
'bottom-left': [0, -1],
|
|
133
|
-
'bottom-right': [-1, -1],
|
|
134
|
-
center: [-0.5, -0.5],
|
|
135
|
-
'top-left': [0, 0]
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Defines a property for the given Style for a specific parameter in a given category (one of fill, stroke, point, text, icon or zoom),
|
|
140
|
-
* by generating its getter and setter.
|
|
141
|
-
* The getter is in charge of returning the right style value from the following ones if they are defined (in that specific order):
|
|
142
|
-
* the value set by the user (`userValue`)
|
|
143
|
-
* the value read from the data source (`dataValue`)
|
|
144
|
-
* the default fallback value (`defaultValue`).
|
|
145
|
-
* The setter can be called to change dynamically the value.
|
|
146
|
-
* @param {Style} style - The Style instance to set.
|
|
147
|
-
* @param {string} category - The category (fill, stroke, point, test, icon or zoom) to set.
|
|
148
|
-
* @param {string} parameter - The parameter of the category to set.
|
|
149
|
-
* @param {All} userValue - The value given by the user (if any). Can be undefined.
|
|
150
|
-
* @param {All} [defaultValue] - The default value to return (if needed).
|
|
151
|
-
*/
|
|
152
|
-
function defineStyleProperty(style, category, parameter, userValue, defaultValue) {
|
|
153
|
-
let property;
|
|
154
|
-
Object.defineProperty(style[category], parameter, {
|
|
155
|
-
enumerable: true,
|
|
156
|
-
get: () => {
|
|
157
|
-
// != to check for 'undefined' and 'null' value)
|
|
158
|
-
if (property != undefined) {
|
|
159
|
-
return property;
|
|
160
|
-
}
|
|
161
|
-
if (userValue != undefined) {
|
|
162
|
-
return readExpression(userValue, style.context);
|
|
163
|
-
}
|
|
164
|
-
const dataValue = style.context.featureStyle?.[category]?.[parameter];
|
|
165
|
-
if (dataValue != undefined) {
|
|
166
|
-
return readExpression(dataValue, style.context);
|
|
167
|
-
}
|
|
168
|
-
if (defaultValue instanceof Function) {
|
|
169
|
-
return defaultValue(style.context.properties, style.context);
|
|
170
|
-
}
|
|
171
|
-
return defaultValue;
|
|
172
|
-
},
|
|
173
|
-
set: v => {
|
|
174
|
-
property = v;
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* StyleContext stores metadata of one FeatureGeometry that are needed for its style computation:
|
|
181
|
-
* type of feature and what is needed (fill, stroke or draw a point, etc.) as well as where to get its
|
|
182
|
-
* properties and its coordinates (for base_altitude).
|
|
183
|
-
*
|
|
184
|
-
* @property {number} zoom Current zoom to display the FeatureGeometry.
|
|
185
|
-
* @property {Object} collection The FeatureCollection to which the FeatureGeometry is attached.
|
|
186
|
-
* @property {Object} properties Properties of the FeatureGeometry.
|
|
187
|
-
* @property {string} type Geometry type of the feature. Can be `point`, `line`, or `polygon`.
|
|
188
|
-
* @property {StyleOptions|Function}featureStyle StyleOptions object (or a function returning one) to get style
|
|
189
|
-
* information at feature and FeatureGeometry level from the data parsed.
|
|
190
|
-
* @property {Coordinates} coordinates The coordinates (in world space) of the last vertex (x, y, z) set with
|
|
191
|
-
* setLocalCoordinatesFromArray().
|
|
192
|
-
* private properties:
|
|
193
|
-
* @property {Coordinates} worldCoord @private Coordinates object to store coordinates in world space.
|
|
194
|
-
* @property {Coordinates} localCoordinates @private Coordinates object to store coordinates in local space.
|
|
195
|
-
* @property {boolean} worldCoordsComputed @private Have the world coordinates already been computed
|
|
196
|
-
* from the local coordinates?
|
|
197
|
-
* @property {Feature} feature @private The itowns feature of interest.
|
|
198
|
-
* @property {FeatureGeometry} geometry @private The FeatureGeometry to compute the style.
|
|
199
|
-
*/
|
|
200
|
-
export class StyleContext {
|
|
201
|
-
#worldCoord = (() => new Coordinates('EPSG:4326', 0, 0, 0))();
|
|
202
|
-
#localCoordinates = (() => new Coordinates('EPSG:4326', 0, 0, 0))();
|
|
203
|
-
#worldCoordsComputed = true;
|
|
204
|
-
#feature = {};
|
|
205
|
-
#geometry = {};
|
|
206
|
-
setZoom(zoom) {
|
|
207
|
-
this.zoom = zoom;
|
|
208
|
-
}
|
|
209
|
-
setFeature(f) {
|
|
210
|
-
this.#feature = f;
|
|
211
|
-
}
|
|
212
|
-
setGeometry(g) {
|
|
213
|
-
this.#geometry = g;
|
|
214
|
-
}
|
|
215
|
-
setCollection(c) {
|
|
216
|
-
this.collection = c;
|
|
217
|
-
this.#localCoordinates.setCrs(c.crs);
|
|
218
|
-
}
|
|
219
|
-
setLocalCoordinatesFromArray(vertices, offset) {
|
|
220
|
-
this.#worldCoordsComputed = false;
|
|
221
|
-
return this.#localCoordinates.setFromArray(vertices, offset);
|
|
222
|
-
}
|
|
223
|
-
get properties() {
|
|
224
|
-
return this.#geometry.properties;
|
|
225
|
-
}
|
|
226
|
-
get type() {
|
|
227
|
-
return this.#feature.type;
|
|
228
|
-
}
|
|
229
|
-
get featureStyle() {
|
|
230
|
-
let featureStyle = this.#feature.style;
|
|
231
|
-
if (featureStyle instanceof Function) {
|
|
232
|
-
featureStyle = featureStyle(this.properties, this);
|
|
233
|
-
}
|
|
234
|
-
return featureStyle;
|
|
235
|
-
}
|
|
236
|
-
get coordinates() {
|
|
237
|
-
if (!this.#worldCoordsComputed) {
|
|
238
|
-
this.#worldCoordsComputed = true;
|
|
239
|
-
this.#worldCoord.copy(this.#localCoordinates).applyMatrix4(this.collection.matrixWorld);
|
|
240
|
-
if (this.#localCoordinates.crs == 'EPSG:4978') {
|
|
241
|
-
return this.#worldCoord.as('EPSG:4326', this.#worldCoord);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
return this.#worldCoord;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
function _addIcon(icon, domElement, opt) {
|
|
248
|
-
const cIcon = icon.cloneNode();
|
|
249
|
-
cIcon.setAttribute('class', 'itowns-icon');
|
|
250
|
-
cIcon.width = icon.width * opt.size;
|
|
251
|
-
cIcon.height = icon.height * opt.size;
|
|
252
|
-
cIcon.style.color = opt.color;
|
|
253
|
-
cIcon.style.opacity = opt.opacity;
|
|
254
|
-
cIcon.style.position = 'absolute';
|
|
255
|
-
cIcon.style.top = '0';
|
|
256
|
-
cIcon.style.left = '0';
|
|
257
|
-
switch (opt.anchor) {
|
|
258
|
-
// center by default
|
|
259
|
-
case 'left':
|
|
260
|
-
cIcon.style.top = `${-0.5 * cIcon.height}px`;
|
|
261
|
-
break;
|
|
262
|
-
case 'right':
|
|
263
|
-
cIcon.style.top = `${-0.5 * cIcon.height}px`;
|
|
264
|
-
cIcon.style.left = `${-cIcon.width}px`;
|
|
265
|
-
break;
|
|
266
|
-
case 'top':
|
|
267
|
-
cIcon.style.left = `${-0.5 * cIcon.width}px`;
|
|
268
|
-
break;
|
|
269
|
-
case 'bottom':
|
|
270
|
-
cIcon.style.top = `${-cIcon.height}px`;
|
|
271
|
-
cIcon.style.left = `${-0.5 * cIcon.width}px`;
|
|
272
|
-
break;
|
|
273
|
-
case 'bottom-left':
|
|
274
|
-
cIcon.style.top = `${-cIcon.height}px`;
|
|
275
|
-
break;
|
|
276
|
-
case 'bottom-right':
|
|
277
|
-
cIcon.style.top = `${-cIcon.height}px`;
|
|
278
|
-
cIcon.style.left = `${-cIcon.width}px`;
|
|
279
|
-
break;
|
|
280
|
-
case 'top-left':
|
|
281
|
-
break;
|
|
282
|
-
case 'top-right':
|
|
283
|
-
cIcon.style.left = `${-cIcon.width}px`;
|
|
284
|
-
break;
|
|
285
|
-
case 'center':
|
|
286
|
-
default:
|
|
287
|
-
cIcon.style.top = `${-0.5 * cIcon.height}px`;
|
|
288
|
-
cIcon.style.left = `${-0.5 * cIcon.width}px`;
|
|
289
|
-
break;
|
|
290
|
-
}
|
|
291
|
-
cIcon.style['z-index'] = -1;
|
|
292
|
-
domElement.appendChild(cIcon);
|
|
293
|
-
return cIcon;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* An object that can contain any properties (order, zoom, fill, stroke, point,
|
|
298
|
-
* text or/and icon) and sub properties of a Style.<br/>
|
|
299
|
-
* Used for the instanciation of a {@link Style}.
|
|
300
|
-
*
|
|
301
|
-
* @typedef {Object} StyleOptions
|
|
302
|
-
*
|
|
303
|
-
* @property {Number} [order] - Order of the features that will be associated to
|
|
304
|
-
* the style. It can helps sorting and prioritizing features if needed.
|
|
305
|
-
*
|
|
306
|
-
* @property {Object} [zoom] - Level on which to display the feature
|
|
307
|
-
* @property {Number} [zoom.max] - max level
|
|
308
|
-
* @property {Number} [zoom.min] - min level
|
|
309
|
-
*
|
|
310
|
-
* @property {Object} [fill] - Fill style for polygons.
|
|
311
|
-
* @property {String|Function|THREE.Color} [fill.color] - Defines the main fill color. Can be
|
|
312
|
-
* any [valid color string](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
|
|
313
|
-
* Default is no value, which means no fill.
|
|
314
|
-
* If the `Layer` is a `GeometryLayer` you can use `THREE.Color`.
|
|
315
|
-
* @property {Image|Canvas|String|Object|Function} [fill.pattern] - Defines a pattern to fill the
|
|
316
|
-
* surface with. It can be an `Image` to use directly, an url to fetch the pattern or an object containing
|
|
317
|
-
* the url of the image to fetch and the transformation to apply.
|
|
318
|
-
* from. See [this example](http://www.itowns-project.org/itowns/examples/#source_file_geojson_raster)
|
|
319
|
-
* for how to use.
|
|
320
|
-
* @property {Image|String} [fill.pattern.source] - The image or the url to fetch the pattern image
|
|
321
|
-
* @property {Object} [fill.pattern.cropValues] - The x, y, width and height (in pixel) of the sub image to use.
|
|
322
|
-
* @property {THREE.Color} [fill.pattern.color] - Can be any
|
|
323
|
-
* [valid color string](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
|
|
324
|
-
* It will change the color of the white pixels of the source image.
|
|
325
|
-
* @property {Number|Function} [fill.opacity] - The opacity of the color or of the
|
|
326
|
-
* pattern. Can be between `0.0` and `1.0`. Default is `1.0`.
|
|
327
|
-
* For a `GeometryLayer`, this opacity property isn't used.
|
|
328
|
-
* @property {Number|Function} [fill.base_altitude] - `GeometryLayer` style option, defines altitude
|
|
329
|
-
* for each coordinate.
|
|
330
|
-
* If `base_altitude` is `undefined`, the original altitude is kept, and if it doesn't exist
|
|
331
|
-
* then the altitude value is set to 0.
|
|
332
|
-
* @property {Number|Function} [fill.extrusion_height] - `GeometryLayer` style option, if defined,
|
|
333
|
-
* polygons will be extruded by the specified amount
|
|
334
|
-
*
|
|
335
|
-
* @property {Object} [stroke] - Lines and polygons edges.
|
|
336
|
-
* @property {String|Function|THREE.Color} [stroke.color] The color of the line. Can be any [valid
|
|
337
|
-
* color string](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
|
|
338
|
-
* Default is no value, which means no stroke.
|
|
339
|
-
* If the `Layer` is a `GeometryLayer` you can use `THREE.Color`.
|
|
340
|
-
* @property {Number|Function} [stroke.opacity] - The opacity of the line. Can be between
|
|
341
|
-
* `0.0` and `1.0`. Default is `1.0`.
|
|
342
|
-
* For a `GeometryLayer`, this opacity property isn't used.
|
|
343
|
-
* @property {Number|Function} [stroke.width] - The width of the line. Default is `1.0`.
|
|
344
|
-
* @property {Number|Function} [stroke.base_altitude] - `GeometryLayer` style option, defines altitude
|
|
345
|
-
* for each coordinate.
|
|
346
|
-
* If `base_altitude` is `undefined`, the original altitude is kept, and if it doesn't exist
|
|
347
|
-
* then the altitude value is set to 0.
|
|
348
|
-
*
|
|
349
|
-
* @property {Object} [point] - Point style.
|
|
350
|
-
* @property {String|Function} [point.color] - The color of the point. Can be any [valid
|
|
351
|
-
* color string](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
|
|
352
|
-
* Default is no value, which means points won't be displayed.
|
|
353
|
-
* @property {Number|Function} [point.radius] - The radius of the point, in pixel. Default
|
|
354
|
-
* is `2.0`.
|
|
355
|
-
* @property {String|Function} [point.line] - The color of the border of the point. Can be
|
|
356
|
-
* any [valid color
|
|
357
|
-
* string](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
|
|
358
|
-
* Not supported for a `GeometryLayer`.
|
|
359
|
-
* @property {Number|Function} [point.width] - The width of the border, in pixel. Default
|
|
360
|
-
* is `0.0` (no border).
|
|
361
|
-
* @property {Number|Function} [point.opacity] - The opacity of the point. Can be between
|
|
362
|
-
* `0.0` and `1.0`. Default is `1.0`.
|
|
363
|
-
* Not supported for `GeometryLayer`.
|
|
364
|
-
* @property {Number|Function} [point.base_altitude] - `GeometryLayer` style option, defines altitude
|
|
365
|
-
* for each coordinate.
|
|
366
|
-
* If `base_altitude` is `undefined`, the original altitude is kept, and if it doesn't exist
|
|
367
|
-
* then the altitude value is set to 0.
|
|
368
|
-
* @property {Object} [point.model] - 3D model to instantiate at each point position.
|
|
369
|
-
*
|
|
370
|
-
* @property {Object} [text] - All things {@link Label} related. (Supported for Points features, not yet
|
|
371
|
-
* for Lines and Polygons features.)
|
|
372
|
-
* @property {String|Function} [text.field] - A string representing a property key of
|
|
373
|
-
* a `FeatureGeometry` enclosed in brackets, that will be replaced by the value of the
|
|
374
|
-
* property for each geometry. For example, if each geometry contains a `name` property,
|
|
375
|
-
* `text.field` can be set to `{name}`. Default is no value, indicating that no
|
|
376
|
-
* text will be displayed.
|
|
377
|
-
*
|
|
378
|
-
* It's also possible to create more complex expressions. For example, you can combine
|
|
379
|
-
* text that will always be displayed (e.g. `foo`) and variable properties (e.g. `{bar}`)
|
|
380
|
-
* like the following: `foo {bar}`. You can also use multiple variables in one field.
|
|
381
|
-
* Let's say for instance that you have two properties latin name and local name of a
|
|
382
|
-
* place, you can write something like `{name_latin} - {name_local}` which can result
|
|
383
|
-
* in `Marrakesh - مراكش` for example.
|
|
384
|
-
* @property {String|Function} [text.color] - The color of the text. Can be any [valid
|
|
385
|
-
* color string](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
|
|
386
|
-
* Default is `#000000`.
|
|
387
|
-
* @property {String|Number[]|Function} [text.anchor] - The anchor of the text compared to its
|
|
388
|
-
* position (see {@link Label} for the position). Can be one of the following values: `top`,
|
|
389
|
-
* `left`, `bottom`, `right`, `center`, `top-left`, `top-right`, `bottom-left`
|
|
390
|
-
* or `bottom-right`. Default is `center`.
|
|
391
|
-
*
|
|
392
|
-
* It can also be defined as an Array of two numbers. Each number defines an offset (in
|
|
393
|
-
* fraction of the label width and height) between the label position and the top-left
|
|
394
|
-
* corner of the text. The first value is the horizontal offset, and the second is the
|
|
395
|
-
* vertical offset. For example, `[-0.5, -0.5]` will be equivalent to `center`.
|
|
396
|
-
* @property {Array|Function} [text.offset] - The offset of the text, depending on its
|
|
397
|
-
* anchor, in pixels. First value is from `left`, second is from `top`. Default
|
|
398
|
-
* is `[0, 0]`.
|
|
399
|
-
* @property {Number|Function} [text.padding] - The padding outside the text, in pixels.
|
|
400
|
-
* Default is `2`.
|
|
401
|
-
* @property {Number|Function} [text.size] - The size of the font, in pixels. Default is
|
|
402
|
-
* `16`.
|
|
403
|
-
* @property {Number|Function} [text.wrap] - The maximum width, in pixels, before the text
|
|
404
|
-
* is wrapped, because the string is too long. Default is `10`.
|
|
405
|
-
* @property {Number|Function} [text.spacing] - The spacing between the letters, in `em`.
|
|
406
|
-
* Default is `0`.
|
|
407
|
-
* @property {String|Function} [text.transform] - A value corresponding to the [CSS
|
|
408
|
-
* property
|
|
409
|
-
* `text-transform`](https://developer.mozilla.org/en-US/docs/Web/CSS/text-transform).
|
|
410
|
-
* Default is `none`.
|
|
411
|
-
* @property {String|Function} [text.justify] - A value corresponding to the [CSS property
|
|
412
|
-
* `text-align`](https://developer.mozilla.org/en-US/docs/Web/CSS/text-align).
|
|
413
|
-
* Default is `center`.
|
|
414
|
-
* @property {Number|Function} [text.opacity] - The opacity of the text. Can be between
|
|
415
|
-
* `0.0` and `1.0`. Default is `1.0`.
|
|
416
|
-
* @property {Array|Function} [text.font] - A list (as an array of string) of font family
|
|
417
|
-
* names, prioritized in the order it is set. Default is `Open Sans Regular,
|
|
418
|
-
* Arial Unicode MS Regular, sans-serif`.
|
|
419
|
-
* @property {String|Function} [text.haloColor] - The color of the halo. Can be any [valid
|
|
420
|
-
* color string](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
|
|
421
|
-
* Default is `#000000`.
|
|
422
|
-
* @property {Number|Function} [text.haloWidth] - The width of the halo, in pixels.
|
|
423
|
-
* Default is `0`.
|
|
424
|
-
* @property {Number|Function} [text.haloBlur] - The blur value of the halo, in pixels.
|
|
425
|
-
* Default is `0`.
|
|
426
|
-
*
|
|
427
|
-
* @property {Object} [icon] - Defines the appearance of icons attached to label.
|
|
428
|
-
* @property {String} [icon.source] - The url of the icons' image file.
|
|
429
|
-
* @property {String} [icon.id] - The id of the icons' sub-image in a vector tile data set.
|
|
430
|
-
* @property {String} [icon.cropValues] - the x, y, width and height (in pixel) of the sub image to use.
|
|
431
|
-
* @property {String} [icon.anchor] - The anchor of the icon compared to the label position.
|
|
432
|
-
* Can be `left`, `bottom`, `right`, `center`, `top-left`, `top-right`, `bottom-left`
|
|
433
|
-
* or `bottom-right`. Default is `center`.
|
|
434
|
-
* @property {Number} [icon.size] - If the icon's image is passed with `icon.source` and/or
|
|
435
|
-
* `icon.id`, its size when displayed on screen is multiplied by `icon.size`. Default is `1`.
|
|
436
|
-
* @property {String|Function} [icon.color] - The color of the icon. Can be any [valid
|
|
437
|
-
* color string](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
|
|
438
|
-
* It will change the color of the white pixels of the icon source image.
|
|
439
|
-
* @property {Number|Function} [icon.opacity] - The opacity of the icon. Can be between
|
|
440
|
-
* `0.0` and `1.0`. Default is `1.0`.
|
|
441
|
-
*/
|
|
442
|
-
|
|
443
|
-
/**
|
|
444
|
-
* A Style is a class that defines the visual appearance of {@link
|
|
445
|
-
* FeatureCollection} and {@link Feature}. It is taken into account when drawing
|
|
446
|
-
* them in textures that will be placed onto tiles.
|
|
447
|
-
*
|
|
448
|
-
* As there are five basic elements present in `Features`, there are also five
|
|
449
|
-
* main components in a `Style` object:
|
|
450
|
-
* - `fill` is for all fillings and polygons
|
|
451
|
-
* - `stroke` is for all lines and polygons edges
|
|
452
|
-
* - `point` is for all points
|
|
453
|
-
* - `text` contains all {@link Label} related things
|
|
454
|
-
* - `icon` defines the appearance of icons attached to label.
|
|
455
|
-
*
|
|
456
|
-
* Many style property can be set to functions. When that is the case, the function's
|
|
457
|
-
* return type must necessarily be the same as the types (other than function) of the property.
|
|
458
|
-
* For instance, if the `fill.pattern` property is set to a function, this function must return
|
|
459
|
-
* an `Image`, a `Canvas`, or `String`.
|
|
460
|
-
* The first parameter of functions used to set `Style` properties is always an object containing
|
|
461
|
-
* the properties of the features displayed with the current `Style` instance.
|
|
462
|
-
*
|
|
463
|
-
* @property {Number} order - Order of the features that will be associated to
|
|
464
|
-
* the style. It can helps sorting and prioritizing features if needed.
|
|
465
|
-
* @property {Object} fill - Polygons and fillings style.
|
|
466
|
-
* @property {String|Function|THREE.Color} fill.color - Defines the main color of the filling. Can be
|
|
467
|
-
* any [valid color
|
|
468
|
-
* string](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
|
|
469
|
-
* Default is no value, indicating that no filling needs to be done.
|
|
470
|
-
* If the `Layer` is a `GeometryLayer` you can use `THREE.Color`.
|
|
471
|
-
* @property {Image|Canvas|String|Object|Function} [fill.pattern] - Defines a pattern to fill the
|
|
472
|
-
* surface with. It can be an `Image` to use directly, an url to fetch the pattern or an object containing
|
|
473
|
-
* the url of the image to fetch and the transformation to apply.
|
|
474
|
-
* from. See [this example] (http://www.itowns-project.org/itowns/examples/#source_file_geojson_raster)
|
|
475
|
-
* for how to use.
|
|
476
|
-
* @property {Image|String} [fill.pattern.source] - The image or the url to fetch the pattern image
|
|
477
|
-
* @property {Object} [fill.pattern.cropValues] - The x, y, width and height (in pixel) of the sub image to use.
|
|
478
|
-
* @property {THREE.Color} [fill.pattern.color] - Can be any [valid color string]
|
|
479
|
-
* @property {Number|Function} fill.opacity - The opacity of the color or of the
|
|
480
|
-
* pattern. Can be between `0.0` and `1.0`. Default is `1.0`.
|
|
481
|
-
* For a `GeometryLayer`, this opacity property isn't used.
|
|
482
|
-
* @property {Number|Function} fill.base_altitude - Only for {@link GeometryLayer}, defines altitude
|
|
483
|
-
* for each coordinate.
|
|
484
|
-
* If `base_altitude` is `undefined`, the original altitude is kept, and if it doesn't exist
|
|
485
|
-
* then the altitude value is set to 0.
|
|
486
|
-
* @property {Number|Function} [fill.extrusion_height] - Only for {@link GeometryLayer} and if user sets it.
|
|
487
|
-
* If defined, polygons will be extruded by the specified amount.
|
|
488
|
-
* @property {Object} stroke - Lines and polygons edges.
|
|
489
|
-
* @property {String|Function|THREE.Color} stroke.color The color of the line. Can be any [valid
|
|
490
|
-
* color string](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
|
|
491
|
-
* Default is no value, indicating that no stroke needs to be done.
|
|
492
|
-
* If the `Layer` is a `GeometryLayer` you can use `THREE.Color`.
|
|
493
|
-
* @property {Number|Function} stroke.opacity - The opacity of the line. Can be between
|
|
494
|
-
* `0.0` and `1.0`. Default is `1.0`.
|
|
495
|
-
* For a `GeometryLayer`, this opacity property isn't used.
|
|
496
|
-
* @property {Number|Function} stroke.width - The width of the line. Default is `1.0`.
|
|
497
|
-
* @property {Number|Function} stroke.base_altitude - Only for {@link GeometryLayer}, defines altitude
|
|
498
|
-
* for each coordinate.
|
|
499
|
-
* If `base_altitude` is `undefined`, the original altitude is kept, and if it doesn't exist
|
|
500
|
-
* then the altitude value is set to 0.
|
|
501
|
-
*
|
|
502
|
-
* @property {Object} point - Point style.
|
|
503
|
-
* @property {String|Function} point.color - The color of the point. Can be any [valid
|
|
504
|
-
* color string](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
|
|
505
|
-
* Default is no value, indicating that no point will be shown.
|
|
506
|
-
* @property {Number|Function} point.radius - The radius of the point, in pixel. Default
|
|
507
|
-
* is `2.0`.
|
|
508
|
-
* @property {String|Function} point.line - The color of the border of the point. Can be
|
|
509
|
-
* any [valid color
|
|
510
|
-
* string](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
|
|
511
|
-
* Not supported for `GeometryLayer`.
|
|
512
|
-
* @property {Number|Function} point.width - The width of the border, in pixel. Default
|
|
513
|
-
* is `0.0` (no border).
|
|
514
|
-
* @property {Number|Function} point.opacity - The opacity of the point. Can be between
|
|
515
|
-
* `0.0` and `1.0`. Default is `1.0`.
|
|
516
|
-
* Not supported for `GeometryLayer`.
|
|
517
|
-
* @property {Number|Function} point.base_altitude - Only for {@link GeometryLayer}, defines altitude
|
|
518
|
-
* for each coordinate.
|
|
519
|
-
* If `base_altitude` is `undefined`, the original altitude is kept, and if it doesn't exist
|
|
520
|
-
* then the altitude value is set to 0.
|
|
521
|
-
* @property {Object} point.model - 3D model to instantiate at each point position
|
|
522
|
-
|
|
523
|
-
*
|
|
524
|
-
* @property {Object} text - All things {@link Label} related.
|
|
525
|
-
* @property {String|Function} text.field - A string representing a property key of
|
|
526
|
-
* a `FeatureGeometry` enclosed in brackets, that will be replaced by the value of the
|
|
527
|
-
* property for each geometry. For example, if each geometry contains a `name` property,
|
|
528
|
-
* `text.field` can be set to `{name}`. Default is no value, indicating that no
|
|
529
|
-
* text will be displayed.
|
|
530
|
-
*
|
|
531
|
-
* It's also possible to create more complex expressions. For example, you can combine
|
|
532
|
-
* text that will always be displayed (e.g. `foo`) and variable properties (e.g. `{bar}`)
|
|
533
|
-
* like the following: `foo {bar}`. You can also use multiple variables in one field.
|
|
534
|
-
* Let's say for instance that you have two properties latin name and local name of a
|
|
535
|
-
* place, you can write something like `{name_latin} - {name_local}` which can result
|
|
536
|
-
* in `Marrakesh - مراكش` for example.
|
|
537
|
-
* @property {String|Function} text.color - The color of the text. Can be any [valid
|
|
538
|
-
* color string](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
|
|
539
|
-
* Default is `#000000`.
|
|
540
|
-
* @property {String|Number[]|Function} text.anchor - The anchor of the text relative to its
|
|
541
|
-
* position (see {@link Label} for the position). Can be one of the following values: `top`,
|
|
542
|
-
* `left`, `bottom`, `right`, `center`, `top-left`, `top-right`, `bottom-left`
|
|
543
|
-
* or `bottom-right`. Default is `center`.
|
|
544
|
-
*
|
|
545
|
-
* It can also be defined as an Array of two numbers. Each number defines an offset (in
|
|
546
|
-
* fraction of the label width and height) between the label position and the top-left
|
|
547
|
-
* corner of the text. The first value is the horizontal offset, and the second is the
|
|
548
|
-
* vertical offset. For example, `[-0.5, -0.5]` will be equivalent to `center`.
|
|
549
|
-
* @property {Array|Function} text.offset - The offset of the text, depending on its
|
|
550
|
-
* anchor, in pixels. First value is from `left`, second is from `top`. Default
|
|
551
|
-
* is `[0, 0]`.
|
|
552
|
-
* @property {Number|Function} text.padding - The padding outside the text, in pixels.
|
|
553
|
-
* Default is `2`.
|
|
554
|
-
* @property {Number|Function} text.size - The size of the font, in pixels. Default is
|
|
555
|
-
* `16`.
|
|
556
|
-
* @property {Number|Function} text.wrap - The maximum width, in pixels, before the text
|
|
557
|
-
* is wrapped, because the string is too long. Default is `10`.
|
|
558
|
-
* @property {Number|Function} text.spacing - The spacing between the letters, in `em`.
|
|
559
|
-
* Default is `0`.
|
|
560
|
-
* @property {String|Function} text.transform - A value corresponding to the [CSS
|
|
561
|
-
* property
|
|
562
|
-
* `text-transform`](https://developer.mozilla.org/en-US/docs/Web/CSS/text-transform).
|
|
563
|
-
* Default is `none`.
|
|
564
|
-
* @property {String|Function} text.justify - A value corresponding to the [CSS property
|
|
565
|
-
* `text-align`](https://developer.mozilla.org/en-US/docs/Web/CSS/text-align).
|
|
566
|
-
* Default is `center`.
|
|
567
|
-
* @property {Number|Function} text.opacity - The opacity of the text. Can be between
|
|
568
|
-
* `0.0` and `1.0`. Default is `1.0`.
|
|
569
|
-
* @property {Array|Function} text.font - A list (as an array of string) of font family
|
|
570
|
-
* names, prioritized in the order it is set. Default is `Open Sans Regular,
|
|
571
|
-
* Arial Unicode MS Regular, sans-serif`.
|
|
572
|
-
* @property {String|Function} text.haloColor - The color of the halo. Can be any [valid
|
|
573
|
-
* color string](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
|
|
574
|
-
* Default is `#000000`.
|
|
575
|
-
* @property {Number|Function} text.haloWidth - The width of the halo, in pixels.
|
|
576
|
-
* Default is `0`.
|
|
577
|
-
* @property {Number|Function} text.haloBlur - The blur value of the halo, in pixels.
|
|
578
|
-
* Default is `0`.
|
|
579
|
-
*
|
|
580
|
-
* @property {Object} icon - Defines the appearance of icons attached to label.
|
|
581
|
-
* @property {String} icon.source - The url of the icons' image file.
|
|
582
|
-
* @property {String} icon.id - The id of the icons' sub-image in a vector tile data set.
|
|
583
|
-
* @property {String} icon.cropValues - the x, y, width and height (in pixel) of the sub image to use.
|
|
584
|
-
* @property {String} icon.anchor - The anchor of the icon compared to the label position.
|
|
585
|
-
* Can be `left`, `bottom`, `right`, `center`, `top-left`, `top-right`, `bottom-left`
|
|
586
|
-
* or `bottom-right`. Default is `center`.
|
|
587
|
-
* @property {Number} icon.size - If the icon's image is passed with `icon.source` and/or
|
|
588
|
-
* `icon.id`, its size when displayed on screen is multiplied by `icon.size`. Default is `1`.
|
|
589
|
-
* @property {String|Function} icon.color - The color of the icon. Can be any [valid
|
|
590
|
-
* color string](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
|
|
591
|
-
* It will change the color of the white pixels of the icon source image.
|
|
592
|
-
* @property {Number|Function} icon.opacity - The opacity of the icon. Can be between
|
|
593
|
-
* `0.0` and `1.0`. Default is `1.0`.
|
|
594
|
-
*
|
|
595
|
-
* @example
|
|
596
|
-
* const style = new itowns.Style({
|
|
597
|
-
* stroke: { color: 'red' },
|
|
598
|
-
* point: { color: 'white', line: 'red' },
|
|
599
|
-
* });
|
|
600
|
-
*
|
|
601
|
-
* const source = new itowns.FileSource(...);
|
|
602
|
-
*
|
|
603
|
-
* const layer = new itowns.ColorLayer('foo', {
|
|
604
|
-
* source: source,
|
|
605
|
-
* style: style,
|
|
606
|
-
* });
|
|
607
|
-
*
|
|
608
|
-
* view.addLayer(layer);
|
|
609
|
-
*/
|
|
610
|
-
|
|
611
|
-
class Style {
|
|
612
|
-
/**
|
|
613
|
-
* @param {StyleOptions} [params={}] An object that contain any properties
|
|
614
|
-
* (order, zoom, fill, stroke, point, text or/and icon)
|
|
615
|
-
* and sub properties of a Style ({@link StyleOptions}).
|
|
616
|
-
*/
|
|
617
|
-
constructor() {
|
|
618
|
-
let params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
619
|
-
this.isStyle = true;
|
|
620
|
-
this.context = new StyleContext();
|
|
621
|
-
this.order = params.order || 0;
|
|
622
|
-
params.zoom = params.zoom || {};
|
|
623
|
-
params.fill = params.fill || {};
|
|
624
|
-
params.stroke = params.stroke || {};
|
|
625
|
-
params.point = params.point || {};
|
|
626
|
-
params.text = params.text || {};
|
|
627
|
-
params.icon = params.icon || {};
|
|
628
|
-
this.zoom = {};
|
|
629
|
-
defineStyleProperty(this, 'zoom', 'min', params.zoom.min);
|
|
630
|
-
defineStyleProperty(this, 'zoom', 'max', params.zoom.max);
|
|
631
|
-
this.fill = {};
|
|
632
|
-
defineStyleProperty(this, 'fill', 'color', params.fill.color);
|
|
633
|
-
defineStyleProperty(this, 'fill', 'opacity', params.fill.opacity, 1.0);
|
|
634
|
-
defineStyleProperty(this, 'fill', 'pattern', params.fill.pattern);
|
|
635
|
-
defineStyleProperty(this, 'fill', 'base_altitude', params.fill.base_altitude, baseAltitudeDefault);
|
|
636
|
-
if (params.fill.extrusion_height) {
|
|
637
|
-
defineStyleProperty(this, 'fill', 'extrusion_height', params.fill.extrusion_height);
|
|
638
|
-
}
|
|
639
|
-
this.stroke = {};
|
|
640
|
-
defineStyleProperty(this, 'stroke', 'color', params.stroke.color);
|
|
641
|
-
defineStyleProperty(this, 'stroke', 'opacity', params.stroke.opacity, 1.0);
|
|
642
|
-
defineStyleProperty(this, 'stroke', 'width', params.stroke.width, 1.0);
|
|
643
|
-
defineStyleProperty(this, 'stroke', 'dasharray', params.stroke.dasharray, []);
|
|
644
|
-
defineStyleProperty(this, 'stroke', 'base_altitude', params.stroke.base_altitude, baseAltitudeDefault);
|
|
645
|
-
this.point = {};
|
|
646
|
-
defineStyleProperty(this, 'point', 'color', params.point.color);
|
|
647
|
-
defineStyleProperty(this, 'point', 'line', params.point.line);
|
|
648
|
-
defineStyleProperty(this, 'point', 'opacity', params.point.opacity, 1.0);
|
|
649
|
-
defineStyleProperty(this, 'point', 'radius', params.point.radius, 2.0);
|
|
650
|
-
defineStyleProperty(this, 'point', 'width', params.point.width, 0.0);
|
|
651
|
-
defineStyleProperty(this, 'point', 'base_altitude', params.point.base_altitude, baseAltitudeDefault);
|
|
652
|
-
if (params.point.model) {
|
|
653
|
-
defineStyleProperty(this, 'point', 'model', params.point.model);
|
|
654
|
-
}
|
|
655
|
-
this.text = {};
|
|
656
|
-
defineStyleProperty(this, 'text', 'field', params.text.field);
|
|
657
|
-
defineStyleProperty(this, 'text', 'zOrder', params.text.zOrder, 'auto');
|
|
658
|
-
defineStyleProperty(this, 'text', 'color', params.text.color, '#000000');
|
|
659
|
-
defineStyleProperty(this, 'text', 'anchor', params.text.anchor, 'center');
|
|
660
|
-
defineStyleProperty(this, 'text', 'offset', params.text.offset, [0, 0]);
|
|
661
|
-
defineStyleProperty(this, 'text', 'padding', params.text.padding, 2);
|
|
662
|
-
defineStyleProperty(this, 'text', 'size', params.text.size, 16);
|
|
663
|
-
defineStyleProperty(this, 'text', 'placement', params.text.placement, 'point');
|
|
664
|
-
defineStyleProperty(this, 'text', 'rotation', params.text.rotation, 'auto');
|
|
665
|
-
defineStyleProperty(this, 'text', 'wrap', params.text.wrap, 10);
|
|
666
|
-
defineStyleProperty(this, 'text', 'spacing', params.text.spacing, 0);
|
|
667
|
-
defineStyleProperty(this, 'text', 'transform', params.text.transform, 'none');
|
|
668
|
-
defineStyleProperty(this, 'text', 'justify', params.text.justify, 'center');
|
|
669
|
-
defineStyleProperty(this, 'text', 'opacity', params.text.opacity, 1.0);
|
|
670
|
-
defineStyleProperty(this, 'text', 'font', params.text.font, ['Open Sans Regular', 'Arial Unicode MS Regular', 'sans-serif']);
|
|
671
|
-
defineStyleProperty(this, 'text', 'haloColor', params.text.haloColor, '#000000');
|
|
672
|
-
defineStyleProperty(this, 'text', 'haloWidth', params.text.haloWidth, 0);
|
|
673
|
-
defineStyleProperty(this, 'text', 'haloBlur', params.text.haloBlur, 0);
|
|
674
|
-
this.icon = {};
|
|
675
|
-
defineStyleProperty(this, 'icon', 'source', params.icon.source);
|
|
676
|
-
if (params.icon.key) {
|
|
677
|
-
console.warn("'icon.key' is deprecated: use 'icon.id' instead");
|
|
678
|
-
params.icon.id = params.icon.key;
|
|
679
|
-
}
|
|
680
|
-
defineStyleProperty(this, 'icon', 'id', params.icon.id);
|
|
681
|
-
defineStyleProperty(this, 'icon', 'cropValues', params.icon.cropValues);
|
|
682
|
-
defineStyleProperty(this, 'icon', 'anchor', params.icon.anchor, 'center');
|
|
683
|
-
defineStyleProperty(this, 'icon', 'size', params.icon.size, 1);
|
|
684
|
-
defineStyleProperty(this, 'icon', 'color', params.icon.color);
|
|
685
|
-
defineStyleProperty(this, 'icon', 'opacity', params.icon.opacity, 1.0);
|
|
686
|
-
}
|
|
687
|
-
setContext(ctx) {
|
|
688
|
-
this.context = ctx;
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
/**
|
|
692
|
-
* set Style from (geojson-like) properties.
|
|
693
|
-
* @param {Object} properties (geojson-like) properties.
|
|
694
|
-
* @param {FeatureContext} featCtx the context of the feature
|
|
695
|
-
*
|
|
696
|
-
* @returns {StyleOptions} containing all properties for itowns.Style
|
|
697
|
-
*/
|
|
698
|
-
static setFromProperties(properties, featCtx) {
|
|
699
|
-
const type = featCtx.type;
|
|
700
|
-
const style = {};
|
|
701
|
-
if (type === FEATURE_TYPES.POINT) {
|
|
702
|
-
const point = {
|
|
703
|
-
...(properties.fill !== undefined && {
|
|
704
|
-
color: properties.fill
|
|
705
|
-
}),
|
|
706
|
-
...(properties['fill-opacity'] !== undefined && {
|
|
707
|
-
opacity: properties['fill-opacity']
|
|
708
|
-
}),
|
|
709
|
-
...(properties.stroke !== undefined && {
|
|
710
|
-
line: properties.stroke
|
|
711
|
-
}),
|
|
712
|
-
...(properties.radius !== undefined && {
|
|
713
|
-
radius: properties.radius
|
|
714
|
-
})
|
|
715
|
-
};
|
|
716
|
-
if (Object.keys(point).length) {
|
|
717
|
-
style.point = point;
|
|
718
|
-
}
|
|
719
|
-
const text = {
|
|
720
|
-
...(properties['label-color'] !== undefined && {
|
|
721
|
-
color: properties['label-color']
|
|
722
|
-
}),
|
|
723
|
-
...(properties['label-opacity'] !== undefined && {
|
|
724
|
-
opacity: properties['label-opacity']
|
|
725
|
-
}),
|
|
726
|
-
...(properties['label-size'] !== undefined && {
|
|
727
|
-
size: properties['label-size']
|
|
728
|
-
})
|
|
729
|
-
};
|
|
730
|
-
if (Object.keys(point).length) {
|
|
731
|
-
style.text = text;
|
|
732
|
-
}
|
|
733
|
-
const icon = {
|
|
734
|
-
...(properties.icon !== undefined && {
|
|
735
|
-
source: properties.icon
|
|
736
|
-
}),
|
|
737
|
-
...(properties['icon-scale'] !== undefined && {
|
|
738
|
-
size: properties['icon-scale']
|
|
739
|
-
}),
|
|
740
|
-
...(properties['icon-opacity'] !== undefined && {
|
|
741
|
-
opacity: properties['icon-opacity']
|
|
742
|
-
}),
|
|
743
|
-
...(properties['icon-color'] !== undefined && {
|
|
744
|
-
color: properties['icon-color']
|
|
745
|
-
})
|
|
746
|
-
};
|
|
747
|
-
if (Object.keys(icon).length) {
|
|
748
|
-
style.icon = icon;
|
|
749
|
-
}
|
|
750
|
-
} else {
|
|
751
|
-
const stroke = {
|
|
752
|
-
...(properties.stroke !== undefined && {
|
|
753
|
-
color: properties.stroke
|
|
754
|
-
}),
|
|
755
|
-
...(properties['stroke-width'] !== undefined && {
|
|
756
|
-
width: properties['stroke-width']
|
|
757
|
-
}),
|
|
758
|
-
...(properties['stroke-opacity'] !== undefined && {
|
|
759
|
-
opacity: properties['stroke-opacity']
|
|
760
|
-
})
|
|
761
|
-
};
|
|
762
|
-
if (Object.keys(stroke).length) {
|
|
763
|
-
style.stroke = stroke;
|
|
764
|
-
}
|
|
765
|
-
if (type !== FEATURE_TYPES.LINE) {
|
|
766
|
-
const fill = {
|
|
767
|
-
...(properties.fill !== undefined && {
|
|
768
|
-
color: properties.fill
|
|
769
|
-
}),
|
|
770
|
-
...(properties['fill-opacity'] !== undefined && {
|
|
771
|
-
opacity: properties['fill-opacity']
|
|
772
|
-
})
|
|
773
|
-
};
|
|
774
|
-
if (Object.keys(fill).length) {
|
|
775
|
-
style.fill = fill;
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
return style;
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
/**
|
|
783
|
-
* set Style from vector tile layer properties.
|
|
784
|
-
* @param {Object} layer vector tile layer.
|
|
785
|
-
* @param {Object} sprites vector tile layer.
|
|
786
|
-
* @param {Number} [order=0]
|
|
787
|
-
* @param {Boolean} [symbolToCircle=false]
|
|
788
|
-
*
|
|
789
|
-
* @returns {StyleOptions} containing all properties for itowns.Style
|
|
790
|
-
*/
|
|
791
|
-
static setFromVectorTileLayer(layer, sprites) {
|
|
792
|
-
let order = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
793
|
-
let symbolToCircle = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
794
|
-
const style = {
|
|
795
|
-
fill: {},
|
|
796
|
-
stroke: {},
|
|
797
|
-
point: {},
|
|
798
|
-
text: {},
|
|
799
|
-
icon: {}
|
|
800
|
-
};
|
|
801
|
-
layer.layout = layer.layout || {};
|
|
802
|
-
layer.paint = layer.paint || {};
|
|
803
|
-
style.order = order;
|
|
804
|
-
if (layer.type === 'fill') {
|
|
805
|
-
const {
|
|
806
|
-
color,
|
|
807
|
-
opacity
|
|
808
|
-
} = rgba2rgb(readVectorProperty(layer.paint['fill-color'] || layer.paint['fill-pattern'], {
|
|
809
|
-
type: 'color'
|
|
810
|
-
}));
|
|
811
|
-
style.fill.color = color;
|
|
812
|
-
style.fill.opacity = readVectorProperty(layer.paint['fill-opacity']) || opacity;
|
|
813
|
-
if (layer.paint['fill-pattern']) {
|
|
814
|
-
try {
|
|
815
|
-
style.fill.pattern = {
|
|
816
|
-
id: layer.paint['fill-pattern'],
|
|
817
|
-
source: sprites.source,
|
|
818
|
-
cropValues: sprites[layer.paint['fill-pattern']]
|
|
819
|
-
};
|
|
820
|
-
} catch (err) {
|
|
821
|
-
err.message = `VTlayer '${layer.id}': argument sprites must not be null when using layer.paint['fill-pattern']`;
|
|
822
|
-
throw err;
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
if (layer.paint['fill-outline-color']) {
|
|
826
|
-
const {
|
|
827
|
-
color,
|
|
828
|
-
opacity
|
|
829
|
-
} = rgba2rgb(readVectorProperty(layer.paint['fill-outline-color'], {
|
|
830
|
-
type: 'color'
|
|
831
|
-
}));
|
|
832
|
-
style.stroke.color = color;
|
|
833
|
-
style.stroke.opacity = opacity;
|
|
834
|
-
style.stroke.width = 1.0;
|
|
835
|
-
style.stroke.dasharray = [];
|
|
836
|
-
}
|
|
837
|
-
} else if (layer.type === 'line') {
|
|
838
|
-
const prepare = readVectorProperty(layer.paint['line-color'], {
|
|
839
|
-
type: 'color'
|
|
840
|
-
});
|
|
841
|
-
const {
|
|
842
|
-
color,
|
|
843
|
-
opacity
|
|
844
|
-
} = rgba2rgb(prepare);
|
|
845
|
-
style.stroke.dasharray = readVectorProperty(layer.paint['line-dasharray']);
|
|
846
|
-
style.stroke.color = color;
|
|
847
|
-
style.stroke.lineCap = layer.layout['line-cap'];
|
|
848
|
-
style.stroke.width = readVectorProperty(layer.paint['line-width']);
|
|
849
|
-
style.stroke.opacity = readVectorProperty(layer.paint['line-opacity']) || opacity;
|
|
850
|
-
} else if (layer.type === 'circle' || symbolToCircle) {
|
|
851
|
-
const {
|
|
852
|
-
color,
|
|
853
|
-
opacity
|
|
854
|
-
} = rgba2rgb(readVectorProperty(layer.paint['circle-color'], {
|
|
855
|
-
type: 'color'
|
|
856
|
-
}));
|
|
857
|
-
style.point.color = color;
|
|
858
|
-
style.point.opacity = opacity;
|
|
859
|
-
style.point.radius = readVectorProperty(layer.paint['circle-radius']);
|
|
860
|
-
} else if (layer.type === 'symbol') {
|
|
861
|
-
// overlapping order
|
|
862
|
-
style.text.zOrder = readVectorProperty(layer.layout['symbol-z-order']);
|
|
863
|
-
if (style.text.zOrder == 'auto') {
|
|
864
|
-
style.text.zOrder = readVectorProperty(layer.layout['symbol-sort-key']) || 'Y';
|
|
865
|
-
} else if (style.text.zOrder == 'viewport-y') {
|
|
866
|
-
style.text.zOrder = 'Y';
|
|
867
|
-
} else if (style.text.zOrder == 'source') {
|
|
868
|
-
style.text.zOrder = 0;
|
|
869
|
-
}
|
|
870
|
-
|
|
871
|
-
// position
|
|
872
|
-
style.text.anchor = readVectorProperty(layer.layout['text-anchor']);
|
|
873
|
-
style.text.offset = readVectorProperty(layer.layout['text-offset']);
|
|
874
|
-
style.text.padding = readVectorProperty(layer.layout['text-padding']);
|
|
875
|
-
style.text.size = readVectorProperty(layer.layout['text-size']);
|
|
876
|
-
style.text.placement = readVectorProperty(layer.layout['symbol-placement']);
|
|
877
|
-
style.text.rotation = readVectorProperty(layer.layout['text-rotation-alignment']);
|
|
878
|
-
|
|
879
|
-
// content
|
|
880
|
-
style.text.field = readVectorProperty(layer.layout['text-field']);
|
|
881
|
-
style.text.wrap = readVectorProperty(layer.layout['text-max-width']);
|
|
882
|
-
style.text.spacing = readVectorProperty(layer.layout['text-letter-spacing']);
|
|
883
|
-
style.text.transform = readVectorProperty(layer.layout['text-transform']);
|
|
884
|
-
style.text.justify = readVectorProperty(layer.layout['text-justify']);
|
|
885
|
-
|
|
886
|
-
// appearance
|
|
887
|
-
const {
|
|
888
|
-
color,
|
|
889
|
-
opacity
|
|
890
|
-
} = rgba2rgb(readVectorProperty(layer.paint['text-color'], {
|
|
891
|
-
type: 'color'
|
|
892
|
-
}));
|
|
893
|
-
style.text.color = color;
|
|
894
|
-
style.text.opacity = readVectorProperty(layer.paint['text-opacity']) || opacity !== undefined && opacity;
|
|
895
|
-
style.text.font = readVectorProperty(layer.layout['text-font']);
|
|
896
|
-
const haloColor = readVectorProperty(layer.paint['text-halo-color'], {
|
|
897
|
-
type: 'color'
|
|
898
|
-
});
|
|
899
|
-
if (haloColor) {
|
|
900
|
-
style.text.haloColor = haloColor.color || haloColor;
|
|
901
|
-
style.text.haloWidth = readVectorProperty(layer.paint['text-halo-width']);
|
|
902
|
-
style.text.haloBlur = readVectorProperty(layer.paint['text-halo-blur']);
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
// additional icon
|
|
906
|
-
const iconImg = readVectorProperty(layer.layout['icon-image']);
|
|
907
|
-
if (iconImg) {
|
|
908
|
-
try {
|
|
909
|
-
style.icon.id = iconImg;
|
|
910
|
-
if (iconImg.stops) {
|
|
911
|
-
const iconCropValue = {
|
|
912
|
-
...(iconImg.base !== undefined && {
|
|
913
|
-
base: iconImg.base
|
|
914
|
-
}),
|
|
915
|
-
stops: iconImg.stops.map(stop => {
|
|
916
|
-
let cropValues = sprites[stop[1]];
|
|
917
|
-
if (stop[1].includes('{')) {
|
|
918
|
-
cropValues = function (p) {
|
|
919
|
-
const id = stop[1].replace(/\{(.+?)\}/g, (a, b) => p[b] || '').trim();
|
|
920
|
-
cropValues = sprites[id];
|
|
921
|
-
return sprites[id];
|
|
922
|
-
};
|
|
923
|
-
}
|
|
924
|
-
return [stop[0], cropValues];
|
|
925
|
-
})
|
|
926
|
-
};
|
|
927
|
-
style.icon.cropValues = iconCropValue;
|
|
928
|
-
} else {
|
|
929
|
-
style.icon.cropValues = sprites[iconImg];
|
|
930
|
-
if (iconImg[0].includes('{')) {
|
|
931
|
-
style.icon.cropValues = function (p) {
|
|
932
|
-
const id = iconImg.replace(/\{(.+?)\}/g, (a, b) => p[b] || '').trim();
|
|
933
|
-
style.icon.cropValues = sprites[id];
|
|
934
|
-
return sprites[id];
|
|
935
|
-
};
|
|
936
|
-
}
|
|
937
|
-
}
|
|
938
|
-
style.icon.source = sprites.source;
|
|
939
|
-
style.icon.size = readVectorProperty(layer.layout['icon-size']) || 1;
|
|
940
|
-
const {
|
|
941
|
-
color,
|
|
942
|
-
opacity
|
|
943
|
-
} = rgba2rgb(readVectorProperty(layer.paint['icon-color'], {
|
|
944
|
-
type: 'color'
|
|
945
|
-
}));
|
|
946
|
-
style.icon.color = color;
|
|
947
|
-
style.icon.opacity = readVectorProperty(layer.paint['icon-opacity']) || opacity !== undefined && opacity;
|
|
948
|
-
} catch (err) {
|
|
949
|
-
err.message = `VTlayer '${layer.id}': argument sprites must not be null when using layer.layout['icon-image']`;
|
|
950
|
-
throw err;
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
}
|
|
954
|
-
// VectorTileSet: by default minZoom = 0 and maxZoom = 24
|
|
955
|
-
// https://docs.mapbox.com/style-spec/reference/layers/#maxzoom and #minzoom
|
|
956
|
-
// Should be move to layer properties, when (if) one mapBox layer will be considered as several itowns layers.
|
|
957
|
-
// issue https://github.com/iTowns/itowns/issues/2153 (last point)
|
|
958
|
-
style.zoom = {
|
|
959
|
-
min: layer.minzoom || 0,
|
|
960
|
-
max: layer.maxzoom || 24
|
|
961
|
-
};
|
|
962
|
-
return style;
|
|
963
|
-
}
|
|
964
|
-
|
|
965
|
-
/**
|
|
966
|
-
* Applies the style.fill to a polygon of the texture canvas.
|
|
967
|
-
* @param {CanvasRenderingContext2D} txtrCtx The Context 2D of the texture canvas.
|
|
968
|
-
* @param {Path2D} polygon The current texture canvas polygon.
|
|
969
|
-
* @param {Number} invCtxScale The ratio to scale line width and radius circle.
|
|
970
|
-
* @param {Boolean} canBeFilled - true if feature.type == FEATURE_TYPES.POLYGON.
|
|
971
|
-
*/
|
|
972
|
-
applyToCanvasPolygon(txtrCtx, polygon, invCtxScale, canBeFilled) {
|
|
973
|
-
const context = this.context;
|
|
974
|
-
// draw line or edge of polygon
|
|
975
|
-
if (this.stroke) {
|
|
976
|
-
// TO DO add possibility of using a pattern (https://github.com/iTowns/itowns/issues/2210)
|
|
977
|
-
this._applyStrokeToPolygon(txtrCtx, invCtxScale, polygon, context);
|
|
978
|
-
}
|
|
979
|
-
|
|
980
|
-
// fill inside of polygon
|
|
981
|
-
if (canBeFilled && this.fill) {
|
|
982
|
-
// canBeFilled can be move to StyleContext in the later PR
|
|
983
|
-
this._applyFillToPolygon(txtrCtx, invCtxScale, polygon, context);
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
|
-
_applyStrokeToPolygon(txtrCtx, invCtxScale, polygon) {
|
|
987
|
-
if (txtrCtx.strokeStyle !== this.stroke.color) {
|
|
988
|
-
txtrCtx.strokeStyle = this.stroke.color;
|
|
989
|
-
}
|
|
990
|
-
const width = (this.stroke.width || 2.0) * invCtxScale;
|
|
991
|
-
if (txtrCtx.lineWidth !== width) {
|
|
992
|
-
txtrCtx.lineWidth = width;
|
|
993
|
-
}
|
|
994
|
-
const alpha = this.stroke.opacity == undefined ? 1.0 : this.stroke.opacity;
|
|
995
|
-
if (alpha !== txtrCtx.globalAlpha && typeof alpha == 'number') {
|
|
996
|
-
txtrCtx.globalAlpha = alpha;
|
|
997
|
-
}
|
|
998
|
-
if (txtrCtx.lineCap !== this.stroke.lineCap) {
|
|
999
|
-
txtrCtx.lineCap = this.stroke.lineCap;
|
|
1000
|
-
}
|
|
1001
|
-
txtrCtx.setLineDash(this.stroke.dasharray.map(a => a * invCtxScale * 2));
|
|
1002
|
-
txtrCtx.stroke(polygon);
|
|
1003
|
-
}
|
|
1004
|
-
async _applyFillToPolygon(txtrCtx, invCtxScale, polygon) {
|
|
1005
|
-
// if (this.fill.pattern && txtrCtx.fillStyle.src !== this.fill.pattern.src) {
|
|
1006
|
-
// need doc for the txtrCtx.fillStyle.src that seems to always be undefined
|
|
1007
|
-
if (this.fill.pattern) {
|
|
1008
|
-
let img = this.fill.pattern;
|
|
1009
|
-
const cropValues = this.fill.pattern.cropValues;
|
|
1010
|
-
if (this.fill.pattern.source) {
|
|
1011
|
-
img = await loadImage(this.fill.pattern.source);
|
|
1012
|
-
}
|
|
1013
|
-
cropImage(img, cropValues);
|
|
1014
|
-
txtrCtx.fillStyle = txtrCtx.createPattern(canvas, 'repeat');
|
|
1015
|
-
if (txtrCtx.fillStyle.setTransform) {
|
|
1016
|
-
txtrCtx.fillStyle.setTransform(matrix.scale(invCtxScale));
|
|
1017
|
-
} else {
|
|
1018
|
-
console.warn('Raster pattern isn\'t completely supported on Ie and edge', txtrCtx.fillStyle);
|
|
1019
|
-
}
|
|
1020
|
-
} else if (txtrCtx.fillStyle !== this.fill.color) {
|
|
1021
|
-
txtrCtx.fillStyle = this.fill.color;
|
|
1022
|
-
}
|
|
1023
|
-
if (this.fill.opacity !== txtrCtx.globalAlpha) {
|
|
1024
|
-
txtrCtx.globalAlpha = this.fill.opacity;
|
|
1025
|
-
}
|
|
1026
|
-
txtrCtx.fill(polygon);
|
|
1027
|
-
}
|
|
1028
|
-
|
|
1029
|
-
/**
|
|
1030
|
-
* Applies this style to a DOM element. Limited to the `text` and `icon`
|
|
1031
|
-
* properties of this style.
|
|
1032
|
-
*
|
|
1033
|
-
* @param {Element} domElement - The element to set the style to.
|
|
1034
|
-
*
|
|
1035
|
-
* @returns {undefined|Promise<HTMLImageElement>}
|
|
1036
|
-
* for a text label: undefined.
|
|
1037
|
-
* for an icon: a Promise resolving with the HTMLImageElement containing the image.
|
|
1038
|
-
*/
|
|
1039
|
-
async applyToHTML(domElement) {
|
|
1040
|
-
if (arguments.length > 1) {
|
|
1041
|
-
console.warn('Deprecated argument sprites. Sprites must be configured in style.');
|
|
1042
|
-
}
|
|
1043
|
-
domElement.style.padding = `${this.text.padding}px`;
|
|
1044
|
-
domElement.style.maxWidth = `${this.text.wrap}em`;
|
|
1045
|
-
domElement.style.color = this.text.color;
|
|
1046
|
-
if (this.text.size > 0) {
|
|
1047
|
-
domElement.style.fontSize = `${this.text.size}px`;
|
|
1048
|
-
}
|
|
1049
|
-
domElement.style.fontFamily = this.text.font.join(',');
|
|
1050
|
-
domElement.style.textTransform = this.text.transform;
|
|
1051
|
-
domElement.style.letterSpacing = `${this.text.spacing}em`;
|
|
1052
|
-
domElement.style.textAlign = this.text.justify;
|
|
1053
|
-
domElement.style['white-space'] = 'pre-line';
|
|
1054
|
-
if (this.text.haloWidth > 0) {
|
|
1055
|
-
domElement.style.setProperty('--text_stroke_display', 'block');
|
|
1056
|
-
domElement.style.setProperty('--text_stroke_width', `${this.text.haloWidth}px`);
|
|
1057
|
-
domElement.style.setProperty('--text_stroke_color', this.text.haloColor);
|
|
1058
|
-
domElement.setAttribute('data-before', domElement.textContent);
|
|
1059
|
-
}
|
|
1060
|
-
if (!this.icon.source) {
|
|
1061
|
-
return;
|
|
1062
|
-
}
|
|
1063
|
-
const icon = document.createElement('img');
|
|
1064
|
-
const iconPromise = new Promise((resolve, reject) => {
|
|
1065
|
-
const opt = {
|
|
1066
|
-
size: this.icon.size,
|
|
1067
|
-
color: this.icon.color,
|
|
1068
|
-
opacity: this.icon.opacity,
|
|
1069
|
-
anchor: this.icon.anchor
|
|
1070
|
-
};
|
|
1071
|
-
icon.onload = () => resolve(_addIcon(icon, domElement, opt));
|
|
1072
|
-
icon.onerror = err => reject(err);
|
|
1073
|
-
});
|
|
1074
|
-
if (!this.icon.cropValues && !this.icon.color) {
|
|
1075
|
-
icon.src = this.icon.source;
|
|
1076
|
-
} else {
|
|
1077
|
-
const cropValues = this.icon.cropValues;
|
|
1078
|
-
const color = this.icon.color;
|
|
1079
|
-
const id = this.icon.id || this.icon.source;
|
|
1080
|
-
const img = await loadImage(this.icon.source);
|
|
1081
|
-
const imgd = cropImage(img, cropValues);
|
|
1082
|
-
const imgdColored = replaceWhitePxl(imgd, color, id);
|
|
1083
|
-
canvas.getContext('2d').putImageData(imgdColored, 0, 0);
|
|
1084
|
-
icon.src = canvas.toDataURL('image/png');
|
|
1085
|
-
}
|
|
1086
|
-
return iconPromise;
|
|
1087
|
-
}
|
|
1088
|
-
|
|
1089
|
-
/**
|
|
1090
|
-
* Gets the values corresponding to the anchor of the text. It is
|
|
1091
|
-
* proportions, to use with a `translate()` and a `transform` property.
|
|
1092
|
-
*
|
|
1093
|
-
* @return {Number[]} Two percentage values, for x and y respectively.
|
|
1094
|
-
*/
|
|
1095
|
-
getTextAnchorPosition() {
|
|
1096
|
-
if (typeof this.text.anchor === 'string') {
|
|
1097
|
-
if (Object.keys(textAnchorPosition).includes(this.text.anchor)) {
|
|
1098
|
-
return textAnchorPosition[this.text.anchor];
|
|
1099
|
-
} else {
|
|
1100
|
-
console.error(`${this.text.anchor} is not a valid input for Style.text.anchor parameter.`);
|
|
1101
|
-
return textAnchorPosition.center;
|
|
1102
|
-
}
|
|
1103
|
-
} else {
|
|
1104
|
-
return this.text.anchor;
|
|
1105
|
-
}
|
|
1106
|
-
}
|
|
1107
|
-
}
|
|
1108
|
-
|
|
1109
|
-
// Add custom style sheet with iTowns specifics
|
|
1110
|
-
const CustomStyle = {
|
|
1111
|
-
itowns_stroke_single_before
|
|
1112
|
-
};
|
|
1113
|
-
const customStyleSheet = document.createElement('style');
|
|
1114
|
-
customStyleSheet.type = 'text/css';
|
|
1115
|
-
Object.keys(CustomStyle).forEach(key => {
|
|
1116
|
-
customStyleSheet.innerHTML += `${CustomStyle[key]}\n\n`;
|
|
1117
|
-
});
|
|
1118
|
-
if (typeof document !== 'undefined') {
|
|
1119
|
-
document.getElementsByTagName('head')[0].appendChild(customStyleSheet);
|
|
1120
|
-
}
|
|
1121
|
-
export default Style;
|