itowns 2.44.3-next.3 → 2.44.3-next.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/CODING.md +1 -1
  2. package/CONTRIBUTORS.md +1 -0
  3. package/dist/debug.js +1 -1
  4. package/dist/debug.js.map +1 -1
  5. package/dist/itowns.js +1 -1
  6. package/dist/itowns.js.LICENSE.txt +0 -2
  7. package/dist/itowns.js.map +1 -1
  8. package/dist/itowns_widgets.js +1 -1
  9. package/dist/itowns_widgets.js.map +1 -1
  10. package/examples/3dtiles_loader.html +109 -45
  11. package/examples/config.json +2 -10
  12. package/examples/entwine_3d_loader.html +3 -1
  13. package/examples/entwine_simple_loader.html +1 -1
  14. package/examples/images/itowns_logo.svg +123 -0
  15. package/examples/js/plugins/COGParser.js +1 -1
  16. package/examples/jsm/OGC3DTilesHelper.js +1 -1
  17. package/examples/layers/JSONLayers/GeoidMNT.json +3 -1
  18. package/examples/source_file_geojson_3d.html +0 -1
  19. package/examples/source_stream_wfs_raster.html +0 -7
  20. package/lib/Controls/GlobeControls.js +45 -28
  21. package/lib/Controls/StateControl.js +5 -2
  22. package/lib/Converter/Feature2Mesh.js +10 -4
  23. package/lib/Converter/Feature2Texture.js +3 -1
  24. package/lib/Converter/convertToTile.js +3 -8
  25. package/lib/Converter/textureConverter.js +3 -4
  26. package/lib/Core/Deprecated/Undeprecator.js +0 -1
  27. package/lib/Core/Feature.js +1 -2
  28. package/lib/Core/Geographic/Coordinates.js +143 -132
  29. package/lib/Core/Geographic/Crs.js +140 -145
  30. package/lib/Core/Geographic/Extent.js +72 -267
  31. package/lib/Core/Geographic/GeoidGrid.js +1 -1
  32. package/lib/Core/Math/Ellipsoid.js +62 -21
  33. package/lib/Core/Prefab/Globe/Atmosphere.js +4 -8
  34. package/lib/Core/Prefab/Globe/GlobeLayer.js +22 -15
  35. package/lib/Core/Prefab/Globe/GlobeTileBuilder.js +111 -0
  36. package/lib/Core/Prefab/GlobeView.js +2 -7
  37. package/lib/Core/Prefab/Planar/PlanarLayer.js +17 -11
  38. package/lib/Core/Prefab/Planar/PlanarTileBuilder.js +43 -43
  39. package/lib/Core/Prefab/TileBuilder.js +27 -32
  40. package/lib/Core/Prefab/computeBufferTileGeometry.js +189 -130
  41. package/lib/Core/Style.js +3 -3
  42. package/lib/Core/Tile/Tile.js +219 -0
  43. package/lib/Core/Tile/TileGrid.js +43 -0
  44. package/lib/Core/TileGeometry.js +112 -28
  45. package/lib/Core/TileMesh.js +3 -3
  46. package/lib/Core/View.js +15 -8
  47. package/lib/Layer/C3DTilesLayer.js +20 -16
  48. package/lib/Layer/ColorLayer.js +35 -9
  49. package/lib/Layer/CopcLayer.js +5 -0
  50. package/lib/Layer/ElevationLayer.js +39 -7
  51. package/lib/Layer/EntwinePointTileLayer.js +12 -5
  52. package/lib/Layer/FeatureGeometryLayer.js +20 -6
  53. package/lib/Layer/GeometryLayer.js +42 -11
  54. package/lib/Layer/LabelLayer.js +19 -9
  55. package/lib/Layer/Layer.js +83 -57
  56. package/lib/Layer/OGC3DTilesLayer.js +81 -30
  57. package/lib/Layer/OrientedImageLayer.js +11 -5
  58. package/lib/Layer/PointCloudLayer.js +74 -30
  59. package/lib/Layer/Potree2Layer.js +7 -2
  60. package/lib/Layer/PotreeLayer.js +8 -3
  61. package/lib/Layer/RasterLayer.js +12 -2
  62. package/lib/Layer/TiledGeometryLayer.js +69 -13
  63. package/lib/Main.js +2 -2
  64. package/lib/Parser/GeoJsonParser.js +1 -1
  65. package/lib/Parser/VectorTileParser.js +1 -1
  66. package/lib/Parser/XbilParser.js +14 -2
  67. package/lib/Provider/Fetcher.js +5 -1
  68. package/lib/Provider/URLBuilder.js +22 -11
  69. package/lib/Renderer/Camera.js +1 -1
  70. package/lib/Renderer/OBB.js +11 -13
  71. package/lib/Renderer/PointsMaterial.js +1 -1
  72. package/lib/Renderer/RasterTile.js +1 -2
  73. package/lib/Renderer/SphereHelper.js +0 -6
  74. package/lib/Source/CopcSource.js +13 -2
  75. package/lib/Source/EntwinePointTileSource.js +14 -4
  76. package/lib/Source/FileSource.js +1 -4
  77. package/lib/Source/Source.js +1 -4
  78. package/lib/Source/TMSSource.js +10 -9
  79. package/lib/Source/VectorTilesSource.js +3 -5
  80. package/lib/Source/WFSSource.js +15 -10
  81. package/lib/Source/WMSSource.js +56 -18
  82. package/lib/Source/WMTSSource.js +13 -7
  83. package/lib/Utils/CameraUtils.js +1 -1
  84. package/lib/Utils/gui/C3DTilesStyle.js +2 -3
  85. package/lib/Utils/placeObjectOnGround.js +0 -1
  86. package/package.json +13 -6
  87. package/examples/3dtiles_25d.html +0 -120
  88. package/examples/3dtiles_basic.html +0 -94
  89. package/examples/3dtiles_batch_table.html +0 -86
  90. package/examples/3dtiles_ion.html +0 -126
  91. package/examples/3dtiles_pointcloud.html +0 -95
  92. package/lib/Core/Prefab/Globe/BuilderEllipsoidTile.js +0 -110
