itowns 2.44.3-next.30 → 2.44.3-next.31
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/dist/itowns.js +1 -1
- package/dist/itowns.js.map +1 -1
- package/examples/config.json +1 -0
- package/examples/source_file_kml_raster_usgs.html +0 -1
- package/examples/vector_tile_mapbox_raster.html +91 -0
- package/lib/Converter/Feature2Texture.js +3 -0
- package/lib/Core/Style.js +57 -39
- package/lib/Layer/LabelLayer.js +26 -18
- package/lib/Parser/VectorTileParser.js +41 -28
- package/lib/Renderer/Label2DRenderer.js +9 -7
- package/lib/Source/VectorTilesSource.js +29 -17
- package/package.json +1 -1
package/examples/config.json
CHANGED
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"Vector tiles": {
|
|
32
32
|
"vector_tile_raster_3d": "Raster on 3D map",
|
|
33
33
|
"vector_tile_raster_2d": "Raster on 2D map",
|
|
34
|
+
"vector_tile_mapbox_raster": "Mapbox Vector Tiles to raster",
|
|
34
35
|
"vector_tile_3d_mesh": "Vector tile to 3d objects",
|
|
35
36
|
"vector_tile_3d_mesh_mapbox": "Mapbox Vector tile to 3d objects",
|
|
36
37
|
"vector_tile_dragndrop": "Drag and drop a style"
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
<html>
|
|
2
|
+
<head>
|
|
3
|
+
<title>Itowns - vector-tiles 2d </title>
|
|
4
|
+
|
|
5
|
+
<meta charset="UTF-8" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
|
|
8
|
+
<link
|
|
9
|
+
rel="stylesheet"
|
|
10
|
+
type="text/css"
|
|
11
|
+
href="css/example.css"
|
|
12
|
+
/>
|
|
13
|
+
<link
|
|
14
|
+
rel="stylesheet"
|
|
15
|
+
type="text/css"
|
|
16
|
+
href="css/LoadingScreen.css"
|
|
17
|
+
/>
|
|
18
|
+
|
|
19
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.6/dat.gui.min.js"></script>
|
|
20
|
+
</head>
|
|
21
|
+
<body>
|
|
22
|
+
<div id="viewerDiv"></div>
|
|
23
|
+
|
|
24
|
+
<!-- Import iTowns source code -->
|
|
25
|
+
<script src="../dist/itowns.js"></script>
|
|
26
|
+
<script src="../dist/debug.js"></script>
|
|
27
|
+
<!-- Import iTowns LoadingScreen and GuiTools plugins -->
|
|
28
|
+
<script src="js/GUI/GuiTools.js"></script>
|
|
29
|
+
<script src="js/GUI/LoadingScreen.js"></script>
|
|
30
|
+
|
|
31
|
+
<script>
|
|
32
|
+
const typeView = 'Planar';
|
|
33
|
+
// const typeView = 'Globe';
|
|
34
|
+
|
|
35
|
+
// `viewerDiv` will contain iTowns' rendering area (`<canvas>`)
|
|
36
|
+
var viewerDiv = document.getElementById('viewerDiv');
|
|
37
|
+
let view;
|
|
38
|
+
|
|
39
|
+
if (typeView === 'Globe') {
|
|
40
|
+
const coord = new itowns.Coordinates('EPSG:4326', 2.351323, 48.856712); // Paris
|
|
41
|
+
// const coord = new itowns.Coordinates("EPSG:4326", 60.599525, 56.834341); // Yekaterinburg
|
|
42
|
+
const placement = {
|
|
43
|
+
coord,
|
|
44
|
+
range: 950000,
|
|
45
|
+
};
|
|
46
|
+
view = new itowns.GlobeView(viewerDiv, placement);
|
|
47
|
+
} else if (typeView === 'Planar') {
|
|
48
|
+
// Define geographic extent: CRS, min/max X, min/max Y
|
|
49
|
+
var extent = new itowns.Extent(
|
|
50
|
+
'EPSG:3857',
|
|
51
|
+
-20037508.342789244, 20037508.342789244,
|
|
52
|
+
-20037508.342789255, 20037508.342789244);
|
|
53
|
+
|
|
54
|
+
// Instanciate PlanarView
|
|
55
|
+
view = new itowns.PlanarView(viewerDiv, extent, {
|
|
56
|
+
maxSubdivisionLevel: 20,
|
|
57
|
+
controls: {
|
|
58
|
+
// We do not want the user to zoom out too much
|
|
59
|
+
maxAltitude: 40000000,
|
|
60
|
+
// We want to keep the rotation disabled, to only have a view from the top
|
|
61
|
+
enableRotation: false,
|
|
62
|
+
// Don't zoom too much on smart zoom
|
|
63
|
+
smartTravelHeightMax: 100000,
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const debugMenu = new GuiTools("menuDiv", view);
|
|
69
|
+
setupLoadingScreen(viewerDiv, view);
|
|
70
|
+
|
|
71
|
+
const source = new itowns.VectorTilesSource({
|
|
72
|
+
style: "mapbox://styles/mapbox/streets-v8",
|
|
73
|
+
accessToken:
|
|
74
|
+
"pk.eyJ1IjoiZnRvcm9tYW5vZmYiLCJhIjoiY2xrc2Zpa2o3MDQxNTNxcG5sczJyaTlncyJ9.5KFKdMLIiy-b_fAjSVhjCQ",
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const layer = new itowns.ColorLayer("vector-map", {
|
|
78
|
+
source,
|
|
79
|
+
noTextureParentOutsideLimit: true,
|
|
80
|
+
addLabelLayer: true,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
view.addLayer(layer).then(() => {
|
|
84
|
+
debugMenu.addLayerGUI.bind(debugMenu);
|
|
85
|
+
itowns.ColorLayersOrdering.moveLayerToIndex(view, "vector-map", 15);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
debug.createTileDebugUI(debugMenu.gui, view);
|
|
89
|
+
</script>
|
|
90
|
+
</body>
|
|
91
|
+
</html>
|
|
@@ -71,6 +71,9 @@ function drawFeature(ctx, feature, extent, invCtxScale) {
|
|
|
71
71
|
for (const geometry of feature.geometries) {
|
|
72
72
|
if (Extent.intersectsExtent(geometry.extent, extent)) {
|
|
73
73
|
context.setGeometry(geometry);
|
|
74
|
+
if (style.zoom.min > style.context.zoom || style.zoom.max <= style.context.zoom) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
74
77
|
if (feature.type === FEATURE_TYPES.POINT && style.point) {
|
|
75
78
|
// cross multiplication to know in the extent system the real size of
|
|
76
79
|
// the point
|
package/lib/Core/Style.js
CHANGED
|
@@ -90,18 +90,18 @@ async function loadImage(source) {
|
|
|
90
90
|
}
|
|
91
91
|
return (await promise).image;
|
|
92
92
|
}
|
|
93
|
-
function cropImage(img) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
canvas.width =
|
|
99
|
-
canvas.height =
|
|
93
|
+
function cropImage(img, cropValues) {
|
|
94
|
+
const x = cropValues.x || 0;
|
|
95
|
+
const y = cropValues.y || 0;
|
|
96
|
+
const width = cropValues.width || img.naturalWidth;
|
|
97
|
+
const height = cropValues.height || img.naturalHeight;
|
|
98
|
+
canvas.width = width;
|
|
99
|
+
canvas.height = height;
|
|
100
100
|
const ctx = canvas.getContext('2d', {
|
|
101
101
|
willReadFrequently: true
|
|
102
102
|
});
|
|
103
|
-
ctx.drawImage(img,
|
|
104
|
-
return ctx.getImageData(0, 0,
|
|
103
|
+
ctx.drawImage(img, x, y, width, height, 0, 0, width, height);
|
|
104
|
+
return ctx.getImageData(0, 0, width, height);
|
|
105
105
|
}
|
|
106
106
|
function replaceWhitePxl(imgd, color, id) {
|
|
107
107
|
if (!color) {
|
|
@@ -166,7 +166,7 @@ function defineStyleProperty(style, category, parameter, userValue, defaultValue
|
|
|
166
166
|
return readExpression(dataValue, style.context);
|
|
167
167
|
}
|
|
168
168
|
if (defaultValue instanceof Function) {
|
|
169
|
-
return defaultValue(style.context.properties, style.context);
|
|
169
|
+
return defaultValue(style.context.properties, style.context) ?? defaultValue;
|
|
170
170
|
}
|
|
171
171
|
return defaultValue;
|
|
172
172
|
},
|
|
@@ -294,15 +294,12 @@ function _addIcon(icon, domElement, opt) {
|
|
|
294
294
|
}
|
|
295
295
|
|
|
296
296
|
/**
|
|
297
|
-
* An object that can contain any properties (
|
|
297
|
+
* An object that can contain any properties (zoom, fill, stroke, point,
|
|
298
298
|
* text or/and icon) and sub properties of a Style.<br/>
|
|
299
299
|
* Used for the instanciation of a {@link Style}.
|
|
300
300
|
*
|
|
301
301
|
* @typedef {Object} StyleOptions
|
|
302
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
303
|
* @property {Object} [zoom] - Level on which to display the feature
|
|
307
304
|
* @property {Number} [zoom.max] - max level
|
|
308
305
|
* @property {Number} [zoom.min] - min level
|
|
@@ -460,8 +457,6 @@ function _addIcon(icon, domElement, opt) {
|
|
|
460
457
|
* The first parameter of functions used to set `Style` properties is always an object containing
|
|
461
458
|
* the properties of the features displayed with the current `Style` instance.
|
|
462
459
|
*
|
|
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
460
|
* @property {Object} fill - Polygons and fillings style.
|
|
466
461
|
* @property {String|Function|THREE.Color} fill.color - Defines the main color of the filling. Can be
|
|
467
462
|
* any [valid color
|
|
@@ -611,14 +606,13 @@ function _addIcon(icon, domElement, opt) {
|
|
|
611
606
|
class Style {
|
|
612
607
|
/**
|
|
613
608
|
* @param {StyleOptions} [params={}] An object that contain any properties
|
|
614
|
-
* (
|
|
609
|
+
* (zoom, fill, stroke, point, text or/and icon)
|
|
615
610
|
* and sub properties of a Style ({@link StyleOptions}).
|
|
616
611
|
*/
|
|
617
612
|
constructor() {
|
|
618
613
|
let params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
619
614
|
this.isStyle = true;
|
|
620
615
|
this.context = new StyleContext();
|
|
621
|
-
this.order = params.order || 0;
|
|
622
616
|
params.zoom = params.zoom || {};
|
|
623
617
|
params.fill = params.fill || {};
|
|
624
618
|
params.stroke = params.stroke || {};
|
|
@@ -783,14 +777,12 @@ class Style {
|
|
|
783
777
|
* set Style from vector tile layer properties.
|
|
784
778
|
* @param {Object} layer vector tile layer.
|
|
785
779
|
* @param {Object} sprites vector tile layer.
|
|
786
|
-
* @param {Number} [order=0]
|
|
787
780
|
* @param {Boolean} [symbolToCircle=false]
|
|
788
781
|
*
|
|
789
782
|
* @returns {StyleOptions} containing all properties for itowns.Style
|
|
790
783
|
*/
|
|
791
784
|
static setFromVectorTileLayer(layer, sprites) {
|
|
792
|
-
let
|
|
793
|
-
let symbolToCircle = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
785
|
+
let symbolToCircle = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
794
786
|
const style = {
|
|
795
787
|
fill: {},
|
|
796
788
|
stroke: {},
|
|
@@ -800,7 +792,6 @@ class Style {
|
|
|
800
792
|
};
|
|
801
793
|
layer.layout = layer.layout || {};
|
|
802
794
|
layer.paint = layer.paint || {};
|
|
803
|
-
style.order = order;
|
|
804
795
|
if (layer.type === 'fill') {
|
|
805
796
|
const {
|
|
806
797
|
color,
|
|
@@ -832,7 +823,8 @@ class Style {
|
|
|
832
823
|
style.stroke.color = color;
|
|
833
824
|
style.stroke.opacity = opacity;
|
|
834
825
|
style.stroke.width = 1.0;
|
|
835
|
-
|
|
826
|
+
} else {
|
|
827
|
+
style.stroke.width = 0.0;
|
|
836
828
|
}
|
|
837
829
|
} else if (layer.type === 'line') {
|
|
838
830
|
const prepare = readVectorProperty(layer.paint['line-color'], {
|
|
@@ -858,6 +850,8 @@ class Style {
|
|
|
858
850
|
style.point.opacity = opacity;
|
|
859
851
|
style.point.radius = readVectorProperty(layer.paint['circle-radius']);
|
|
860
852
|
} else if (layer.type === 'symbol') {
|
|
853
|
+
// if symbol we shouldn't draw stroke but defaut value is 1.
|
|
854
|
+
style.stroke.width = 0.0;
|
|
861
855
|
// overlapping order
|
|
862
856
|
style.text.zOrder = readVectorProperty(layer.layout['symbol-z-order']);
|
|
863
857
|
if (style.text.zOrder == 'auto') {
|
|
@@ -878,7 +872,7 @@ class Style {
|
|
|
878
872
|
|
|
879
873
|
// content
|
|
880
874
|
style.text.field = readVectorProperty(layer.layout['text-field']);
|
|
881
|
-
style.text.wrap = readVectorProperty(layer.layout['text-max-width']);
|
|
875
|
+
style.text.wrap = readVectorProperty(layer.layout['text-max-width']); // Units ems
|
|
882
876
|
style.text.spacing = readVectorProperty(layer.layout['text-letter-spacing']);
|
|
883
877
|
style.text.transform = readVectorProperty(layer.layout['text-transform']);
|
|
884
878
|
style.text.justify = readVectorProperty(layer.layout['text-justify']);
|
|
@@ -905,6 +899,12 @@ class Style {
|
|
|
905
899
|
// additional icon
|
|
906
900
|
const iconImg = readVectorProperty(layer.layout['icon-image']);
|
|
907
901
|
if (iconImg) {
|
|
902
|
+
const cropValueDefault = {
|
|
903
|
+
x: 0,
|
|
904
|
+
y: 0,
|
|
905
|
+
width: 1,
|
|
906
|
+
height: 1
|
|
907
|
+
};
|
|
908
908
|
try {
|
|
909
909
|
style.icon.id = iconImg;
|
|
910
910
|
if (iconImg.stops) {
|
|
@@ -917,9 +917,15 @@ class Style {
|
|
|
917
917
|
if (stop[1].includes('{')) {
|
|
918
918
|
cropValues = function (p) {
|
|
919
919
|
const id = stop[1].replace(/\{(.+?)\}/g, (a, b) => p[b] || '').trim();
|
|
920
|
-
cropValues
|
|
920
|
+
if (cropValues === undefined) {
|
|
921
|
+
// const warning = `WARNING: "${id}" not found in sprite file`;
|
|
922
|
+
sprites[id] = cropValueDefault; // or return cropValueDefault;
|
|
923
|
+
}
|
|
921
924
|
return sprites[id];
|
|
922
925
|
};
|
|
926
|
+
} else if (cropValues === undefined) {
|
|
927
|
+
// const warning = `WARNING: "${stop[1]}" not found in sprite file`;
|
|
928
|
+
cropValues = cropValueDefault;
|
|
923
929
|
}
|
|
924
930
|
return [stop[0], cropValues];
|
|
925
931
|
})
|
|
@@ -927,24 +933,33 @@ class Style {
|
|
|
927
933
|
style.icon.cropValues = iconCropValue;
|
|
928
934
|
} else {
|
|
929
935
|
style.icon.cropValues = sprites[iconImg];
|
|
930
|
-
if (iconImg
|
|
936
|
+
if (iconImg.includes('{')) {
|
|
931
937
|
style.icon.cropValues = function (p) {
|
|
932
938
|
const id = iconImg.replace(/\{(.+?)\}/g, (a, b) => p[b] || '').trim();
|
|
933
|
-
|
|
939
|
+
if (sprites[id] === undefined) {
|
|
940
|
+
// const warning = `WARNING: "${id}" not found in sprite file`;
|
|
941
|
+
sprites[id] = cropValueDefault; // or return cropValueDefault;
|
|
942
|
+
}
|
|
934
943
|
return sprites[id];
|
|
935
944
|
};
|
|
945
|
+
} else if (sprites[iconImg] === undefined) {
|
|
946
|
+
// const warning = `WARNING: "${iconImg}" not found in sprite file`;
|
|
947
|
+
style.icon.cropValues = cropValueDefault;
|
|
936
948
|
}
|
|
937
949
|
}
|
|
938
950
|
style.icon.source = sprites.source;
|
|
939
|
-
style.icon.size = readVectorProperty(layer.layout['icon-size'])
|
|
951
|
+
style.icon.size = readVectorProperty(layer.layout['icon-size']) ?? 1;
|
|
940
952
|
const {
|
|
941
953
|
color,
|
|
942
954
|
opacity
|
|
943
955
|
} = rgba2rgb(readVectorProperty(layer.paint['icon-color'], {
|
|
944
956
|
type: 'color'
|
|
945
957
|
}));
|
|
946
|
-
style
|
|
947
|
-
|
|
958
|
+
// https://docs.mapbox.com/style-spec/reference/layers/#paint-symbol-icon-color
|
|
959
|
+
if (iconImg.sdf) {
|
|
960
|
+
style.icon.color = color;
|
|
961
|
+
}
|
|
962
|
+
style.icon.opacity = readVectorProperty(layer.paint['icon-opacity']) ?? (opacity !== undefined && opacity);
|
|
948
963
|
} catch (err) {
|
|
949
964
|
err.message = `VTlayer '${layer.id}': argument sprites must not be null when using layer.layout['icon-image']`;
|
|
950
965
|
throw err;
|
|
@@ -970,28 +985,27 @@ class Style {
|
|
|
970
985
|
* @param {Boolean} canBeFilled - true if feature.type == FEATURE_TYPES.POLYGON.
|
|
971
986
|
*/
|
|
972
987
|
applyToCanvasPolygon(txtrCtx, polygon, invCtxScale, canBeFilled) {
|
|
973
|
-
const context = this.context;
|
|
974
988
|
// draw line or edge of polygon
|
|
975
|
-
if (this.stroke) {
|
|
989
|
+
if (this.stroke.width > 0) {
|
|
976
990
|
// TO DO add possibility of using a pattern (https://github.com/iTowns/itowns/issues/2210)
|
|
977
|
-
this._applyStrokeToPolygon(txtrCtx, invCtxScale, polygon
|
|
991
|
+
this._applyStrokeToPolygon(txtrCtx, invCtxScale, polygon);
|
|
978
992
|
}
|
|
979
993
|
|
|
980
994
|
// fill inside of polygon
|
|
981
|
-
if (canBeFilled && this.fill) {
|
|
995
|
+
if (canBeFilled && (this.fill.pattern || this.fill.color)) {
|
|
982
996
|
// canBeFilled can be move to StyleContext in the later PR
|
|
983
|
-
this._applyFillToPolygon(txtrCtx, invCtxScale, polygon
|
|
997
|
+
this._applyFillToPolygon(txtrCtx, invCtxScale, polygon);
|
|
984
998
|
}
|
|
985
999
|
}
|
|
986
1000
|
_applyStrokeToPolygon(txtrCtx, invCtxScale, polygon) {
|
|
987
1001
|
if (txtrCtx.strokeStyle !== this.stroke.color) {
|
|
988
1002
|
txtrCtx.strokeStyle = this.stroke.color;
|
|
989
1003
|
}
|
|
990
|
-
const width =
|
|
1004
|
+
const width = this.stroke.width * invCtxScale;
|
|
991
1005
|
if (txtrCtx.lineWidth !== width) {
|
|
992
1006
|
txtrCtx.lineWidth = width;
|
|
993
1007
|
}
|
|
994
|
-
const alpha = this.stroke.opacity
|
|
1008
|
+
const alpha = this.stroke.opacity;
|
|
995
1009
|
if (alpha !== txtrCtx.globalAlpha && typeof alpha == 'number') {
|
|
996
1010
|
txtrCtx.globalAlpha = alpha;
|
|
997
1011
|
}
|
|
@@ -1006,7 +1020,9 @@ class Style {
|
|
|
1006
1020
|
// need doc for the txtrCtx.fillStyle.src that seems to always be undefined
|
|
1007
1021
|
if (this.fill.pattern) {
|
|
1008
1022
|
let img = this.fill.pattern;
|
|
1009
|
-
const cropValues =
|
|
1023
|
+
const cropValues = {
|
|
1024
|
+
...this.fill.pattern.cropValues
|
|
1025
|
+
};
|
|
1010
1026
|
if (this.fill.pattern.source) {
|
|
1011
1027
|
img = await loadImage(this.fill.pattern.source);
|
|
1012
1028
|
}
|
|
@@ -1074,7 +1090,9 @@ class Style {
|
|
|
1074
1090
|
if (!this.icon.cropValues && !this.icon.color) {
|
|
1075
1091
|
icon.src = this.icon.source;
|
|
1076
1092
|
} else {
|
|
1077
|
-
const cropValues =
|
|
1093
|
+
const cropValues = {
|
|
1094
|
+
...this.icon.cropValues
|
|
1095
|
+
};
|
|
1078
1096
|
const color = this.icon.color;
|
|
1079
1097
|
const id = this.icon.id || this.icon.source;
|
|
1080
1098
|
const img = await loadImage(this.icon.source);
|
package/lib/Layer/LabelLayer.js
CHANGED
|
@@ -5,7 +5,6 @@ import GeometryLayer from "./GeometryLayer.js";
|
|
|
5
5
|
import Coordinates from "../Core/Geographic/Coordinates.js";
|
|
6
6
|
import Extent from "../Core/Geographic/Extent.js";
|
|
7
7
|
import Label from "../Core/Label.js";
|
|
8
|
-
import { FEATURE_TYPES } from "../Core/Feature.js";
|
|
9
8
|
import { readExpression, StyleContext } from "../Core/Style.js";
|
|
10
9
|
import { ScreenGrid } from "../Renderer/Label2DRenderer.js";
|
|
11
10
|
const context = new StyleContext();
|
|
@@ -238,9 +237,10 @@ class LabelLayer extends GeometryLayer {
|
|
|
238
237
|
coord.crs = data.crs;
|
|
239
238
|
context.setZoom(extentOrTile.zoom);
|
|
240
239
|
data.features.forEach(f => {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
240
|
+
if (f.style.text) {
|
|
241
|
+
if (Object.keys(f.style.text).length === 0) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
244
|
}
|
|
245
245
|
context.setFeature(f);
|
|
246
246
|
const featureField = f.style?.text?.field;
|
|
@@ -252,19 +252,11 @@ class LabelLayer extends GeometryLayer {
|
|
|
252
252
|
// determine if the altitude needs update with ElevationLayer
|
|
253
253
|
labels.needsAltitude = labels.needsAltitude || this.forceClampToTerrain === true || isDefaultElevationStyle && !f.hasRawElevationData;
|
|
254
254
|
f.geometries.forEach(g => {
|
|
255
|
-
// NOTE: this only works because only POINT is supported, it
|
|
256
|
-
// needs more work for LINE and POLYGON
|
|
257
|
-
coord.setFromArray(f.vertices, g.size * g.indices[0].offset);
|
|
258
|
-
// Transform coordinate to data.crs projection
|
|
259
|
-
coord.applyMatrix4(data.matrixWorld);
|
|
260
|
-
if (!_extent.isPointInside(coord)) {
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
const geometryField = g.properties.style && g.properties.style.text && g.properties.style.text.field;
|
|
264
255
|
context.setGeometry(g);
|
|
265
|
-
let content;
|
|
266
256
|
this.style.setContext(context);
|
|
267
257
|
const layerField = this.style.text && this.style.text.field;
|
|
258
|
+
const geometryField = g.properties.style && g.properties.style.text && g.properties.style.text.field;
|
|
259
|
+
let content;
|
|
268
260
|
if (this.labelDomelement) {
|
|
269
261
|
content = readExpression(this.labelDomelement, context);
|
|
270
262
|
} else if (!geometryField && !featureField && !layerField) {
|
|
@@ -273,10 +265,26 @@ class LabelLayer extends GeometryLayer {
|
|
|
273
265
|
return;
|
|
274
266
|
}
|
|
275
267
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
268
|
+
if (this.style.zoom.min > this.style.context.zoom || this.style.zoom.max <= this.style.context.zoom) {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// NOTE: this only works fine for POINT.
|
|
273
|
+
// It needs more work for LINE and POLYGON as we currently only use the first point of the entity
|
|
274
|
+
|
|
275
|
+
g.indices.forEach(i => {
|
|
276
|
+
coord.setFromArray(f.vertices, g.size * i.offset);
|
|
277
|
+
// Transform coordinate to data.crs projection
|
|
278
|
+
coord.applyMatrix4(data.matrixWorld);
|
|
279
|
+
if (!_extent.isPointInside(coord)) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
const label = new Label(content, coord.clone(), this.style);
|
|
283
|
+
label.layerId = this.id;
|
|
284
|
+
label.order = f.order;
|
|
285
|
+
label.padding = this.margin || label.padding;
|
|
286
|
+
labels.push(label);
|
|
287
|
+
});
|
|
280
288
|
});
|
|
281
289
|
});
|
|
282
290
|
return labels;
|
|
@@ -105,9 +105,10 @@ function vtFeatureToFeatureGeometry(vtFeature, feature) {
|
|
|
105
105
|
function readPBF(file, options) {
|
|
106
106
|
options.out = options.out || {};
|
|
107
107
|
const vectorTile = new VectorTile(new Protobuf(file));
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
108
|
+
const vtLayerNames = Object.keys(vectorTile.layers);
|
|
109
|
+
const collection = new FeatureCollection(options.out);
|
|
110
|
+
if (vtLayerNames.length < 1) {
|
|
111
|
+
return Promise.resolve(collection);
|
|
111
112
|
}
|
|
112
113
|
|
|
113
114
|
// x,y,z tile coordinates
|
|
@@ -117,44 +118,56 @@ function readPBF(file, options) {
|
|
|
117
118
|
// https://alastaira.wordpress.com/2011/07/06/converting-tms-tile-coordinates-to-googlebingosm-tile-coordinates/
|
|
118
119
|
// Only if the layer.origin is top
|
|
119
120
|
const y = options.in.isInverted ? options.extent.row : (1 << z) - options.extent.row - 1;
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const size = vFeature.extent * 2 ** z;
|
|
121
|
+
const vFeature0 = vectorTile.layers[vtLayerNames[0]];
|
|
122
|
+
// TODO: verify if size is correct because is computed with only one feature (vFeature0).
|
|
123
|
+
const size = vFeature0.extent * 2 ** z;
|
|
124
124
|
const center = -0.5 * size;
|
|
125
125
|
collection.scale.set(globalExtent.x / size, -globalExtent.y / size, 1);
|
|
126
|
-
collection.position.set(
|
|
126
|
+
collection.position.set(vFeature0.extent * x + center, vFeature0.extent * y + center, 0).multiply(collection.scale);
|
|
127
127
|
collection.updateMatrixWorld();
|
|
128
|
-
|
|
129
|
-
if (!options.in.layers[
|
|
130
|
-
return;
|
|
128
|
+
vtLayerNames.forEach(vtLayerName => {
|
|
129
|
+
if (!options.in.layers[vtLayerName]) {
|
|
130
|
+
return Promise.resolve(collection);
|
|
131
131
|
}
|
|
132
|
-
const
|
|
133
|
-
for (let i =
|
|
134
|
-
const vtFeature =
|
|
132
|
+
const vectorTileLayer = vectorTile.layers[vtLayerName];
|
|
133
|
+
for (let i = vectorTileLayer.length - 1; i >= 0; i--) {
|
|
134
|
+
const vtFeature = vectorTileLayer.feature(i);
|
|
135
135
|
vtFeature.tileNumbers = {
|
|
136
136
|
x,
|
|
137
137
|
y: options.extent.row,
|
|
138
138
|
z
|
|
139
139
|
};
|
|
140
|
-
|
|
140
|
+
// Find layers where this vtFeature is used
|
|
141
|
+
const layers = options.in.layers[vtLayerName].filter(l => l.filterExpression.filter({
|
|
141
142
|
zoom: z
|
|
142
|
-
}, vtFeature)
|
|
143
|
+
}, vtFeature));
|
|
144
|
+
for (const layer of layers) {
|
|
145
|
+
const feature = collection.requestFeatureById(layer.id, vtFeature.type - 1);
|
|
146
|
+
feature.id = layer.id;
|
|
147
|
+
feature.order = layer.order;
|
|
148
|
+
feature.style = options.in.styles[feature.id];
|
|
149
|
+
vtFeatureToFeatureGeometry(vtFeature, feature);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/*
|
|
153
|
+
// This optimization is not fully working and need to be reassessed
|
|
154
|
+
// (see https://github.com/iTowns/itowns/pull/2469/files#r1861802136)
|
|
143
155
|
let feature;
|
|
144
156
|
for (const layer of layers) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
+
if (!feature) {
|
|
158
|
+
feature = collection.requestFeatureById(layer.id, vtFeature.type - 1);
|
|
159
|
+
feature.id = layer.id;
|
|
160
|
+
feature.order = layer.order;
|
|
161
|
+
feature.style = options.in.styles[feature.id];
|
|
162
|
+
vtFeatureToFeatureGeometry(vtFeature, feature);
|
|
163
|
+
} else if (!collection.features.find(f => f.id === layer.id)) {
|
|
164
|
+
feature = collection.newFeatureByReference(feature);
|
|
165
|
+
feature.id = layer.id;
|
|
166
|
+
feature.order = layer.order;
|
|
167
|
+
feature.style = options.in.styles[feature.id];
|
|
168
|
+
}
|
|
157
169
|
}
|
|
170
|
+
*/
|
|
158
171
|
}
|
|
159
172
|
});
|
|
160
173
|
collection.removeEmptyFeature();
|
|
@@ -167,13 +167,15 @@ class Label2DRenderer {
|
|
|
167
167
|
if (!frustum.containsPoint(worldPosition.applyMatrix4(camera.matrixWorldInverse)) ||
|
|
168
168
|
// Check if globe horizon culls the label
|
|
169
169
|
// Do some horizon culling (if possible) if the tiles level is small enough.
|
|
170
|
-
label.horizonCullingPoint && GlobeLayer.horizonCulling(label.horizonCullingPoint)
|
|
171
|
-
//
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
170
|
+
label.horizonCullingPoint && GlobeLayer.horizonCulling(label.horizonCullingPoint)
|
|
171
|
+
// Why do we might need this part ?
|
|
172
|
+
// || // Check if content isn't present in visible labels
|
|
173
|
+
// this.grid.visible.some((l) => {
|
|
174
|
+
// // TODO for icon without text filter by position
|
|
175
|
+
// const textContent = label.content.textContent;
|
|
176
|
+
// return textContent !== '' && l.content.textContent.toLowerCase() == textContent.toLowerCase();
|
|
177
|
+
// })
|
|
178
|
+
) {
|
|
177
179
|
label.visible = false;
|
|
178
180
|
} else {
|
|
179
181
|
// projecting world position label
|