@@ -1,5 +1,18 @@
1
1
  import proj4 from 'proj4';
2
2
  proj4.defs('EPSG:4978', '+proj=geocent +datum=WGS84 +units=m +no_defs');
3
+
4
+ // Redefining proj4 global projections to match epsg.org database axis order.
5
+ // See https://github.com/iTowns/itowns/pull/2465#issuecomment-2517024859
6
+ proj4.defs('EPSG:4326').axis = 'neu';
7
+ proj4.defs('EPSG:4269').axis = 'neu';
8
+ proj4.defs('WGS84').axis = 'neu';
9
+
10
+ /**
11
+ * A projection as a CRS identifier string. This identifier references a
12
+ * projection definition previously defined with
13
+ * [`proj4.defs`](https://github.com/proj4js/proj4js#named-projections).
14
+ */
15
+
3
16
  function isString(s) {
4
17
  return typeof s === 'string' || s instanceof String;
5
18
  }
@@ -8,168 +21,150 @@ function mustBeString(crs) {
8
21
  throw new Error(`Crs parameter value must be a string: '${crs}'`);
9
22
  }
10
23
  }
11
- function isTms(crs) {
12
- return isString(crs) && crs.startsWith('TMS');
13
- }
14
- function isEpsg(crs) {
15
- return isString(crs) && crs.startsWith('EPSG');
16
- }
17
- function formatToTms(crs) {
18
- mustBeString(crs);
19
- return isTms(crs) ? crs : `TMS:${crs.match(/\d+/)[0]}`;
20
- }
21
- function formatToEPSG(crs) {
22
- mustBeString(crs);
23
- return isEpsg(crs) ? crs : `EPSG:${crs.match(/\d+/)[0]}`;
24
- }
25
- const UNIT = {
24
+
25
+ /**
26
+ * System units supported for a coordinate system. See
27
+ * [proj](https://proj4.org/en/9.5/operations/conversions/unitconvert.html#angular-units).
28
+ * Note that only degree and meters units are supported for now.
29
+ */
30
+ export const UNIT = {
31
+ /**
32
+ * Angular unit in degree.
33
+ */
26
34
  DEGREE: 1,
27
- METER: 2
35
+ /**
36
+ * Distance unit in meter.
37
+ */
38
+ METER: 2,
39
+ /**
40
+ * Distance unit in foot.
41
+ */
42
+ FOOT: 3
28
43
  };
29
- function is4326(crs) {
44
+
45
+ /**
46
+ * Checks that the CRS is EPSG:4326.
47
+ * @internal
48
+ *
49
+ * @param crs - The CRS to test.
50
+ */
51
+ export function is4326(crs) {
30
52
  return crs === 'EPSG:4326';
31
53
  }
32
- function isGeocentric(crs) {
33
- mustBeString(crs);
34
- const projection = proj4.defs(crs);
35
- return !projection ? false : projection.projName == 'geocent';
36
- }
37
- function _unitFromProj4Unit(projunit) {
38
- if (projunit === 'degrees') {
54
+ function unitFromProj4Unit(proj) {
55
+ if (proj.units === 'degrees') {
39
56
  return UNIT.DEGREE;
40
- } else if (projunit === 'm') {
57
+ } else if (proj.units === 'm' || proj.units === 'meter') {
58
+ return UNIT.METER;
59
+ } else if (proj.units === 'foot') {
60
+ return UNIT.FOOT;
61
+ } else if (proj.units === undefined && proj.to_meter === undefined) {
62
+ // See https://proj.org/en/9.4/usage/projections.html [17/10/2024]
63
+ // > The default unit for projected coordinates is the meter.
41
64
  return UNIT.METER;
42
65
  } else {
43
66
  return undefined;
44
67
  }
45
68
  }
46
- function toUnit(crs) {
69
+
70
+ /**
71
+ * Returns the horizontal coordinates system units associated with this CRS.
72
+ *
73
+ * @param crs - The CRS to extract the unit from.
74
+ * @returns Either `UNIT.METER`, `UNIT.DEGREE`, `UNIT.FOOT` or `undefined`.
75
+ */
76
+ export function getUnit(crs) {
47
77
  mustBeString(crs);
48
- switch (crs) {
49
- case 'EPSG:4326':
50
- return UNIT.DEGREE;
51
- case 'EPSG:4978':
52
- return UNIT.METER;
53
- default:
54
- {
55
- const p = proj4.defs(formatToEPSG(crs));
56
- if (!p) {
57
- return undefined;
58
- }
59
- return _unitFromProj4Unit(p.units);
60
- }
78
+ const p = proj4.defs(crs);
79
+ if (!p) {
80
+ return undefined;
61
81
  }
82
+ return unitFromProj4Unit(p);
62
83
  }
63
- function toUnitWithError(crs) {
84
+
85
+ /**
86
+ * Asserts that the CRS is using metric units.
87
+ *
88
+ * @param crs - The CRS to check.
89
+ * @throws {@link Error} if the CRS is not valid.
90
+ */
91
+ export function isMetricUnit(crs) {
92
+ return getUnit(crs) === UNIT.METER;
93
+ }
94
+
95
+ /**
96
+ * Asserts that the CRS is geographic.
97
+ *
98
+ * @param crs - The CRS to check.
99
+ * @throws {@link Error} if the CRS is not valid.
100
+ */
101
+ export function isGeographic(crs) {
102
+ return getUnit(crs) === UNIT.DEGREE;
103
+ }
104
+
105
+ /**
106
+ * Asserts that the CRS is geocentric.
107
+ *
108
+ * @param crs - The CRS to test.
109
+ * @returns false if the crs isn't defined.
110
+ */
111
+ export function isGeocentric(crs) {
64
112
  mustBeString(crs);
65
- const u = toUnit(crs);
66
- if (u === undefined) {
67
- throw new Error(`No unit found for crs: '${crs}'`);
113
+ const projection = proj4.defs(crs);
114
+ return !projection ? false : projection.projName == 'geocent';
115
+ }
116
+
117
+ /**
118
+ * Asserts that the CRS is valid, meaning it has been previously defined and
119
+ * includes an unit.
120
+ *
121
+ * @param crs - The CRS to test.
122
+ * @throws {@link Error} if the crs is not valid.
123
+ */
124
+ export function isValid(crs) {
125
+ const proj = proj4.defs(crs);
126
+ if (!proj) {
127
+ throw new Error(`Undefined crs '${crs}'. Add it with proj4.defs('${crs}', string)`);
128
+ }
129
+ if (!unitFromProj4Unit(proj)) {
130
+ throw new Error(`No valid unit found for crs '${crs}', found ${proj.units}`);
68
131
  }
69
- return u;
70
132
  }
71
133
 
72
134
  /**
73
- * This module provides basic methods to manipulate a CRS (as a string).
135
+ * Gives a reasonable epsilon for this CRS.
74
136
  *
75
- * @module CRS
137
+ * @param crs - The CRS to use.
138
+ * @returns 0.01 if the CRS is EPSG:4326, 0.001 otherwise.
76
139
  */
77
- export default {
78
- /**
79
- * Units that can be used for a CRS.
80
- *
81
- * @enum {number}
82
- */
83
- UNIT,
84
- /**
85
- * Assert that the CRS is valid one.
86
- *
87
- * @param {string} crs - The CRS to validate.
88
- *
89
- * @throws {Error} if the CRS is not valid.
90
- */
91
- isValid(crs) {
92
- toUnitWithError(crs);
93
- },
94
- /**
95
- * Assert that the CRS is geographic.
96
- *
97
- * @param {string} crs - The CRS to validate.
98
- * @return {boolean}
99
- * @throws {Error} if the CRS is not valid.
100
- */
101
- isGeographic(crs) {
102
- return toUnitWithError(crs) == UNIT.DEGREE;
103
- },
104
- /**
105
- * Assert that the CRS is using metric units.
106
- *
107
- * @param {string} crs - The CRS to validate.
108
- * @return {boolean}
109
- * @throws {Error} if the CRS is not valid.
110
- */
111
- isMetricUnit(crs) {
112
- return toUnit(crs) == UNIT.METER;
113
- },
114
- /**
115
- * Get the unit to use with the CRS.
116
- *
117
- * @param {string} crs - The CRS to get the unit from.
118
- * @return {number} Either `UNIT.METER`, `UNIT.DEGREE` or `undefined`.
119
- */
120
- toUnit,
121
- /**
122
- * Is the CRS EPSG:4326 ?
123
- *
124
- * @param {string} crs - The CRS to test.
125
- * @return {boolean}
126
- */
127
- is4326,
128
- /**
129
- * Is the CRS geocentric ?
130
- * if crs isn't defined the method returns false.
131
- *
132
- * @param {string} crs - The CRS to test.
133
- * @return {boolean}
134
- */
135
- isGeocentric,
136
- /**
137
- * Give a reasonnable epsilon to use with this CRS.
138
- *
139
- * @param {string} crs - The CRS to use.
140
- * @return {number} 0.01 if the CRS is EPSG:4326, 0.001 otherwise.
141
- */
142
- reasonnableEpsilon(crs) {
143
- if (is4326(crs)) {
144
- return 0.01;
145
- } else {
146
- return 0.001;
147
- }
148
- },
149
- /**
150
- * format crs to European Petroleum Survey Group notation : EPSG:XXXX.
151
- *
152
- * @param {string} crs The crs to format
153
- * @return {string} formated crs
154
- */
155
- formatToEPSG,
156
- /**
157
- * format crs to tile matrix set notation : TMS:XXXX.
158
- *
159
- * @param {string} crs The crs to format
160
- * @return {string} formated crs
161
- */
162
- formatToTms,
163
- isTms,
164
- isEpsg,
165
- tms_3857: 'TMS:3857',
166
- tms_4326: 'TMS:4326',
167
- /**
168
- * Define a proj4 projection as a string and reference.
169
- *
170
- * @param {string} code code is the projection's SRS code (only used internally by the Proj4js library)
171
- * @param {string} proj4def is the Proj4 definition string for the projection to use
172
- * @return {undefined}
173
- */
174
- defs: (code, proj4def) => proj4.defs(code, proj4def)
175
- };
140
+ export function reasonableEpsilon(crs) {
141
+ if (is4326(crs)) {
142
+ return 0.01;
143
+ } else {
144
+ return 0.001;
145
+ }
146
+ }
147
+
148
+ /**
149
+ * Returns the axis parameter defined in proj4 for the provided crs.
150
+ * Might be undefined depending on crs definition.
151
+ *
152
+ * @param crs - The CRS to get axis from.
153
+ * @returns the matching proj4 axis string, 'enu' for instance (east, north, up)
154
+ */
155
+ export function axisOrder(crs) {
156
+ mustBeString(crs);
157
+ const projection = proj4.defs(crs);
158
+ return !projection ? undefined : projection.axis;
159
+ }
160
+
161
+ /**
162
+ * Defines a proj4 projection as a named alias.
163
+ * This function is a specialized wrapper over the
164
+ * [`proj4.defs`](https://github.com/proj4js/proj4js#named-projections)
165
+ * function.
166
+ *
167
+ * @param code - Named alias of the currently defined projection.
168
+ * @param proj4def - Proj4 or WKT string of the defined projection.
169
+ */
170
+ export const defs = (code, proj4def) => proj4.defs(code, proj4def);