@hztxi/cesium-engine 25.0.2 → 25.0.3
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/Build/ThirdParty/Workers/zip-web-worker.js +761 -520
- package/Build/Workers/chunk-2KZP32NE.js +3201 -0
- package/Build/Workers/chunk-2P5SGQUU.js +44 -0
- package/Build/Workers/chunk-2PFSIZOR.js +959 -0
- package/Build/Workers/chunk-2RC5GQMH.js +82 -0
- package/Build/Workers/chunk-2TM5FET3.js +241 -0
- package/Build/Workers/chunk-2ZYMQXBB.js +519 -0
- package/Build/Workers/chunk-37IVAHRF.js +3201 -0
- package/Build/Workers/chunk-3CSWK42O.js +3648 -0
- package/Build/Workers/chunk-3GDVUAIX.js +1287 -0
- package/Build/Workers/chunk-3L5NZHVW.js +288 -0
- package/Build/Workers/chunk-3LQDIJFX.js +2719 -0
- package/Build/Workers/chunk-3WIDW5QO.js +1800 -0
- package/Build/Workers/chunk-4L4ZXXL7.js +57 -0
- package/Build/Workers/chunk-4QK5RZ5I.js +171 -0
- package/Build/Workers/chunk-4RWSLDVO.js +198 -0
- package/Build/Workers/chunk-53HFLKT5.js +76 -0
- package/Build/Workers/chunk-5DJBLQEH.js +56 -0
- package/Build/Workers/chunk-5FNZGB4U.js +368 -0
- package/Build/Workers/chunk-5KOCUIKQ.js +476 -0
- package/Build/Workers/chunk-5PK42ITB.js +219 -0
- package/Build/Workers/chunk-5SGB3BKM.js +73 -0
- package/Build/Workers/chunk-5ZWRS2E6.js +280 -0
- package/Build/Workers/chunk-6FU5LWYG.js +352 -0
- package/Build/Workers/chunk-6IYEGXEW.js +1344 -0
- package/Build/Workers/chunk-6KWWDFT4.js +278 -0
- package/Build/Workers/chunk-73DJHI53.js +398 -0
- package/Build/Workers/chunk-73OT3YBQ.js +1054 -0
- package/Build/Workers/chunk-73T2E2OA.js +454 -0
- package/Build/Workers/chunk-752QDGCS.js +778 -0
- package/Build/Workers/chunk-76HD3HYN.js +2342 -0
- package/Build/Workers/chunk-7I4AKIEV.js +58 -0
- package/Build/Workers/chunk-7ZYD7GL6.js +414 -0
- package/Build/Workers/chunk-ALJYMECF.js +973 -0
- package/Build/Workers/chunk-ANGZAKVP.js +257 -0
- package/Build/Workers/chunk-ATT5UEK6.js +97 -0
- package/Build/Workers/chunk-AW3UT5RP.js +97 -0
- package/Build/Workers/chunk-AZGPL6BR.js +38 -0
- package/Build/Workers/chunk-B7SMDRPA.js +476 -0
- package/Build/Workers/chunk-BADQ2G5E.js +837 -0
- package/Build/Workers/chunk-BAPOWX62.js +368 -0
- package/Build/Workers/chunk-BE5ULV4I.js +1800 -0
- package/Build/Workers/chunk-BII4UB3C.js +476 -0
- package/Build/Workers/chunk-BPL3HT2R.js +837 -0
- package/Build/Workers/chunk-BVAMP4M3.js +101 -0
- package/Build/Workers/chunk-BVFS5LSK.js +1067 -0
- package/Build/Workers/chunk-CKWUU4JK.js +138 -0
- package/Build/Workers/chunk-CMMHWVUF.js +2719 -0
- package/Build/Workers/chunk-CQNFIAZU.js +56 -0
- package/Build/Workers/chunk-CSUBL77L.js +140 -0
- package/Build/Workers/chunk-DHCQSFRN.js +301 -0
- package/Build/Workers/chunk-DKFSOFKR.js +241 -0
- package/Build/Workers/chunk-DLHFYNG6.js +52 -0
- package/Build/Workers/chunk-ETABYWY4.js +973 -0
- package/Build/Workers/chunk-EYVCQUVQ.js +1067 -0
- package/Build/Workers/chunk-FE7VHPNW.js +102 -0
- package/Build/Workers/chunk-FFEVCOBU.js +387 -0
- package/Build/Workers/chunk-FWABE4BL.js +305 -0
- package/Build/Workers/chunk-GC24BPCQ.js +305 -0
- package/Build/Workers/chunk-GCTHMF35.js +387 -0
- package/Build/Workers/chunk-GDHSPLWC.js +9237 -0
- package/Build/Workers/chunk-GGK7SA4Y.js +414 -0
- package/Build/Workers/chunk-GGVG7G5Z.js +1483 -0
- package/Build/Workers/chunk-GL7W3I3A.js +959 -0
- package/Build/Workers/chunk-H52M4HMP.js +9230 -0
- package/Build/Workers/chunk-H7QGY7HB.js +1054 -0
- package/Build/Workers/chunk-H7ZXQIV2.js +398 -0
- package/Build/Workers/chunk-HBJKIDKK.js +76 -0
- package/Build/Workers/chunk-HERVRBJW.js +76 -0
- package/Build/Workers/chunk-HFMS7MXO.js +511 -0
- package/Build/Workers/chunk-HH6PJ22V.js +455 -0
- package/Build/Workers/chunk-HQ2PXPP7.js +102 -0
- package/Build/Workers/chunk-HTO45L3X.js +454 -0
- package/Build/Workers/chunk-HW5TLMPQ.js +57 -0
- package/Build/Workers/chunk-IC3HVJBG.js +301 -0
- package/Build/Workers/chunk-IEKP7CEH.js +387 -0
- package/Build/Workers/chunk-ILUFUAF3.js +1992 -0
- package/Build/Workers/chunk-ILX5N5QR.js +2342 -0
- package/Build/Workers/chunk-IRSD4EJW.js +630 -0
- package/Build/Workers/chunk-J3A3XMTG.js +672 -0
- package/Build/Workers/chunk-JK54NBBO.js +778 -0
- package/Build/Workers/chunk-JSFKPEFK.js +352 -0
- package/Build/Workers/chunk-JTSSQ3RH.js +147 -0
- package/Build/Workers/chunk-JZVZDHC2.js +288 -0
- package/Build/Workers/chunk-K724BR5O.js +455 -0
- package/Build/Workers/chunk-KJOVSN7J.js +56 -0
- package/Build/Workers/chunk-KKEMKV5G.js +44 -0
- package/Build/Workers/chunk-KXNXQXP5.js +682 -0
- package/Build/Workers/chunk-KYXZ3XTC.js +497 -0
- package/Build/Workers/chunk-L65LWRUE.js +3648 -0
- package/Build/Workers/chunk-LAN4XQR6.js +162 -0
- package/Build/Workers/chunk-LVO4J36T.js +1800 -0
- package/Build/Workers/chunk-LY5KUQ2L.js +57 -0
- package/Build/Workers/chunk-M2XWG5VC.js +124 -0
- package/Build/Workers/chunk-MUPWJMPP.js +44 -0
- package/Build/Workers/chunk-MVBEMXN4.js +163 -0
- package/Build/Workers/chunk-MVQYVX6D.js +511 -0
- package/Build/Workers/chunk-N4RF6TUL.js +301 -0
- package/Build/Workers/chunk-NCH4P66E.js +219 -0
- package/Build/Workers/chunk-NCL22ZUX.js +56 -0
- package/Build/Workers/chunk-NNJDVVEG.js +3794 -0
- package/Build/Workers/chunk-NYQSZLRF.js +78 -0
- package/Build/Workers/chunk-O2V4I3I5.js +682 -0
- package/Build/Workers/chunk-O453S45W.js +1483 -0
- package/Build/Workers/chunk-O5CYW2IR.js +1046 -0
- package/Build/Workers/chunk-OJ7O7DKV.js +973 -0
- package/Build/Workers/chunk-OJK33YVT.js +171 -0
- package/Build/Workers/chunk-OKFC4PDV.js +1344 -0
- package/Build/Workers/chunk-OKUXJIW3.js +124 -0
- package/Build/Workers/chunk-OWDZ5BX4.js +280 -0
- package/Build/Workers/chunk-PCERHV4S.js +198 -0
- package/Build/Workers/chunk-PJT22BD4.js +352 -0
- package/Build/Workers/chunk-PKV3R77E.js +672 -0
- package/Build/Workers/chunk-PQ2MGY7X.js +162 -0
- package/Build/Workers/chunk-PR62UBKE.js +693 -0
- package/Build/Workers/chunk-QJJ3GXSH.js +140 -0
- package/Build/Workers/chunk-QM4HZZYW.js +219 -0
- package/Build/Workers/chunk-QQ2BBL7Z.js +162 -0
- package/Build/Workers/chunk-QYC6Y25A.js +124 -0
- package/Build/Workers/chunk-RBAZR7R2.js +280 -0
- package/Build/Workers/chunk-REZJEC6F.js +241 -0
- package/Build/Workers/chunk-RS3LRHOK.js +73 -0
- package/Build/Workers/chunk-S2WTOFGB.js +102 -0
- package/Build/Workers/chunk-SGLJWWWY.js +352 -0
- package/Build/Workers/chunk-SJZMU3OS.js +2342 -0
- package/Build/Workers/chunk-SMZXVFCA.js +1344 -0
- package/Build/Workers/chunk-SND4KNB6.js +754 -0
- package/Build/Workers/chunk-SRH2XIWS.js +1067 -0
- package/Build/Workers/chunk-SXSP3JHS.js +38 -0
- package/Build/Workers/chunk-T6SVKD76.js +511 -0
- package/Build/Workers/chunk-TA3PH4Q7.js +519 -0
- package/Build/Workers/chunk-TDJ2NSYJ.js +171 -0
- package/Build/Workers/chunk-TJCD5NV5.js +837 -0
- package/Build/Workers/chunk-TXBADNRA.js +9237 -0
- package/Build/Workers/chunk-TYW2D7VU.js +2719 -0
- package/Build/Workers/chunk-U3KB4HMG.js +1054 -0
- package/Build/Workers/chunk-U6OMVSBY.js +368 -0
- package/Build/Workers/chunk-UAVMVBMC.js +754 -0
- package/Build/Workers/chunk-UCOZLNHF.js +1284 -0
- package/Build/Workers/chunk-UDKEO3UF.js +163 -0
- package/Build/Workers/chunk-UIQUUY4A.js +73 -0
- package/Build/Workers/chunk-ULY2FDDP.js +454 -0
- package/Build/Workers/chunk-UT7YX565.js +1992 -0
- package/Build/Workers/chunk-UTOYFI3Q.js +1992 -0
- package/Build/Workers/chunk-UUXWWJI7.js +101 -0
- package/Build/Workers/chunk-V5AWAGL2.js +97 -0
- package/Build/Workers/chunk-V5AXOGPW.js +682 -0
- package/Build/Workers/chunk-VAUX2Q2X.js +138 -0
- package/Build/Workers/chunk-VDX4SJKV.js +58 -0
- package/Build/Workers/chunk-W7WEPLZL.js +414 -0
- package/Build/Workers/chunk-WNAG4FHY.js +305 -0
- package/Build/Workers/chunk-WNQX2CP3.js +455 -0
- package/Build/Workers/chunk-XCASHPVG.js +778 -0
- package/Build/Workers/chunk-XJUIVTHG.js +1483 -0
- package/Build/Workers/chunk-XQVSSVT2.js +140 -0
- package/Build/Workers/chunk-Y5E2LVSX.js +138 -0
- package/Build/Workers/chunk-YEMKJOOG.js +352 -0
- package/Build/Workers/chunk-YGFVAGYF.js +630 -0
- package/Build/Workers/chunk-YNWTO2WN.js +147 -0
- package/Build/Workers/chunk-YZAMLSIA.js +352 -0
- package/Build/Workers/chunk-Z6LUW5FN.js +198 -0
- package/Build/Workers/chunk-ZDUCDVKX.js +288 -0
- package/Build/Workers/chunk-ZEEPTE4R.js +147 -0
- package/Build/Workers/chunk-ZIBW2BFB.js +1284 -0
- package/Build/Workers/chunk-ZOYVNCFZ.js +754 -0
- package/Build/Workers/chunk-ZSWY7UNG.js +3201 -0
- package/Build/Workers/chunk-ZXRWKKJP.js +398 -0
- package/Build/Workers/combineGeometry.js +24 -24
- package/Build/Workers/createBoxGeometry.js +18 -18
- package/Build/Workers/createBoxOutlineGeometry.js +16 -16
- package/Build/Workers/createCircleGeometry.js +26 -26
- package/Build/Workers/createCircleOutlineGeometry.js +19 -19
- package/Build/Workers/createCoplanarPolygonGeometry.js +33 -33
- package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +31 -31
- package/Build/Workers/createCorridorGeometry.js +29 -29
- package/Build/Workers/createCorridorOutlineGeometry.js +28 -28
- package/Build/Workers/createCylinderGeometry.js +20 -20
- package/Build/Workers/createCylinderOutlineGeometry.js +18 -18
- package/Build/Workers/createEllipseGeometry.js +26 -26
- package/Build/Workers/createEllipseOutlineGeometry.js +19 -19
- package/Build/Workers/createEllipsoidGeometry.js +19 -19
- package/Build/Workers/createEllipsoidOutlineGeometry.js +18 -18
- package/Build/Workers/createFrustumGeometry.js +18 -18
- package/Build/Workers/createFrustumOutlineGeometry.js +18 -18
- package/Build/Workers/createGeometry.js +24 -24
- package/Build/Workers/createGroundPolylineGeometry.js +23 -23
- package/Build/Workers/createMvtTile.js +1815 -0
- package/Build/Workers/createPlaneGeometry.js +16 -16
- package/Build/Workers/createPlaneOutlineGeometry.js +15 -15
- package/Build/Workers/createPolygonGeometry.js +32 -32
- package/Build/Workers/createPolygonOutlineGeometry.js +30 -30
- package/Build/Workers/createPolylineGeometry.js +25 -25
- package/Build/Workers/createPolylineVolumeGeometry.js +31 -31
- package/Build/Workers/createPolylineVolumeOutlineGeometry.js +27 -27
- package/Build/Workers/createRectangleGeometry.js +27 -27
- package/Build/Workers/createRectangleOutlineGeometry.js +20 -20
- package/Build/Workers/createSimplePolylineGeometry.js +23 -23
- package/Build/Workers/createSphereGeometry.js +19 -19
- package/Build/Workers/createSphereOutlineGeometry.js +18 -18
- package/Build/Workers/createTaskProcessorWorker.js +3 -3
- package/Build/Workers/createVectorTileClampedPolylines.js +14 -14
- package/Build/Workers/createVectorTileGeometries.js +24 -24
- package/Build/Workers/createVectorTilePoints.js +13 -13
- package/Build/Workers/createVectorTilePolygons.js +22 -22
- package/Build/Workers/createVectorTilePolylines.js +14 -14
- package/Build/Workers/createVerticesFromCesium3DTilesTerrain.js +26 -26
- package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +23 -23
- package/Build/Workers/createVerticesFromHeightmap.js +25 -25
- package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +21 -21
- package/Build/Workers/createWallGeometry.js +24 -24
- package/Build/Workers/createWallOutlineGeometry.js +23 -23
- package/Build/Workers/decodeDraco.js +10 -10
- package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +58 -44
- package/Build/Workers/decodeI3S.js +10 -10
- package/Build/Workers/gaussianSplatSorter.js +4 -4
- package/Build/Workers/gaussianSplatTextureGenerator.js +4 -4
- package/Build/Workers/incrementallyBuildTerrainPicker.js +10 -10
- package/Build/Workers/transcodeKTX2.js +7 -7
- package/Build/Workers/transferTypedArrayTest.js +1 -1
- package/Build/Workers/upsampleQuantizedTerrainMesh.js +23 -23
- package/Build/Workers/upsampleVerticesFromCesium3DTilesTerrain.js +26 -26
- package/Source/Core/ScreenSpaceEventHandler.js +19 -0
- package/Source/ThirdParty/Workers/zip-web-worker.js +1 -1
- package/Source/ThirdParty/zip-module.wasm +0 -0
- package/index.d.ts +48305 -0
- package/index.js +373 -373
- package/package.json +10 -10
|
@@ -0,0 +1,1815 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Cesium - https://github.com/CesiumGS/cesium
|
|
4
|
+
* Version 1.144.0
|
|
5
|
+
*
|
|
6
|
+
* Copyright 2011-2022 Cesium Contributors
|
|
7
|
+
*
|
|
8
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
* you may not use this file except in compliance with the License.
|
|
10
|
+
* You may obtain a copy of the License at
|
|
11
|
+
*
|
|
12
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
*
|
|
14
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
* See the License for the specific language governing permissions and
|
|
18
|
+
* limitations under the License.
|
|
19
|
+
*
|
|
20
|
+
* Columbus View (Pat. Pend.)
|
|
21
|
+
*
|
|
22
|
+
* Portions licensed separately.
|
|
23
|
+
* See https://github.com/CesiumGS/cesium/blob/main/LICENSE.md for full licensing details.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import {
|
|
27
|
+
createTaskProcessorWorker_default
|
|
28
|
+
} from "./chunk-UUXWWJI7.js";
|
|
29
|
+
import {
|
|
30
|
+
WebMercatorProjection_default
|
|
31
|
+
} from "./chunk-JTSSQ3RH.js";
|
|
32
|
+
import {
|
|
33
|
+
oneTimeWarning_default
|
|
34
|
+
} from "./chunk-DLHFYNG6.js";
|
|
35
|
+
import {
|
|
36
|
+
PolygonPipeline_default
|
|
37
|
+
} from "./chunk-2PFSIZOR.js";
|
|
38
|
+
import "./chunk-K724BR5O.js";
|
|
39
|
+
import {
|
|
40
|
+
PrimitiveType_default
|
|
41
|
+
} from "./chunk-DHCQSFRN.js";
|
|
42
|
+
import {
|
|
43
|
+
Matrix2_default,
|
|
44
|
+
Rectangle_default
|
|
45
|
+
} from "./chunk-GDHSPLWC.js";
|
|
46
|
+
import {
|
|
47
|
+
Cartesian4_default,
|
|
48
|
+
Matrix4_default
|
|
49
|
+
} from "./chunk-ZSWY7UNG.js";
|
|
50
|
+
import {
|
|
51
|
+
ComponentDatatype_default
|
|
52
|
+
} from "./chunk-6KWWDFT4.js";
|
|
53
|
+
import {
|
|
54
|
+
WebGLConstants_default
|
|
55
|
+
} from "./chunk-YGFVAGYF.js";
|
|
56
|
+
import {
|
|
57
|
+
RuntimeError_default
|
|
58
|
+
} from "./chunk-VDX4SJKV.js";
|
|
59
|
+
import {
|
|
60
|
+
Cartesian2_default,
|
|
61
|
+
Cartographic_default,
|
|
62
|
+
Ellipsoid_default
|
|
63
|
+
} from "./chunk-UT7YX565.js";
|
|
64
|
+
import {
|
|
65
|
+
Cartesian3_default,
|
|
66
|
+
Frozen_default,
|
|
67
|
+
Matrix3_default
|
|
68
|
+
} from "./chunk-76HD3HYN.js";
|
|
69
|
+
import "./chunk-TA3PH4Q7.js";
|
|
70
|
+
import {
|
|
71
|
+
Check_default,
|
|
72
|
+
DeveloperError_default
|
|
73
|
+
} from "./chunk-UDKEO3UF.js";
|
|
74
|
+
import {
|
|
75
|
+
__publicField,
|
|
76
|
+
defined_default
|
|
77
|
+
} from "./chunk-NYQSZLRF.js";
|
|
78
|
+
|
|
79
|
+
// packages/engine/Source/Core/WebMercatorTilingScheme.js
|
|
80
|
+
var southwestScratch = new Cartographic_default();
|
|
81
|
+
var northeastScratch = new Cartographic_default();
|
|
82
|
+
var southwestCartesianScratch = new Cartesian3_default();
|
|
83
|
+
var northeastCartesianScratch = new Cartesian3_default();
|
|
84
|
+
var WebMercatorTilingScheme = class {
|
|
85
|
+
/**
|
|
86
|
+
* @param {object} [options] Object with the following properties:
|
|
87
|
+
* @param {Ellipsoid} [options.ellipsoid=Ellipsoid.default] The ellipsoid whose surface is being tiled. Defaults to
|
|
88
|
+
* the default ellipsoid.
|
|
89
|
+
* @param {number} [options.numberOfLevelZeroTilesX=1] The number of tiles in the X direction at level zero of
|
|
90
|
+
* the tile tree.
|
|
91
|
+
* @param {number} [options.numberOfLevelZeroTilesY=1] The number of tiles in the Y direction at level zero of
|
|
92
|
+
* the tile tree.
|
|
93
|
+
* @param {Cartesian2} [options.rectangleSouthwestInMeters] The southwest corner of the rectangle covered by the
|
|
94
|
+
* tiling scheme, in meters. If this parameter or rectangleNortheastInMeters is not specified, the entire
|
|
95
|
+
* globe is covered in the longitude direction and an equal distance is covered in the latitude
|
|
96
|
+
* direction, resulting in a square projection.
|
|
97
|
+
* @param {Cartesian2} [options.rectangleNortheastInMeters] The northeast corner of the rectangle covered by the
|
|
98
|
+
* tiling scheme, in meters. If this parameter or rectangleSouthwestInMeters is not specified, the entire
|
|
99
|
+
* globe is covered in the longitude direction and an equal distance is covered in the latitude
|
|
100
|
+
* direction, resulting in a square projection.
|
|
101
|
+
*/
|
|
102
|
+
constructor(options) {
|
|
103
|
+
/**
|
|
104
|
+
* @type {Cartesian2}
|
|
105
|
+
* @private
|
|
106
|
+
*/
|
|
107
|
+
__publicField(this, "_rectangleSouthwestInMeters");
|
|
108
|
+
/**
|
|
109
|
+
* @type {Cartesian2}
|
|
110
|
+
* @private
|
|
111
|
+
*/
|
|
112
|
+
__publicField(this, "_rectangleNortheastInMeters");
|
|
113
|
+
options = options ?? Frozen_default.EMPTY_OBJECT;
|
|
114
|
+
this._ellipsoid = options.ellipsoid ?? Ellipsoid_default.default;
|
|
115
|
+
this._numberOfLevelZeroTilesX = options.numberOfLevelZeroTilesX ?? 1;
|
|
116
|
+
this._numberOfLevelZeroTilesY = options.numberOfLevelZeroTilesY ?? 1;
|
|
117
|
+
this._projection = new WebMercatorProjection_default(this._ellipsoid);
|
|
118
|
+
if (defined_default(options.rectangleSouthwestInMeters) && defined_default(options.rectangleNortheastInMeters)) {
|
|
119
|
+
this._rectangleSouthwestInMeters = options.rectangleSouthwestInMeters;
|
|
120
|
+
this._rectangleNortheastInMeters = options.rectangleNortheastInMeters;
|
|
121
|
+
} else {
|
|
122
|
+
const semimajorAxisTimesPi = this._ellipsoid.maximumRadius * Math.PI;
|
|
123
|
+
this._rectangleSouthwestInMeters = new Cartesian2_default(
|
|
124
|
+
-semimajorAxisTimesPi,
|
|
125
|
+
-semimajorAxisTimesPi
|
|
126
|
+
);
|
|
127
|
+
this._rectangleNortheastInMeters = new Cartesian2_default(
|
|
128
|
+
semimajorAxisTimesPi,
|
|
129
|
+
semimajorAxisTimesPi
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
let { x, y } = this._rectangleSouthwestInMeters;
|
|
133
|
+
Cartesian3_default.fromElements(x, y, 0, southwestCartesianScratch);
|
|
134
|
+
this._projection.unproject(southwestCartesianScratch, southwestScratch);
|
|
135
|
+
({ x, y } = this._rectangleNortheastInMeters);
|
|
136
|
+
Cartesian3_default.fromElements(x, y, 0, northeastCartesianScratch);
|
|
137
|
+
this._projection.unproject(northeastCartesianScratch, northeastScratch);
|
|
138
|
+
this._rectangle = new Rectangle_default(
|
|
139
|
+
southwestScratch.longitude,
|
|
140
|
+
southwestScratch.latitude,
|
|
141
|
+
northeastScratch.longitude,
|
|
142
|
+
northeastScratch.latitude
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Gets the ellipsoid that is tiled by this tiling scheme.
|
|
147
|
+
* @type {Ellipsoid}
|
|
148
|
+
*/
|
|
149
|
+
get ellipsoid() {
|
|
150
|
+
return this._ellipsoid;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Gets the rectangle, in radians, covered by this tiling scheme.
|
|
154
|
+
* @type {Rectangle}
|
|
155
|
+
*/
|
|
156
|
+
get rectangle() {
|
|
157
|
+
return this._rectangle;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Gets the map projection used by this tiling scheme.
|
|
161
|
+
* @type {MapProjection}
|
|
162
|
+
*/
|
|
163
|
+
get projection() {
|
|
164
|
+
return this._projection;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Gets the total number of tiles in the X direction at a specified level-of-detail.
|
|
168
|
+
*
|
|
169
|
+
* @param {number} level The level-of-detail.
|
|
170
|
+
* @returns {number} The number of tiles in the X direction at the given level.
|
|
171
|
+
*/
|
|
172
|
+
getNumberOfXTilesAtLevel(level) {
|
|
173
|
+
return this._numberOfLevelZeroTilesX << level;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Gets the total number of tiles in the Y direction at a specified level-of-detail.
|
|
177
|
+
*
|
|
178
|
+
* @param {number} level The level-of-detail.
|
|
179
|
+
* @returns {number} The number of tiles in the Y direction at the given level.
|
|
180
|
+
*/
|
|
181
|
+
getNumberOfYTilesAtLevel(level) {
|
|
182
|
+
return this._numberOfLevelZeroTilesY << level;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Transforms a rectangle specified in geodetic radians to the native coordinate system
|
|
186
|
+
* of this tiling scheme.
|
|
187
|
+
*
|
|
188
|
+
* @param {Rectangle} rectangle The rectangle to transform.
|
|
189
|
+
* @param {Rectangle} [result] The instance to which to copy the result, or undefined if a new instance
|
|
190
|
+
* should be created.
|
|
191
|
+
* @returns {Rectangle} The specified 'result', or a new object containing the native rectangle if 'result'
|
|
192
|
+
* is undefined.
|
|
193
|
+
*/
|
|
194
|
+
rectangleToNativeRectangle(rectangle, result) {
|
|
195
|
+
const projection = this._projection;
|
|
196
|
+
const southwest = projection.project(Rectangle_default.southwest(rectangle));
|
|
197
|
+
const northeast = projection.project(Rectangle_default.northeast(rectangle));
|
|
198
|
+
if (!defined_default(result)) {
|
|
199
|
+
return new Rectangle_default(southwest.x, southwest.y, northeast.x, northeast.y);
|
|
200
|
+
}
|
|
201
|
+
result.west = southwest.x;
|
|
202
|
+
result.south = southwest.y;
|
|
203
|
+
result.east = northeast.x;
|
|
204
|
+
result.north = northeast.y;
|
|
205
|
+
return result;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Converts tile x, y coordinates and level to a rectangle expressed in the native coordinates
|
|
209
|
+
* of the tiling scheme.
|
|
210
|
+
*
|
|
211
|
+
* @param {number} x The integer x coordinate of the tile.
|
|
212
|
+
* @param {number} y The integer y coordinate of the tile.
|
|
213
|
+
* @param {number} level The tile level-of-detail. Zero is the least detailed.
|
|
214
|
+
* @param {Rectangle} [result] The instance to which to copy the result, or undefined if a new instance
|
|
215
|
+
* should be created.
|
|
216
|
+
* @returns {Rectangle} The specified 'result', or a new object containing the rectangle
|
|
217
|
+
* if 'result' is undefined.
|
|
218
|
+
*/
|
|
219
|
+
tileXYToNativeRectangle(x, y, level, result) {
|
|
220
|
+
const xTiles = this.getNumberOfXTilesAtLevel(level);
|
|
221
|
+
const yTiles = this.getNumberOfYTilesAtLevel(level);
|
|
222
|
+
const xTileWidth = (this._rectangleNortheastInMeters.x - this._rectangleSouthwestInMeters.x) / xTiles;
|
|
223
|
+
const west = this._rectangleSouthwestInMeters.x + x * xTileWidth;
|
|
224
|
+
const east = this._rectangleSouthwestInMeters.x + (x + 1) * xTileWidth;
|
|
225
|
+
const yTileHeight = (this._rectangleNortheastInMeters.y - this._rectangleSouthwestInMeters.y) / yTiles;
|
|
226
|
+
const north = this._rectangleNortheastInMeters.y - y * yTileHeight;
|
|
227
|
+
const south = this._rectangleNortheastInMeters.y - (y + 1) * yTileHeight;
|
|
228
|
+
if (!defined_default(result)) {
|
|
229
|
+
return new Rectangle_default(west, south, east, north);
|
|
230
|
+
}
|
|
231
|
+
result.west = west;
|
|
232
|
+
result.south = south;
|
|
233
|
+
result.east = east;
|
|
234
|
+
result.north = north;
|
|
235
|
+
return result;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Converts tile x, y coordinates and level to a cartographic rectangle in radians.
|
|
239
|
+
*
|
|
240
|
+
* @param {number} x The integer x coordinate of the tile.
|
|
241
|
+
* @param {number} y The integer y coordinate of the tile.
|
|
242
|
+
* @param {number} level The tile level-of-detail. Zero is the least detailed.
|
|
243
|
+
* @param {Rectangle} [result] The instance to which to copy the result, or undefined if a new instance
|
|
244
|
+
* should be created.
|
|
245
|
+
* @returns {Rectangle} The specified 'result', or a new object containing the rectangle
|
|
246
|
+
* if 'result' is undefined.
|
|
247
|
+
*/
|
|
248
|
+
tileXYToRectangle(x, y, level, result) {
|
|
249
|
+
const nativeRectangle = this.tileXYToNativeRectangle(x, y, level, result);
|
|
250
|
+
const projection = this._projection;
|
|
251
|
+
const southwest = projection.unproject(
|
|
252
|
+
new Cartesian3_default(nativeRectangle.west, nativeRectangle.south)
|
|
253
|
+
);
|
|
254
|
+
const northeast = projection.unproject(
|
|
255
|
+
new Cartesian3_default(nativeRectangle.east, nativeRectangle.north)
|
|
256
|
+
);
|
|
257
|
+
nativeRectangle.west = southwest.longitude;
|
|
258
|
+
nativeRectangle.south = southwest.latitude;
|
|
259
|
+
nativeRectangle.east = northeast.longitude;
|
|
260
|
+
nativeRectangle.north = northeast.latitude;
|
|
261
|
+
return nativeRectangle;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Calculates the tile x, y coordinates of the tile containing
|
|
265
|
+
* a given cartographic position.
|
|
266
|
+
*
|
|
267
|
+
* @param {Cartographic} position The position.
|
|
268
|
+
* @param {number} level The tile level-of-detail. Zero is the least detailed.
|
|
269
|
+
* @param {Cartesian2} [result] The instance to which to copy the result, or undefined if a new instance
|
|
270
|
+
* should be created.
|
|
271
|
+
* @returns {Cartesian2} The specified 'result', or a new object containing the tile x, y coordinates
|
|
272
|
+
* if 'result' is undefined.
|
|
273
|
+
*/
|
|
274
|
+
positionToTileXY(position, level, result) {
|
|
275
|
+
const rectangle = this._rectangle;
|
|
276
|
+
if (!Rectangle_default.contains(rectangle, position)) {
|
|
277
|
+
return void 0;
|
|
278
|
+
}
|
|
279
|
+
const xTiles = this.getNumberOfXTilesAtLevel(level);
|
|
280
|
+
const yTiles = this.getNumberOfYTilesAtLevel(level);
|
|
281
|
+
const overallWidth = this._rectangleNortheastInMeters.x - this._rectangleSouthwestInMeters.x;
|
|
282
|
+
const xTileWidth = overallWidth / xTiles;
|
|
283
|
+
const overallHeight = this._rectangleNortheastInMeters.y - this._rectangleSouthwestInMeters.y;
|
|
284
|
+
const yTileHeight = overallHeight / yTiles;
|
|
285
|
+
const projection = this._projection;
|
|
286
|
+
const webMercatorPosition = projection.project(position);
|
|
287
|
+
const distanceFromWest = webMercatorPosition.x - this._rectangleSouthwestInMeters.x;
|
|
288
|
+
const distanceFromNorth = this._rectangleNortheastInMeters.y - webMercatorPosition.y;
|
|
289
|
+
let xTileCoordinate = distanceFromWest / xTileWidth | 0;
|
|
290
|
+
if (xTileCoordinate >= xTiles) {
|
|
291
|
+
xTileCoordinate = xTiles - 1;
|
|
292
|
+
}
|
|
293
|
+
let yTileCoordinate = distanceFromNorth / yTileHeight | 0;
|
|
294
|
+
if (yTileCoordinate >= yTiles) {
|
|
295
|
+
yTileCoordinate = yTiles - 1;
|
|
296
|
+
}
|
|
297
|
+
if (!defined_default(result)) {
|
|
298
|
+
return new Cartesian2_default(xTileCoordinate, yTileCoordinate);
|
|
299
|
+
}
|
|
300
|
+
result.x = xTileCoordinate;
|
|
301
|
+
result.y = yTileCoordinate;
|
|
302
|
+
return result;
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
var WebMercatorTilingScheme_default = WebMercatorTilingScheme;
|
|
306
|
+
|
|
307
|
+
// packages/engine/Source/Scene/MetadataType.js
|
|
308
|
+
var MetadataType = {
|
|
309
|
+
/**
|
|
310
|
+
* A single component
|
|
311
|
+
*
|
|
312
|
+
* @type {string}
|
|
313
|
+
* @constant
|
|
314
|
+
*/
|
|
315
|
+
SCALAR: "SCALAR",
|
|
316
|
+
/**
|
|
317
|
+
* A vector with two components
|
|
318
|
+
*
|
|
319
|
+
* @type {string}
|
|
320
|
+
* @constant
|
|
321
|
+
*/
|
|
322
|
+
VEC2: "VEC2",
|
|
323
|
+
/**
|
|
324
|
+
* A vector with three components
|
|
325
|
+
*
|
|
326
|
+
* @type {string}
|
|
327
|
+
* @constant
|
|
328
|
+
*/
|
|
329
|
+
VEC3: "VEC3",
|
|
330
|
+
/**
|
|
331
|
+
* A vector with four components
|
|
332
|
+
*
|
|
333
|
+
* @type {string}
|
|
334
|
+
* @constant
|
|
335
|
+
*/
|
|
336
|
+
VEC4: "VEC4",
|
|
337
|
+
/**
|
|
338
|
+
* A 2x2 matrix, stored in column-major format.
|
|
339
|
+
*
|
|
340
|
+
* @type {string}
|
|
341
|
+
* @constant
|
|
342
|
+
*/
|
|
343
|
+
MAT2: "MAT2",
|
|
344
|
+
/**
|
|
345
|
+
* A 3x3 matrix, stored in column-major format.
|
|
346
|
+
*
|
|
347
|
+
* @type {string}
|
|
348
|
+
* @constant
|
|
349
|
+
*/
|
|
350
|
+
MAT3: "MAT3",
|
|
351
|
+
/**
|
|
352
|
+
* A 4x4 matrix, stored in column-major format.
|
|
353
|
+
*
|
|
354
|
+
* @type {string}
|
|
355
|
+
* @constant
|
|
356
|
+
*/
|
|
357
|
+
MAT4: "MAT4",
|
|
358
|
+
/**
|
|
359
|
+
* A boolean (true/false) value
|
|
360
|
+
*
|
|
361
|
+
* @type {string}
|
|
362
|
+
* @constant
|
|
363
|
+
*/
|
|
364
|
+
BOOLEAN: "BOOLEAN",
|
|
365
|
+
/**
|
|
366
|
+
* A UTF-8 encoded string value
|
|
367
|
+
*
|
|
368
|
+
* @type {string}
|
|
369
|
+
* @constant
|
|
370
|
+
*/
|
|
371
|
+
STRING: "STRING",
|
|
372
|
+
/**
|
|
373
|
+
* An enumerated value. This type is used in conjunction with a {@link MetadataEnum} to describe the valid values.
|
|
374
|
+
*
|
|
375
|
+
* @see MetadataEnum
|
|
376
|
+
*
|
|
377
|
+
* @type {string}
|
|
378
|
+
* @constant
|
|
379
|
+
*/
|
|
380
|
+
ENUM: "ENUM"
|
|
381
|
+
};
|
|
382
|
+
MetadataType.isVectorType = function(type) {
|
|
383
|
+
Check_default.typeOf.string("type", type);
|
|
384
|
+
switch (type) {
|
|
385
|
+
case MetadataType.VEC2:
|
|
386
|
+
case MetadataType.VEC3:
|
|
387
|
+
case MetadataType.VEC4:
|
|
388
|
+
return true;
|
|
389
|
+
default:
|
|
390
|
+
return false;
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
MetadataType.isMatrixType = function(type) {
|
|
394
|
+
Check_default.typeOf.string("type", type);
|
|
395
|
+
switch (type) {
|
|
396
|
+
case MetadataType.MAT2:
|
|
397
|
+
case MetadataType.MAT3:
|
|
398
|
+
case MetadataType.MAT4:
|
|
399
|
+
return true;
|
|
400
|
+
default:
|
|
401
|
+
return false;
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
MetadataType.getComponentCount = function(type) {
|
|
405
|
+
Check_default.typeOf.string("type", type);
|
|
406
|
+
switch (type) {
|
|
407
|
+
case MetadataType.SCALAR:
|
|
408
|
+
case MetadataType.STRING:
|
|
409
|
+
case MetadataType.ENUM:
|
|
410
|
+
case MetadataType.BOOLEAN:
|
|
411
|
+
return 1;
|
|
412
|
+
case MetadataType.VEC2:
|
|
413
|
+
return 2;
|
|
414
|
+
case MetadataType.VEC3:
|
|
415
|
+
return 3;
|
|
416
|
+
case MetadataType.VEC4:
|
|
417
|
+
return 4;
|
|
418
|
+
case MetadataType.MAT2:
|
|
419
|
+
return 4;
|
|
420
|
+
case MetadataType.MAT3:
|
|
421
|
+
return 9;
|
|
422
|
+
case MetadataType.MAT4:
|
|
423
|
+
return 16;
|
|
424
|
+
//>>includeStart('debug', pragmas.debug);
|
|
425
|
+
default:
|
|
426
|
+
throw new DeveloperError_default(`Invalid metadata type ${type}`);
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
MetadataType.getMathType = function(type) {
|
|
430
|
+
switch (type) {
|
|
431
|
+
case MetadataType.VEC2:
|
|
432
|
+
return Cartesian2_default;
|
|
433
|
+
case MetadataType.VEC3:
|
|
434
|
+
return Cartesian3_default;
|
|
435
|
+
case MetadataType.VEC4:
|
|
436
|
+
return Cartesian4_default;
|
|
437
|
+
case MetadataType.MAT2:
|
|
438
|
+
return Matrix2_default;
|
|
439
|
+
case MetadataType.MAT3:
|
|
440
|
+
return Matrix3_default;
|
|
441
|
+
case MetadataType.MAT4:
|
|
442
|
+
return Matrix4_default;
|
|
443
|
+
default:
|
|
444
|
+
return void 0;
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
Object.freeze(MetadataType);
|
|
448
|
+
var MetadataType_default = MetadataType;
|
|
449
|
+
|
|
450
|
+
// packages/engine/Source/Scene/buildVectorGltfFromMVT.js
|
|
451
|
+
var DEFAULT_HEIGHT = 0;
|
|
452
|
+
var scratchWorld = new Cartesian3_default();
|
|
453
|
+
var scratchLocal = new Cartesian3_default();
|
|
454
|
+
var tilingScheme = new WebMercatorTilingScheme_default();
|
|
455
|
+
function buildVectorGltfFromMVT(decoded, tileCoordinates, options) {
|
|
456
|
+
const tileX = tileCoordinates.tileX;
|
|
457
|
+
const tileY = tileCoordinates.tileY;
|
|
458
|
+
const tileZ = tileCoordinates.tileZ;
|
|
459
|
+
const featureIdProperty = options?.featureIdProperty;
|
|
460
|
+
const tileRect = tilingScheme.tileXYToRectangle(tileX, tileY, tileZ);
|
|
461
|
+
const tileCenter = Rectangle_default.center(tileRect);
|
|
462
|
+
const origin = Cartesian3_default.fromRadians(
|
|
463
|
+
tileCenter.longitude,
|
|
464
|
+
tileCenter.latitude,
|
|
465
|
+
0
|
|
466
|
+
);
|
|
467
|
+
const MAX_INT_U32 = 4294967295;
|
|
468
|
+
const nullFeatureId = MAX_INT_U32;
|
|
469
|
+
const primitiveRestartIndex = MAX_INT_U32;
|
|
470
|
+
const featureIdLookup = /* @__PURE__ */ new Map();
|
|
471
|
+
const featureProperties = /* @__PURE__ */ new Map();
|
|
472
|
+
const bufferViews = [];
|
|
473
|
+
const accessors = [];
|
|
474
|
+
const chunks = [];
|
|
475
|
+
let byteLength = 0;
|
|
476
|
+
function addPadding() {
|
|
477
|
+
const padding = (4 - byteLength % 4) % 4;
|
|
478
|
+
if (padding > 0) {
|
|
479
|
+
chunks.push(new Uint8Array(padding));
|
|
480
|
+
byteLength += padding;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
function addBufferView(typedArray, target) {
|
|
484
|
+
addPadding();
|
|
485
|
+
const byteOffset = byteLength;
|
|
486
|
+
chunks.push(
|
|
487
|
+
new Uint8Array(
|
|
488
|
+
typedArray.buffer,
|
|
489
|
+
typedArray.byteOffset,
|
|
490
|
+
typedArray.byteLength
|
|
491
|
+
)
|
|
492
|
+
);
|
|
493
|
+
byteLength += typedArray.byteLength;
|
|
494
|
+
const bufferViewIndex = bufferViews.length;
|
|
495
|
+
bufferViews.push({
|
|
496
|
+
buffer: 0,
|
|
497
|
+
byteOffset,
|
|
498
|
+
byteLength: typedArray.byteLength,
|
|
499
|
+
target
|
|
500
|
+
});
|
|
501
|
+
return bufferViewIndex;
|
|
502
|
+
}
|
|
503
|
+
function addAccessor(typedArray, options2) {
|
|
504
|
+
const bufferView = addBufferView(typedArray, options2.target);
|
|
505
|
+
const componentCount = (
|
|
506
|
+
/** @type {*} */
|
|
507
|
+
MetadataType_default.getComponentCount(
|
|
508
|
+
options2.type
|
|
509
|
+
)
|
|
510
|
+
);
|
|
511
|
+
const accessor = (
|
|
512
|
+
/** @type {*} */
|
|
513
|
+
{
|
|
514
|
+
bufferView,
|
|
515
|
+
byteOffset: 0,
|
|
516
|
+
componentType: options2.componentType,
|
|
517
|
+
count: typedArray.length / componentCount,
|
|
518
|
+
type: options2.type
|
|
519
|
+
}
|
|
520
|
+
);
|
|
521
|
+
if (defined_default(options2.min)) {
|
|
522
|
+
accessor.min = options2.min;
|
|
523
|
+
}
|
|
524
|
+
if (defined_default(options2.max)) {
|
|
525
|
+
accessor.max = options2.max;
|
|
526
|
+
}
|
|
527
|
+
const accessorIndex = accessors.length;
|
|
528
|
+
accessors.push(accessor);
|
|
529
|
+
return accessorIndex;
|
|
530
|
+
}
|
|
531
|
+
function computeMinMax(positions) {
|
|
532
|
+
let minX = Number.POSITIVE_INFINITY;
|
|
533
|
+
let minY = Number.POSITIVE_INFINITY;
|
|
534
|
+
let minZ = Number.POSITIVE_INFINITY;
|
|
535
|
+
let maxX = Number.NEGATIVE_INFINITY;
|
|
536
|
+
let maxY = Number.NEGATIVE_INFINITY;
|
|
537
|
+
let maxZ = Number.NEGATIVE_INFINITY;
|
|
538
|
+
for (let i = 0; i < positions.length; i += 3) {
|
|
539
|
+
const x = positions[i];
|
|
540
|
+
const y = positions[i + 1];
|
|
541
|
+
const z = positions[i + 2];
|
|
542
|
+
if (x < minX) {
|
|
543
|
+
minX = x;
|
|
544
|
+
}
|
|
545
|
+
if (y < minY) {
|
|
546
|
+
minY = y;
|
|
547
|
+
}
|
|
548
|
+
if (z < minZ) {
|
|
549
|
+
minZ = z;
|
|
550
|
+
}
|
|
551
|
+
if (x > maxX) {
|
|
552
|
+
maxX = x;
|
|
553
|
+
}
|
|
554
|
+
if (y > maxY) {
|
|
555
|
+
maxY = y;
|
|
556
|
+
}
|
|
557
|
+
if (z > maxZ) {
|
|
558
|
+
maxZ = z;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
return {
|
|
562
|
+
min: [minX, minY, minZ],
|
|
563
|
+
max: [maxX, maxY, maxZ]
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
function addFeatureIdsToPrimitive(attributes, extensions, featureIdValues) {
|
|
567
|
+
if (featureIdValues.length === 0) {
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
const featureIds = new Uint32Array(featureIdValues);
|
|
571
|
+
const featureAccessor = addAccessor(featureIds, {
|
|
572
|
+
type: "SCALAR",
|
|
573
|
+
componentType: ComponentDatatype_default.UNSIGNED_INT,
|
|
574
|
+
target: WebGLConstants_default.ARRAY_BUFFER
|
|
575
|
+
});
|
|
576
|
+
attributes._FEATURE_ID_0 = featureAccessor;
|
|
577
|
+
const featureIdDef = {
|
|
578
|
+
featureCount: featureIdLookup.size,
|
|
579
|
+
nullFeatureId,
|
|
580
|
+
attribute: 0
|
|
581
|
+
};
|
|
582
|
+
if (featureProperties.size > 0) {
|
|
583
|
+
featureIdDef.propertyTable = 0;
|
|
584
|
+
}
|
|
585
|
+
extensions.EXT_mesh_features = {
|
|
586
|
+
featureIds: [featureIdDef]
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
function addMetadataBufferView(bytes, alignment) {
|
|
590
|
+
alignment = alignment ?? 4;
|
|
591
|
+
const pad = (alignment - byteLength % alignment) % alignment;
|
|
592
|
+
if (pad > 0) {
|
|
593
|
+
chunks.push(new Uint8Array(pad));
|
|
594
|
+
byteLength += pad;
|
|
595
|
+
}
|
|
596
|
+
const byteOffset = byteLength;
|
|
597
|
+
chunks.push(bytes);
|
|
598
|
+
byteLength += bytes.byteLength;
|
|
599
|
+
const bufferViewIndex = bufferViews.length;
|
|
600
|
+
bufferViews.push({
|
|
601
|
+
buffer: 0,
|
|
602
|
+
byteOffset,
|
|
603
|
+
byteLength: bytes.byteLength
|
|
604
|
+
});
|
|
605
|
+
return bufferViewIndex;
|
|
606
|
+
}
|
|
607
|
+
function buildStructuralMetadata() {
|
|
608
|
+
if (featureProperties.size === 0) {
|
|
609
|
+
return void 0;
|
|
610
|
+
}
|
|
611
|
+
const propertyTypes = /* @__PURE__ */ new Map();
|
|
612
|
+
for (const props of featureProperties.values()) {
|
|
613
|
+
for (const [key, value] of Object.entries(props)) {
|
|
614
|
+
if (!defined_default(value)) {
|
|
615
|
+
continue;
|
|
616
|
+
}
|
|
617
|
+
const jsType = typeof value;
|
|
618
|
+
let metaType;
|
|
619
|
+
if (jsType === "string") {
|
|
620
|
+
metaType = "STRING";
|
|
621
|
+
} else if (jsType === "number") {
|
|
622
|
+
metaType = "SCALAR";
|
|
623
|
+
} else if (jsType === "boolean") {
|
|
624
|
+
metaType = "BOOLEAN";
|
|
625
|
+
} else {
|
|
626
|
+
metaType = "STRING";
|
|
627
|
+
}
|
|
628
|
+
const existing = propertyTypes.get(key);
|
|
629
|
+
if (!defined_default(existing)) {
|
|
630
|
+
propertyTypes.set(key, metaType);
|
|
631
|
+
} else if (existing !== metaType) {
|
|
632
|
+
propertyTypes.set(key, "STRING");
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
if (propertyTypes.size === 0) {
|
|
637
|
+
return void 0;
|
|
638
|
+
}
|
|
639
|
+
const classProperties = {};
|
|
640
|
+
for (const [name, type] of propertyTypes) {
|
|
641
|
+
if (type === "SCALAR") {
|
|
642
|
+
classProperties[name] = {
|
|
643
|
+
type: "SCALAR",
|
|
644
|
+
componentType: "FLOAT64"
|
|
645
|
+
};
|
|
646
|
+
} else if (type === "BOOLEAN") {
|
|
647
|
+
classProperties[name] = {
|
|
648
|
+
type: "BOOLEAN"
|
|
649
|
+
};
|
|
650
|
+
} else {
|
|
651
|
+
classProperties[name] = {
|
|
652
|
+
type: "STRING"
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
const tableProperties = {};
|
|
657
|
+
const count = featureIdLookup.size;
|
|
658
|
+
for (const [name, type] of propertyTypes) {
|
|
659
|
+
if (type === "SCALAR") {
|
|
660
|
+
const values = new Float64Array(count);
|
|
661
|
+
for (let i = 0; i < count; i++) {
|
|
662
|
+
const props = featureProperties.get(i);
|
|
663
|
+
const raw = props?.[name];
|
|
664
|
+
values[i] = typeof raw === "number" && Number.isFinite(raw) ? raw : NaN;
|
|
665
|
+
}
|
|
666
|
+
const bvIndex = addMetadataBufferView(
|
|
667
|
+
new Uint8Array(values.buffer, values.byteOffset, values.byteLength),
|
|
668
|
+
8
|
|
669
|
+
);
|
|
670
|
+
tableProperties[name] = { values: bvIndex };
|
|
671
|
+
} else if (type === "BOOLEAN") {
|
|
672
|
+
const byteCount = Math.ceil(count / 8);
|
|
673
|
+
const values = new Uint8Array(byteCount);
|
|
674
|
+
for (let i = 0; i < count; i++) {
|
|
675
|
+
const props = featureProperties.get(i);
|
|
676
|
+
const raw = props?.[name];
|
|
677
|
+
if (raw) {
|
|
678
|
+
values[i >> 3] |= 1 << (i & 7);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
const bvIndex = addMetadataBufferView(values);
|
|
682
|
+
tableProperties[name] = { values: bvIndex };
|
|
683
|
+
} else {
|
|
684
|
+
const encoder = new TextEncoder();
|
|
685
|
+
const stringParts = [];
|
|
686
|
+
const offsets = new Uint32Array(count + 1);
|
|
687
|
+
let totalBytes = 0;
|
|
688
|
+
for (let i = 0; i < count; i++) {
|
|
689
|
+
offsets[i] = totalBytes;
|
|
690
|
+
const props = featureProperties.get(i);
|
|
691
|
+
const raw = props?.[name];
|
|
692
|
+
let str;
|
|
693
|
+
if (raw === null || raw === void 0) {
|
|
694
|
+
str = "";
|
|
695
|
+
} else if (typeof raw === "string") {
|
|
696
|
+
str = raw;
|
|
697
|
+
} else {
|
|
698
|
+
str = String(raw);
|
|
699
|
+
}
|
|
700
|
+
const encoded = encoder.encode(str);
|
|
701
|
+
stringParts.push(encoded);
|
|
702
|
+
totalBytes += encoded.byteLength;
|
|
703
|
+
}
|
|
704
|
+
offsets[count] = totalBytes;
|
|
705
|
+
const valuesBuffer = new Uint8Array(totalBytes);
|
|
706
|
+
let writeOffset = 0;
|
|
707
|
+
for (const part of stringParts) {
|
|
708
|
+
valuesBuffer.set(part, writeOffset);
|
|
709
|
+
writeOffset += part.byteLength;
|
|
710
|
+
}
|
|
711
|
+
const valuesBv = addMetadataBufferView(valuesBuffer);
|
|
712
|
+
const offsetsBv = addMetadataBufferView(
|
|
713
|
+
new Uint8Array(
|
|
714
|
+
offsets.buffer,
|
|
715
|
+
offsets.byteOffset,
|
|
716
|
+
offsets.byteLength
|
|
717
|
+
)
|
|
718
|
+
);
|
|
719
|
+
tableProperties[name] = {
|
|
720
|
+
values: valuesBv,
|
|
721
|
+
stringOffsets: offsetsBv,
|
|
722
|
+
stringOffsetType: "UINT32"
|
|
723
|
+
};
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
return {
|
|
727
|
+
schema: {
|
|
728
|
+
classes: {
|
|
729
|
+
mvt_feature: {
|
|
730
|
+
properties: classProperties
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
},
|
|
734
|
+
propertyTables: [
|
|
735
|
+
{
|
|
736
|
+
class: "mvt_feature",
|
|
737
|
+
count,
|
|
738
|
+
properties: tableProperties
|
|
739
|
+
}
|
|
740
|
+
]
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
const meshes = [];
|
|
744
|
+
const nodes = [];
|
|
745
|
+
const translation = [origin.x, origin.y, origin.z];
|
|
746
|
+
for (const layer of decoded.layers) {
|
|
747
|
+
const extent = layer.extent;
|
|
748
|
+
const pointPositions = [];
|
|
749
|
+
const pointFeatureIds = [];
|
|
750
|
+
const linePositions = [];
|
|
751
|
+
const lineFeatureIds = [];
|
|
752
|
+
const lineIndices = [];
|
|
753
|
+
let lineCount = 0;
|
|
754
|
+
const polygonPositions = [];
|
|
755
|
+
const polygonFeatureIds = [];
|
|
756
|
+
const polygonIndices = [];
|
|
757
|
+
const polygonAttributeOffsets = [];
|
|
758
|
+
const polygonIndicesOffsets = [];
|
|
759
|
+
const polygonHoleCounts = [];
|
|
760
|
+
const polygonHoleOffsets = [];
|
|
761
|
+
let polygonCount = 0;
|
|
762
|
+
for (const feature of layer.features) {
|
|
763
|
+
const currentFeatureId = defined_default(featureIdProperty) ? mapFeatureIdFromProperty(
|
|
764
|
+
feature,
|
|
765
|
+
featureIdProperty,
|
|
766
|
+
featureIdLookup
|
|
767
|
+
) ?? nullFeatureId : getOrAssignAutoFeatureId(feature, featureIdLookup);
|
|
768
|
+
if (currentFeatureId !== nullFeatureId && !featureProperties.has(currentFeatureId)) {
|
|
769
|
+
const props = Object.assign({}, feature.properties);
|
|
770
|
+
props["_layer"] = layer.name ?? "";
|
|
771
|
+
featureProperties.set(currentFeatureId, props);
|
|
772
|
+
}
|
|
773
|
+
if (feature.type === "Point") {
|
|
774
|
+
const points = (
|
|
775
|
+
/** @type {VectorTilePoint[]} */
|
|
776
|
+
feature.geometry
|
|
777
|
+
);
|
|
778
|
+
for (const point of points) {
|
|
779
|
+
appendTilePointAsLocalPosition(
|
|
780
|
+
point,
|
|
781
|
+
tileX,
|
|
782
|
+
tileY,
|
|
783
|
+
tileZ,
|
|
784
|
+
extent,
|
|
785
|
+
DEFAULT_HEIGHT,
|
|
786
|
+
origin,
|
|
787
|
+
pointPositions
|
|
788
|
+
);
|
|
789
|
+
pointFeatureIds.push(currentFeatureId);
|
|
790
|
+
}
|
|
791
|
+
continue;
|
|
792
|
+
}
|
|
793
|
+
if (feature.type === "LineString") {
|
|
794
|
+
const lines = (
|
|
795
|
+
/** @type {VectorTilePoint[][]} */
|
|
796
|
+
feature.geometry
|
|
797
|
+
);
|
|
798
|
+
for (const line of lines) {
|
|
799
|
+
const lineStart = linePositions.length / 3;
|
|
800
|
+
for (const point of line) {
|
|
801
|
+
appendTilePointAsLocalPosition(
|
|
802
|
+
point,
|
|
803
|
+
tileX,
|
|
804
|
+
tileY,
|
|
805
|
+
tileZ,
|
|
806
|
+
extent,
|
|
807
|
+
DEFAULT_HEIGHT,
|
|
808
|
+
origin,
|
|
809
|
+
linePositions
|
|
810
|
+
);
|
|
811
|
+
lineFeatureIds.push(currentFeatureId);
|
|
812
|
+
}
|
|
813
|
+
for (let i = 0; i < line.length; i++) {
|
|
814
|
+
lineIndices.push(lineStart + i);
|
|
815
|
+
}
|
|
816
|
+
lineIndices.push(primitiveRestartIndex);
|
|
817
|
+
lineCount++;
|
|
818
|
+
}
|
|
819
|
+
continue;
|
|
820
|
+
}
|
|
821
|
+
if (feature.type === "Polygon") {
|
|
822
|
+
const rawRings = (
|
|
823
|
+
/** @type {VectorTilePoint[][]} */
|
|
824
|
+
feature.geometry
|
|
825
|
+
);
|
|
826
|
+
const groups = groupPolygonRings(rawRings);
|
|
827
|
+
for (const group of groups) {
|
|
828
|
+
const rings = [group.outerRing, ...group.holes];
|
|
829
|
+
const positions2D = [];
|
|
830
|
+
const polygonPositionComponents = [];
|
|
831
|
+
const holeOffsets = [];
|
|
832
|
+
let vertexOffset = 0;
|
|
833
|
+
for (let ringIndex = 0; ringIndex < rings.length; ringIndex++) {
|
|
834
|
+
const ring = rings[ringIndex];
|
|
835
|
+
if (ringIndex > 0) {
|
|
836
|
+
holeOffsets.push(vertexOffset);
|
|
837
|
+
}
|
|
838
|
+
for (const point of ring) {
|
|
839
|
+
positions2D.push(new Cartesian2_default(point.x, point.y));
|
|
840
|
+
appendTilePointAsLocalPosition(
|
|
841
|
+
point,
|
|
842
|
+
tileX,
|
|
843
|
+
tileY,
|
|
844
|
+
tileZ,
|
|
845
|
+
extent,
|
|
846
|
+
DEFAULT_HEIGHT,
|
|
847
|
+
origin,
|
|
848
|
+
polygonPositionComponents
|
|
849
|
+
);
|
|
850
|
+
vertexOffset++;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
if (positions2D.length < 3) {
|
|
854
|
+
continue;
|
|
855
|
+
}
|
|
856
|
+
const triangles = PolygonPipeline_default.triangulate(
|
|
857
|
+
positions2D,
|
|
858
|
+
holeOffsets.length > 0 ? holeOffsets : void 0
|
|
859
|
+
);
|
|
860
|
+
if (!defined_default(triangles) || triangles.length === 0) {
|
|
861
|
+
oneTimeWarning_default(
|
|
862
|
+
"buildVectorGltfFromMVT-triangulation-failed",
|
|
863
|
+
"Polygon triangulation failed; skipping polygon."
|
|
864
|
+
);
|
|
865
|
+
continue;
|
|
866
|
+
}
|
|
867
|
+
const globalVertexStart = polygonPositions.length / 3;
|
|
868
|
+
const globalIndexStart = polygonIndices.length;
|
|
869
|
+
polygonAttributeOffsets.push(globalVertexStart);
|
|
870
|
+
polygonIndicesOffsets.push(globalIndexStart);
|
|
871
|
+
polygonHoleCounts.push(holeOffsets.length);
|
|
872
|
+
for (let i = 0; i < holeOffsets.length; i++) {
|
|
873
|
+
polygonHoleOffsets.push(globalVertexStart + holeOffsets[i]);
|
|
874
|
+
}
|
|
875
|
+
for (let i = 0; i < polygonPositionComponents.length; i++) {
|
|
876
|
+
polygonPositions.push(polygonPositionComponents[i]);
|
|
877
|
+
}
|
|
878
|
+
for (let i = 0; i < polygonPositionComponents.length / 3; i++) {
|
|
879
|
+
polygonFeatureIds.push(currentFeatureId);
|
|
880
|
+
}
|
|
881
|
+
for (let i = 0; i < triangles.length; i++) {
|
|
882
|
+
polygonIndices.push(triangles[i] + globalVertexStart);
|
|
883
|
+
}
|
|
884
|
+
polygonCount++;
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
if (pointPositions.length === 0 && linePositions.length === 0 && polygonPositions.length === 0) {
|
|
889
|
+
continue;
|
|
890
|
+
}
|
|
891
|
+
if (lineIndices.length > 0 && lineIndices[lineIndices.length - 1] === primitiveRestartIndex) {
|
|
892
|
+
lineIndices.pop();
|
|
893
|
+
}
|
|
894
|
+
const primitives = [];
|
|
895
|
+
if (pointPositions.length > 0) {
|
|
896
|
+
const positions = new Float32Array(pointPositions);
|
|
897
|
+
const minMax = computeMinMax(positions);
|
|
898
|
+
const positionAccessor = addAccessor(positions, {
|
|
899
|
+
type: "VEC3",
|
|
900
|
+
componentType: ComponentDatatype_default.FLOAT,
|
|
901
|
+
target: WebGLConstants_default.ARRAY_BUFFER,
|
|
902
|
+
min: minMax.min,
|
|
903
|
+
max: minMax.max
|
|
904
|
+
});
|
|
905
|
+
const attributes = (
|
|
906
|
+
/** @type {*} */
|
|
907
|
+
{
|
|
908
|
+
POSITION: positionAccessor
|
|
909
|
+
}
|
|
910
|
+
);
|
|
911
|
+
const extensions = (
|
|
912
|
+
/** @type {*} */
|
|
913
|
+
{
|
|
914
|
+
CESIUM_mesh_vector: {
|
|
915
|
+
vector: true,
|
|
916
|
+
count: positions.length / 3
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
);
|
|
920
|
+
addFeatureIdsToPrimitive(attributes, extensions, pointFeatureIds);
|
|
921
|
+
primitives.push({
|
|
922
|
+
mode: PrimitiveType_default.POINTS,
|
|
923
|
+
attributes,
|
|
924
|
+
extensions
|
|
925
|
+
});
|
|
926
|
+
}
|
|
927
|
+
if (linePositions.length > 0 && lineIndices.length > 1) {
|
|
928
|
+
const positions = new Float32Array(linePositions);
|
|
929
|
+
const indices = new Uint32Array(lineIndices);
|
|
930
|
+
const minMax = computeMinMax(positions);
|
|
931
|
+
const positionAccessor = addAccessor(positions, {
|
|
932
|
+
type: "VEC3",
|
|
933
|
+
componentType: ComponentDatatype_default.FLOAT,
|
|
934
|
+
target: WebGLConstants_default.ARRAY_BUFFER,
|
|
935
|
+
min: minMax.min,
|
|
936
|
+
max: minMax.max
|
|
937
|
+
});
|
|
938
|
+
const indicesAccessor = addAccessor(indices, {
|
|
939
|
+
type: "SCALAR",
|
|
940
|
+
componentType: ComponentDatatype_default.UNSIGNED_INT,
|
|
941
|
+
target: WebGLConstants_default.ELEMENT_ARRAY_BUFFER
|
|
942
|
+
});
|
|
943
|
+
const attributes = (
|
|
944
|
+
/** @type {*} */
|
|
945
|
+
{
|
|
946
|
+
POSITION: positionAccessor
|
|
947
|
+
}
|
|
948
|
+
);
|
|
949
|
+
const extensions = (
|
|
950
|
+
/** @type {*} */
|
|
951
|
+
{
|
|
952
|
+
CESIUM_mesh_vector: {
|
|
953
|
+
vector: true,
|
|
954
|
+
count: lineCount
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
);
|
|
958
|
+
addFeatureIdsToPrimitive(attributes, extensions, lineFeatureIds);
|
|
959
|
+
primitives.push({
|
|
960
|
+
mode: PrimitiveType_default.LINE_STRIP,
|
|
961
|
+
indices: indicesAccessor,
|
|
962
|
+
attributes,
|
|
963
|
+
extensions
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
if (polygonPositions.length > 0 && polygonIndices.length >= 3) {
|
|
967
|
+
const positions = new Float32Array(polygonPositions);
|
|
968
|
+
const indices = new Uint32Array(polygonIndices);
|
|
969
|
+
const attributeOffsets = new Uint32Array(polygonAttributeOffsets);
|
|
970
|
+
const indicesOffsets = new Uint32Array(polygonIndicesOffsets);
|
|
971
|
+
const hasPolygonHoles = polygonHoleOffsets.length > 0;
|
|
972
|
+
const holeCounts = hasPolygonHoles ? new Uint32Array(polygonHoleCounts) : void 0;
|
|
973
|
+
const holeOffsets = hasPolygonHoles ? new Uint32Array(polygonHoleOffsets) : void 0;
|
|
974
|
+
const minMax = computeMinMax(positions);
|
|
975
|
+
const positionAccessor = addAccessor(positions, {
|
|
976
|
+
type: "VEC3",
|
|
977
|
+
componentType: ComponentDatatype_default.FLOAT,
|
|
978
|
+
target: WebGLConstants_default.ARRAY_BUFFER,
|
|
979
|
+
min: minMax.min,
|
|
980
|
+
max: minMax.max
|
|
981
|
+
});
|
|
982
|
+
const indicesAccessor = addAccessor(indices, {
|
|
983
|
+
type: "SCALAR",
|
|
984
|
+
componentType: ComponentDatatype_default.UNSIGNED_INT,
|
|
985
|
+
target: WebGLConstants_default.ELEMENT_ARRAY_BUFFER
|
|
986
|
+
});
|
|
987
|
+
const attributeOffsetsAccessor = addAccessor(attributeOffsets, {
|
|
988
|
+
type: "SCALAR",
|
|
989
|
+
componentType: ComponentDatatype_default.UNSIGNED_INT,
|
|
990
|
+
target: WebGLConstants_default.ARRAY_BUFFER
|
|
991
|
+
});
|
|
992
|
+
const indicesOffsetsAccessor = addAccessor(indicesOffsets, {
|
|
993
|
+
type: "SCALAR",
|
|
994
|
+
componentType: ComponentDatatype_default.UNSIGNED_INT,
|
|
995
|
+
target: WebGLConstants_default.ARRAY_BUFFER
|
|
996
|
+
});
|
|
997
|
+
const holeCountsAccessor = defined_default(holeCounts) ? addAccessor(holeCounts, {
|
|
998
|
+
type: "SCALAR",
|
|
999
|
+
componentType: ComponentDatatype_default.UNSIGNED_INT,
|
|
1000
|
+
target: WebGLConstants_default.ARRAY_BUFFER
|
|
1001
|
+
}) : void 0;
|
|
1002
|
+
const holeOffsetsAccessor = defined_default(holeOffsets) ? addAccessor(holeOffsets, {
|
|
1003
|
+
type: "SCALAR",
|
|
1004
|
+
componentType: ComponentDatatype_default.UNSIGNED_INT,
|
|
1005
|
+
target: WebGLConstants_default.ARRAY_BUFFER
|
|
1006
|
+
}) : void 0;
|
|
1007
|
+
const attributes = (
|
|
1008
|
+
/** @type {*} */
|
|
1009
|
+
{
|
|
1010
|
+
POSITION: positionAccessor
|
|
1011
|
+
}
|
|
1012
|
+
);
|
|
1013
|
+
const extensions = (
|
|
1014
|
+
/** @type {*} */
|
|
1015
|
+
{
|
|
1016
|
+
CESIUM_mesh_vector: {
|
|
1017
|
+
vector: true,
|
|
1018
|
+
count: polygonCount,
|
|
1019
|
+
polygonAttributeOffsets: attributeOffsetsAccessor,
|
|
1020
|
+
polygonIndicesOffsets: indicesOffsetsAccessor
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
);
|
|
1024
|
+
if (hasPolygonHoles) {
|
|
1025
|
+
extensions.CESIUM_mesh_vector.polygonHoleCounts = holeCountsAccessor;
|
|
1026
|
+
extensions.CESIUM_mesh_vector.polygonHoleOffsets = holeOffsetsAccessor;
|
|
1027
|
+
}
|
|
1028
|
+
addFeatureIdsToPrimitive(attributes, extensions, polygonFeatureIds);
|
|
1029
|
+
primitives.push({
|
|
1030
|
+
mode: PrimitiveType_default.TRIANGLES,
|
|
1031
|
+
indices: indicesAccessor,
|
|
1032
|
+
attributes,
|
|
1033
|
+
extensions
|
|
1034
|
+
});
|
|
1035
|
+
}
|
|
1036
|
+
if (primitives.length === 0) {
|
|
1037
|
+
continue;
|
|
1038
|
+
}
|
|
1039
|
+
const meshIndex = meshes.length;
|
|
1040
|
+
meshes.push({ primitives });
|
|
1041
|
+
nodes.push({
|
|
1042
|
+
name: layer.name,
|
|
1043
|
+
mesh: meshIndex,
|
|
1044
|
+
translation
|
|
1045
|
+
});
|
|
1046
|
+
}
|
|
1047
|
+
if (nodes.length === 0) {
|
|
1048
|
+
return void 0;
|
|
1049
|
+
}
|
|
1050
|
+
const structuralMetadata = buildStructuralMetadata();
|
|
1051
|
+
const binaryChunk = concatChunks(chunks, byteLength);
|
|
1052
|
+
const extensionsUsed = ["CESIUM_mesh_vector"];
|
|
1053
|
+
if (featureIdLookup.size > 0) {
|
|
1054
|
+
extensionsUsed.push("EXT_mesh_features");
|
|
1055
|
+
}
|
|
1056
|
+
if (defined_default(structuralMetadata)) {
|
|
1057
|
+
extensionsUsed.push("EXT_structural_metadata");
|
|
1058
|
+
}
|
|
1059
|
+
const nodeIndices = nodes.map((_, i) => i);
|
|
1060
|
+
const gltfJson = {
|
|
1061
|
+
asset: {
|
|
1062
|
+
version: "2.0"
|
|
1063
|
+
},
|
|
1064
|
+
extensionsUsed,
|
|
1065
|
+
scene: 0,
|
|
1066
|
+
scenes: [
|
|
1067
|
+
{
|
|
1068
|
+
nodes: nodeIndices
|
|
1069
|
+
}
|
|
1070
|
+
],
|
|
1071
|
+
nodes,
|
|
1072
|
+
meshes,
|
|
1073
|
+
accessors,
|
|
1074
|
+
bufferViews,
|
|
1075
|
+
buffers: [
|
|
1076
|
+
{
|
|
1077
|
+
byteLength: binaryChunk.byteLength
|
|
1078
|
+
}
|
|
1079
|
+
],
|
|
1080
|
+
extensions: (
|
|
1081
|
+
/** @type {Object|undefined} */
|
|
1082
|
+
void 0
|
|
1083
|
+
)
|
|
1084
|
+
};
|
|
1085
|
+
if (defined_default(structuralMetadata)) {
|
|
1086
|
+
gltfJson.extensions = {
|
|
1087
|
+
EXT_structural_metadata: structuralMetadata
|
|
1088
|
+
};
|
|
1089
|
+
}
|
|
1090
|
+
return buildGlb(gltfJson, binaryChunk);
|
|
1091
|
+
}
|
|
1092
|
+
function getOrAssignAutoFeatureId(feature, featureIdLookup) {
|
|
1093
|
+
let id = featureIdLookup.get(feature);
|
|
1094
|
+
if (!defined_default(id)) {
|
|
1095
|
+
id = featureIdLookup.size;
|
|
1096
|
+
featureIdLookup.set(feature, id);
|
|
1097
|
+
}
|
|
1098
|
+
return id;
|
|
1099
|
+
}
|
|
1100
|
+
function mapFeatureIdFromProperty(feature, featureIdProperty, featureIdLookup) {
|
|
1101
|
+
const properties = feature.properties;
|
|
1102
|
+
if (!defined_default(properties)) {
|
|
1103
|
+
return void 0;
|
|
1104
|
+
}
|
|
1105
|
+
const propertyValue = (
|
|
1106
|
+
/** @type {*} */
|
|
1107
|
+
properties[featureIdProperty]
|
|
1108
|
+
);
|
|
1109
|
+
if (!defined_default(propertyValue)) {
|
|
1110
|
+
return void 0;
|
|
1111
|
+
}
|
|
1112
|
+
if (typeof propertyValue !== "string" && typeof propertyValue !== "number" && typeof propertyValue !== "boolean") {
|
|
1113
|
+
return void 0;
|
|
1114
|
+
}
|
|
1115
|
+
if (typeof propertyValue === "number" && !Number.isFinite(propertyValue)) {
|
|
1116
|
+
return void 0;
|
|
1117
|
+
}
|
|
1118
|
+
const mapKey = `${typeof propertyValue}:${propertyValue}`;
|
|
1119
|
+
let mappedFeatureId = featureIdLookup.get(mapKey);
|
|
1120
|
+
if (defined_default(mappedFeatureId)) {
|
|
1121
|
+
return mappedFeatureId;
|
|
1122
|
+
}
|
|
1123
|
+
mappedFeatureId = featureIdLookup.size;
|
|
1124
|
+
featureIdLookup.set(mapKey, mappedFeatureId);
|
|
1125
|
+
return mappedFeatureId;
|
|
1126
|
+
}
|
|
1127
|
+
function groupPolygonRings(rawRings) {
|
|
1128
|
+
const groups = [];
|
|
1129
|
+
for (const rawRing of rawRings) {
|
|
1130
|
+
const ring = stripClosingVertex(rawRing);
|
|
1131
|
+
if (ring.length < 3) {
|
|
1132
|
+
continue;
|
|
1133
|
+
}
|
|
1134
|
+
const area = ringSignedArea(ring);
|
|
1135
|
+
if (area <= 0) {
|
|
1136
|
+
groups.push({ outerRing: ring, holes: [] });
|
|
1137
|
+
} else if (groups.length > 0) {
|
|
1138
|
+
groups[groups.length - 1].holes.push(ring);
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
return groups;
|
|
1142
|
+
}
|
|
1143
|
+
function ringSignedArea(ring) {
|
|
1144
|
+
let area = 0;
|
|
1145
|
+
for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {
|
|
1146
|
+
area += (ring[j].x + ring[i].x) * (ring[j].y - ring[i].y);
|
|
1147
|
+
}
|
|
1148
|
+
return area / 2;
|
|
1149
|
+
}
|
|
1150
|
+
function stripClosingVertex(ring) {
|
|
1151
|
+
if (ring.length > 1 && ring[0].x === ring[ring.length - 1].x && ring[0].y === ring[ring.length - 1].y) {
|
|
1152
|
+
return ring.slice(0, ring.length - 1);
|
|
1153
|
+
}
|
|
1154
|
+
return ring;
|
|
1155
|
+
}
|
|
1156
|
+
function appendTilePointAsLocalPosition(point, tileX, tileY, tileZ, extent, height, origin, out) {
|
|
1157
|
+
const n = 1 << tileZ;
|
|
1158
|
+
const u = (tileX + point.x / extent) / n;
|
|
1159
|
+
const v = (tileY + point.y / extent) / n;
|
|
1160
|
+
const lon = u * 2 * Math.PI - Math.PI;
|
|
1161
|
+
const lat = Math.atan(Math.sinh(Math.PI * (1 - 2 * v)));
|
|
1162
|
+
Cartesian3_default.fromRadians(lon, lat, height, void 0, scratchWorld);
|
|
1163
|
+
Cartesian3_default.subtract(scratchWorld, origin, scratchLocal);
|
|
1164
|
+
out.push(scratchLocal.x, scratchLocal.y, scratchLocal.z);
|
|
1165
|
+
}
|
|
1166
|
+
function buildGlb(gltfJson, binaryChunk) {
|
|
1167
|
+
const GLB_MAGIC = 1179937895;
|
|
1168
|
+
const GLB_VERSION = 2;
|
|
1169
|
+
const CHUNK_TYPE_JSON = 1313821514;
|
|
1170
|
+
const CHUNK_TYPE_BIN = 5130562;
|
|
1171
|
+
const jsonBytes = new TextEncoder().encode(JSON.stringify(gltfJson));
|
|
1172
|
+
const jsonPaddedLength = Math.ceil(jsonBytes.length / 4) * 4;
|
|
1173
|
+
const jsonChunk = new Uint8Array(jsonPaddedLength);
|
|
1174
|
+
jsonChunk.fill(32);
|
|
1175
|
+
jsonChunk.set(jsonBytes);
|
|
1176
|
+
const binPaddedLength = Math.ceil(binaryChunk.byteLength / 4) * 4;
|
|
1177
|
+
const binChunk = new Uint8Array(binPaddedLength);
|
|
1178
|
+
binChunk.set(binaryChunk);
|
|
1179
|
+
const totalLength = 12 + // header
|
|
1180
|
+
8 + jsonPaddedLength + // JSON chunk header + data
|
|
1181
|
+
8 + binPaddedLength;
|
|
1182
|
+
const glb = new Uint8Array(totalLength);
|
|
1183
|
+
const view = new DataView(glb.buffer);
|
|
1184
|
+
let offset = 0;
|
|
1185
|
+
view.setUint32(offset, GLB_MAGIC, true);
|
|
1186
|
+
offset += 4;
|
|
1187
|
+
view.setUint32(offset, GLB_VERSION, true);
|
|
1188
|
+
offset += 4;
|
|
1189
|
+
view.setUint32(offset, totalLength, true);
|
|
1190
|
+
offset += 4;
|
|
1191
|
+
view.setUint32(offset, jsonPaddedLength, true);
|
|
1192
|
+
offset += 4;
|
|
1193
|
+
view.setUint32(offset, CHUNK_TYPE_JSON, true);
|
|
1194
|
+
offset += 4;
|
|
1195
|
+
glb.set(jsonChunk, offset);
|
|
1196
|
+
offset += jsonPaddedLength;
|
|
1197
|
+
view.setUint32(offset, binPaddedLength, true);
|
|
1198
|
+
offset += 4;
|
|
1199
|
+
view.setUint32(offset, CHUNK_TYPE_BIN, true);
|
|
1200
|
+
offset += 4;
|
|
1201
|
+
glb.set(binChunk, offset);
|
|
1202
|
+
return glb;
|
|
1203
|
+
}
|
|
1204
|
+
function concatChunks(chunks, totalByteLength) {
|
|
1205
|
+
const out = new Uint8Array(totalByteLength);
|
|
1206
|
+
let offset = 0;
|
|
1207
|
+
for (const chunk of chunks) {
|
|
1208
|
+
out.set(chunk, offset);
|
|
1209
|
+
offset += chunk.byteLength;
|
|
1210
|
+
}
|
|
1211
|
+
return out;
|
|
1212
|
+
}
|
|
1213
|
+
var buildVectorGltfFromMVT_default = buildVectorGltfFromMVT;
|
|
1214
|
+
|
|
1215
|
+
// packages/engine/Source/Scene/decodeMVT.js
|
|
1216
|
+
var textDecoder = new TextDecoder();
|
|
1217
|
+
var GeomType = {
|
|
1218
|
+
UNKNOWN: 0,
|
|
1219
|
+
POINT: 1,
|
|
1220
|
+
LINESTRING: 2,
|
|
1221
|
+
POLYGON: 3
|
|
1222
|
+
};
|
|
1223
|
+
var TileField = {
|
|
1224
|
+
LAYERS: 3
|
|
1225
|
+
};
|
|
1226
|
+
var LayerField = {
|
|
1227
|
+
NAME: 1,
|
|
1228
|
+
FEATURES: 2,
|
|
1229
|
+
KEYS: 3,
|
|
1230
|
+
VALUES: 4,
|
|
1231
|
+
EXTENT: 5
|
|
1232
|
+
};
|
|
1233
|
+
var FeatureField = {
|
|
1234
|
+
ID: 1,
|
|
1235
|
+
TAGS: 2,
|
|
1236
|
+
TYPE: 3,
|
|
1237
|
+
GEOMETRY: 4
|
|
1238
|
+
};
|
|
1239
|
+
var GeoVisLayerField = {
|
|
1240
|
+
VALUES: 1,
|
|
1241
|
+
FEATURES: 2,
|
|
1242
|
+
NAME: 3,
|
|
1243
|
+
KEYS: 4,
|
|
1244
|
+
EXTENT: 5
|
|
1245
|
+
};
|
|
1246
|
+
var GeoVisFeatureField = {
|
|
1247
|
+
TYPE: 1,
|
|
1248
|
+
GEOMETRY: 2,
|
|
1249
|
+
TAGS: 3
|
|
1250
|
+
};
|
|
1251
|
+
var ValueField = {
|
|
1252
|
+
STRING: 1,
|
|
1253
|
+
FLOAT: 2,
|
|
1254
|
+
DOUBLE: 3,
|
|
1255
|
+
INT64: 4,
|
|
1256
|
+
UINT64: 5,
|
|
1257
|
+
SINT64: 6,
|
|
1258
|
+
BOOL: 7
|
|
1259
|
+
};
|
|
1260
|
+
var geomTypeName = ["Unknown", "Point", "LineString", "Polygon"];
|
|
1261
|
+
function decodeMVT(arrayBuffer, format = "mvt") {
|
|
1262
|
+
const bytes = new Uint8Array(arrayBuffer);
|
|
1263
|
+
if (format === "geovis") {
|
|
1264
|
+
return decodeGeoVisMVT(bytes);
|
|
1265
|
+
}
|
|
1266
|
+
const layers = [];
|
|
1267
|
+
let pos = 0;
|
|
1268
|
+
while (pos < bytes.length) {
|
|
1269
|
+
const tag = readTag(bytes, pos, bytes.length);
|
|
1270
|
+
const fieldNumber = tag.fieldNumber;
|
|
1271
|
+
const wireType = tag.wireType;
|
|
1272
|
+
pos = tag.newPos;
|
|
1273
|
+
if (fieldNumber === TileField.LAYERS && wireType === 2) {
|
|
1274
|
+
const layerLength = readVarintLength(bytes, pos, bytes.length);
|
|
1275
|
+
pos = layerLength.newPos;
|
|
1276
|
+
const layerEnd = advanceByLength(
|
|
1277
|
+
pos,
|
|
1278
|
+
layerLength.value,
|
|
1279
|
+
bytes.length,
|
|
1280
|
+
"layer"
|
|
1281
|
+
);
|
|
1282
|
+
layers.push(decodeLayer(bytes, pos, layerEnd));
|
|
1283
|
+
pos = layerEnd;
|
|
1284
|
+
} else {
|
|
1285
|
+
pos = skipField(bytes, pos, wireType, bytes.length);
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
return { layers };
|
|
1289
|
+
}
|
|
1290
|
+
function decodeGeoVisMVT(bytes) {
|
|
1291
|
+
const layers = [];
|
|
1292
|
+
let pos = 0;
|
|
1293
|
+
while (pos < bytes.length) {
|
|
1294
|
+
const tag = readTag(bytes, pos, bytes.length);
|
|
1295
|
+
pos = tag.newPos;
|
|
1296
|
+
if (tag.fieldNumber !== TileField.LAYERS || tag.wireType !== 2) {
|
|
1297
|
+
pos = skipField(bytes, pos, tag.wireType, bytes.length);
|
|
1298
|
+
continue;
|
|
1299
|
+
}
|
|
1300
|
+
const layerLength = readVarintLength(bytes, pos, bytes.length);
|
|
1301
|
+
pos = layerLength.newPos;
|
|
1302
|
+
const layerEnd = advanceByLength(
|
|
1303
|
+
pos,
|
|
1304
|
+
layerLength.value,
|
|
1305
|
+
bytes.length,
|
|
1306
|
+
"GeoVis layer"
|
|
1307
|
+
);
|
|
1308
|
+
layers.push(decodeGeoVisLayer(bytes, pos, layerEnd));
|
|
1309
|
+
pos = layerEnd;
|
|
1310
|
+
}
|
|
1311
|
+
return { layers };
|
|
1312
|
+
}
|
|
1313
|
+
function decodeGeoVisLayer(bytes, start, end) {
|
|
1314
|
+
let pos = start;
|
|
1315
|
+
let name = "";
|
|
1316
|
+
let extent = 4096;
|
|
1317
|
+
const keys = [];
|
|
1318
|
+
const values = [];
|
|
1319
|
+
const rawFeatures = [];
|
|
1320
|
+
while (pos < end) {
|
|
1321
|
+
const tag = readTag(bytes, pos, end);
|
|
1322
|
+
pos = tag.newPos;
|
|
1323
|
+
if (tag.wireType === 2) {
|
|
1324
|
+
const length = readVarintLength(bytes, pos, end);
|
|
1325
|
+
pos = length.newPos;
|
|
1326
|
+
const fieldEnd = advanceByLength(
|
|
1327
|
+
pos,
|
|
1328
|
+
length.value,
|
|
1329
|
+
end,
|
|
1330
|
+
"GeoVis layer field"
|
|
1331
|
+
);
|
|
1332
|
+
if (tag.fieldNumber === GeoVisLayerField.VALUES) {
|
|
1333
|
+
values.push(decodeValue(bytes, pos, fieldEnd));
|
|
1334
|
+
} else if (tag.fieldNumber === GeoVisLayerField.FEATURES) {
|
|
1335
|
+
rawFeatures.push({ start: pos, end: fieldEnd });
|
|
1336
|
+
} else if (tag.fieldNumber === GeoVisLayerField.NAME) {
|
|
1337
|
+
name = readString(bytes, pos, fieldEnd - pos);
|
|
1338
|
+
} else if (tag.fieldNumber === GeoVisLayerField.KEYS) {
|
|
1339
|
+
keys.push(readString(bytes, pos, fieldEnd - pos));
|
|
1340
|
+
}
|
|
1341
|
+
pos = fieldEnd;
|
|
1342
|
+
} else if (tag.fieldNumber === GeoVisLayerField.EXTENT && tag.wireType === 0) {
|
|
1343
|
+
const value = readVarint32(bytes, pos, end);
|
|
1344
|
+
extent = value.value;
|
|
1345
|
+
pos = value.newPos;
|
|
1346
|
+
} else {
|
|
1347
|
+
pos = skipField(bytes, pos, tag.wireType, end);
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
const features = rawFeatures.map(
|
|
1351
|
+
({ start: featureStart, end: featureEnd }) => decodeGeoVisFeature(bytes, featureStart, featureEnd, keys, values)
|
|
1352
|
+
);
|
|
1353
|
+
return { name, extent, features };
|
|
1354
|
+
}
|
|
1355
|
+
function decodeGeoVisFeature(bytes, start, end, keys, values) {
|
|
1356
|
+
let pos = start;
|
|
1357
|
+
let geomType = GeomType.UNKNOWN;
|
|
1358
|
+
const tags = [];
|
|
1359
|
+
const geometryCommands = [];
|
|
1360
|
+
while (pos < end) {
|
|
1361
|
+
const tag = readTag(bytes, pos, end);
|
|
1362
|
+
pos = tag.newPos;
|
|
1363
|
+
if (tag.wireType === 0 && tag.fieldNumber === GeoVisFeatureField.TYPE) {
|
|
1364
|
+
const value = readVarint32(bytes, pos, end);
|
|
1365
|
+
geomType = value.value - 1;
|
|
1366
|
+
pos = value.newPos;
|
|
1367
|
+
} else if (tag.wireType === 2) {
|
|
1368
|
+
const length = readVarintLength(bytes, pos, end);
|
|
1369
|
+
pos = length.newPos;
|
|
1370
|
+
const fieldEnd = advanceByLength(
|
|
1371
|
+
pos,
|
|
1372
|
+
length.value,
|
|
1373
|
+
end,
|
|
1374
|
+
"GeoVis feature field"
|
|
1375
|
+
);
|
|
1376
|
+
const target = tag.fieldNumber === GeoVisFeatureField.GEOMETRY ? geometryCommands : tag.fieldNumber === GeoVisFeatureField.TAGS ? tags : void 0;
|
|
1377
|
+
if (target !== void 0) {
|
|
1378
|
+
while (pos < fieldEnd) {
|
|
1379
|
+
const value = readVarint32(bytes, pos, fieldEnd);
|
|
1380
|
+
target.push(value.value);
|
|
1381
|
+
pos = value.newPos;
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
pos = fieldEnd;
|
|
1385
|
+
} else {
|
|
1386
|
+
pos = skipField(bytes, pos, tag.wireType, end);
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
const properties = {};
|
|
1390
|
+
for (let i = 0; i < tags.length - 1; i += 2) {
|
|
1391
|
+
const key = keys[tags[i]];
|
|
1392
|
+
const value = values[tags[i + 1]];
|
|
1393
|
+
if (typeof key === "string" && value !== void 0) {
|
|
1394
|
+
properties[key] = value;
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
return {
|
|
1398
|
+
id: void 0,
|
|
1399
|
+
type: (
|
|
1400
|
+
/** @type {"Point"|"LineString"|"Polygon"|"Unknown"} */
|
|
1401
|
+
geomTypeName[geomType] ?? "Unknown"
|
|
1402
|
+
),
|
|
1403
|
+
geometry: decodeGeometry(
|
|
1404
|
+
geomType,
|
|
1405
|
+
normalizeGeoVisGeometry(geometryCommands)
|
|
1406
|
+
),
|
|
1407
|
+
properties
|
|
1408
|
+
};
|
|
1409
|
+
}
|
|
1410
|
+
function normalizeGeoVisGeometry(commands) {
|
|
1411
|
+
const normalized = [];
|
|
1412
|
+
let pos = 0;
|
|
1413
|
+
while (pos < commands.length) {
|
|
1414
|
+
const command = commands[pos++];
|
|
1415
|
+
const count = command >>> 3;
|
|
1416
|
+
const commandId = command & 7;
|
|
1417
|
+
let mvtCommandId;
|
|
1418
|
+
if (commandId === 4) {
|
|
1419
|
+
mvtCommandId = 1;
|
|
1420
|
+
} else if (commandId === 3) {
|
|
1421
|
+
mvtCommandId = 2;
|
|
1422
|
+
} else if (commandId === 7) {
|
|
1423
|
+
mvtCommandId = 7;
|
|
1424
|
+
} else {
|
|
1425
|
+
return [];
|
|
1426
|
+
}
|
|
1427
|
+
normalized.push(count << 3 | mvtCommandId);
|
|
1428
|
+
if (mvtCommandId === 7) {
|
|
1429
|
+
continue;
|
|
1430
|
+
}
|
|
1431
|
+
const coordinateCount = count * 2;
|
|
1432
|
+
if (pos + coordinateCount > commands.length) {
|
|
1433
|
+
return [];
|
|
1434
|
+
}
|
|
1435
|
+
for (let i = 0; i < coordinateCount; i++) {
|
|
1436
|
+
normalized.push(commands[pos++]);
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
return normalized;
|
|
1440
|
+
}
|
|
1441
|
+
function decodeLayer(bytes, start, end) {
|
|
1442
|
+
let pos = start;
|
|
1443
|
+
let name = "";
|
|
1444
|
+
let extent = 4096;
|
|
1445
|
+
const keys = [];
|
|
1446
|
+
const values = [];
|
|
1447
|
+
const rawFeatures = [];
|
|
1448
|
+
while (pos < end) {
|
|
1449
|
+
const tag = readTag(bytes, pos, end);
|
|
1450
|
+
const fieldNumber = tag.fieldNumber;
|
|
1451
|
+
const wireType = tag.wireType;
|
|
1452
|
+
pos = tag.newPos;
|
|
1453
|
+
if (fieldNumber === LayerField.NAME && wireType === 2) {
|
|
1454
|
+
const length = readVarintLength(bytes, pos, end);
|
|
1455
|
+
pos = length.newPos;
|
|
1456
|
+
const stringEnd = advanceByLength(pos, length.value, end, "layer name");
|
|
1457
|
+
name = readString(bytes, pos, length.value);
|
|
1458
|
+
pos = stringEnd;
|
|
1459
|
+
} else if (fieldNumber === LayerField.FEATURES && wireType === 2) {
|
|
1460
|
+
const length = readVarintLength(bytes, pos, end);
|
|
1461
|
+
pos = length.newPos;
|
|
1462
|
+
const featureEnd = advanceByLength(pos, length.value, end, "feature");
|
|
1463
|
+
rawFeatures.push({ start: pos, end: featureEnd });
|
|
1464
|
+
pos = featureEnd;
|
|
1465
|
+
} else if (fieldNumber === LayerField.KEYS && wireType === 2) {
|
|
1466
|
+
const length = readVarintLength(bytes, pos, end);
|
|
1467
|
+
pos = length.newPos;
|
|
1468
|
+
const stringEnd = advanceByLength(pos, length.value, end, "key");
|
|
1469
|
+
keys.push(readString(bytes, pos, length.value));
|
|
1470
|
+
pos = stringEnd;
|
|
1471
|
+
} else if (fieldNumber === LayerField.VALUES && wireType === 2) {
|
|
1472
|
+
const length = readVarintLength(bytes, pos, end);
|
|
1473
|
+
pos = length.newPos;
|
|
1474
|
+
const valueEnd = advanceByLength(pos, length.value, end, "value");
|
|
1475
|
+
const value = decodeValue(bytes, pos, valueEnd);
|
|
1476
|
+
values.push(value);
|
|
1477
|
+
pos = valueEnd;
|
|
1478
|
+
} else if (fieldNumber === LayerField.EXTENT && wireType === 0) {
|
|
1479
|
+
const value = readVarint32(bytes, pos, end);
|
|
1480
|
+
extent = value.value;
|
|
1481
|
+
pos = value.newPos;
|
|
1482
|
+
} else {
|
|
1483
|
+
pos = skipField(bytes, pos, wireType, end);
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
const features = rawFeatures.map(
|
|
1487
|
+
({ start: featureStart, end: featureEnd }) => decodeFeature(bytes, featureStart, featureEnd, keys, values)
|
|
1488
|
+
);
|
|
1489
|
+
return { name, extent, features };
|
|
1490
|
+
}
|
|
1491
|
+
function decodeFeature(bytes, start, end, keys, values) {
|
|
1492
|
+
let pos = start;
|
|
1493
|
+
let id;
|
|
1494
|
+
let geomType = GeomType.UNKNOWN;
|
|
1495
|
+
const tags = [];
|
|
1496
|
+
const geometryCommands = [];
|
|
1497
|
+
while (pos < end) {
|
|
1498
|
+
const tag = readTag(bytes, pos, end);
|
|
1499
|
+
const fieldNumber = tag.fieldNumber;
|
|
1500
|
+
const wireType = tag.wireType;
|
|
1501
|
+
pos = tag.newPos;
|
|
1502
|
+
if (fieldNumber === FeatureField.ID && wireType === 0) {
|
|
1503
|
+
const value = readBigVarint(bytes, pos, end);
|
|
1504
|
+
id = value.value;
|
|
1505
|
+
pos = value.newPos;
|
|
1506
|
+
} else if (fieldNumber === FeatureField.TYPE && wireType === 0) {
|
|
1507
|
+
const value = readVarint32(bytes, pos, end);
|
|
1508
|
+
geomType = value.value;
|
|
1509
|
+
pos = value.newPos;
|
|
1510
|
+
} else if (fieldNumber === FeatureField.TAGS && wireType === 2) {
|
|
1511
|
+
const length = readVarintLength(bytes, pos, end);
|
|
1512
|
+
pos = length.newPos;
|
|
1513
|
+
const tagEnd = advanceByLength(pos, length.value, end, "feature tags");
|
|
1514
|
+
while (pos < tagEnd) {
|
|
1515
|
+
const value = readVarint32(bytes, pos, tagEnd);
|
|
1516
|
+
tags.push(value.value);
|
|
1517
|
+
pos = value.newPos;
|
|
1518
|
+
}
|
|
1519
|
+
} else if (fieldNumber === FeatureField.GEOMETRY && wireType === 2) {
|
|
1520
|
+
const length = readVarintLength(bytes, pos, end);
|
|
1521
|
+
pos = length.newPos;
|
|
1522
|
+
const geometryEnd = advanceByLength(
|
|
1523
|
+
pos,
|
|
1524
|
+
length.value,
|
|
1525
|
+
end,
|
|
1526
|
+
"feature geometry"
|
|
1527
|
+
);
|
|
1528
|
+
while (pos < geometryEnd) {
|
|
1529
|
+
const value = readVarint32(bytes, pos, geometryEnd);
|
|
1530
|
+
geometryCommands.push(value.value);
|
|
1531
|
+
pos = value.newPos;
|
|
1532
|
+
}
|
|
1533
|
+
} else {
|
|
1534
|
+
pos = skipField(bytes, pos, wireType, end);
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
const properties = {};
|
|
1538
|
+
for (let i = 0; i < tags.length - 1; i += 2) {
|
|
1539
|
+
const key = keys[tags[i]];
|
|
1540
|
+
const value = values[tags[i + 1]];
|
|
1541
|
+
if (typeof key !== "string" || value === void 0) {
|
|
1542
|
+
continue;
|
|
1543
|
+
}
|
|
1544
|
+
properties[key] = value;
|
|
1545
|
+
}
|
|
1546
|
+
const geometry = decodeGeometry(geomType, geometryCommands);
|
|
1547
|
+
return {
|
|
1548
|
+
id,
|
|
1549
|
+
type: (
|
|
1550
|
+
/** @type {"Point"|"LineString"|"Polygon"|"Unknown"} */
|
|
1551
|
+
geomTypeName[geomType] ?? "Unknown"
|
|
1552
|
+
),
|
|
1553
|
+
geometry,
|
|
1554
|
+
properties
|
|
1555
|
+
};
|
|
1556
|
+
}
|
|
1557
|
+
function decodeGeometry(geomType, cmds) {
|
|
1558
|
+
let i = 0;
|
|
1559
|
+
let x = 0;
|
|
1560
|
+
let y = 0;
|
|
1561
|
+
if (geomType === GeomType.POINT) {
|
|
1562
|
+
const points = [];
|
|
1563
|
+
while (i < cmds.length) {
|
|
1564
|
+
const cmd = cmds[i++];
|
|
1565
|
+
const cmdId = cmd & 7;
|
|
1566
|
+
const count = cmd >> 3;
|
|
1567
|
+
if (cmdId === 1) {
|
|
1568
|
+
for (let c = 0; c < count; c++) {
|
|
1569
|
+
x += zigzag(cmds[i++]);
|
|
1570
|
+
y += zigzag(cmds[i++]);
|
|
1571
|
+
points.push({ x, y });
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
return points;
|
|
1576
|
+
}
|
|
1577
|
+
if (geomType === GeomType.LINESTRING) {
|
|
1578
|
+
const lines = [];
|
|
1579
|
+
let current = null;
|
|
1580
|
+
while (i < cmds.length) {
|
|
1581
|
+
const cmd = cmds[i++];
|
|
1582
|
+
const cmdId = cmd & 7;
|
|
1583
|
+
const count = cmd >> 3;
|
|
1584
|
+
if (cmdId === 1) {
|
|
1585
|
+
if (current !== null) {
|
|
1586
|
+
lines.push(current);
|
|
1587
|
+
}
|
|
1588
|
+
current = [];
|
|
1589
|
+
x += zigzag(cmds[i++]);
|
|
1590
|
+
y += zigzag(cmds[i++]);
|
|
1591
|
+
current.push({ x, y });
|
|
1592
|
+
} else if (cmdId === 2) {
|
|
1593
|
+
for (let c = 0; c < count; c++) {
|
|
1594
|
+
x += zigzag(cmds[i++]);
|
|
1595
|
+
y += zigzag(cmds[i++]);
|
|
1596
|
+
current.push({ x, y });
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
if (current !== null) {
|
|
1601
|
+
lines.push(current);
|
|
1602
|
+
}
|
|
1603
|
+
return lines;
|
|
1604
|
+
}
|
|
1605
|
+
if (geomType === GeomType.POLYGON) {
|
|
1606
|
+
const rings = [];
|
|
1607
|
+
let current = null;
|
|
1608
|
+
while (i < cmds.length) {
|
|
1609
|
+
const cmd = cmds[i++];
|
|
1610
|
+
const cmdId = cmd & 7;
|
|
1611
|
+
const count = cmd >> 3;
|
|
1612
|
+
if (cmdId === 1) {
|
|
1613
|
+
if (current !== null) {
|
|
1614
|
+
rings.push(current);
|
|
1615
|
+
}
|
|
1616
|
+
current = [];
|
|
1617
|
+
x += zigzag(cmds[i++]);
|
|
1618
|
+
y += zigzag(cmds[i++]);
|
|
1619
|
+
current.push({ x, y });
|
|
1620
|
+
} else if (cmdId === 2) {
|
|
1621
|
+
for (let c = 0; c < count; c++) {
|
|
1622
|
+
x += zigzag(cmds[i++]);
|
|
1623
|
+
y += zigzag(cmds[i++]);
|
|
1624
|
+
current.push({ x, y });
|
|
1625
|
+
}
|
|
1626
|
+
} else if (cmdId === 7) {
|
|
1627
|
+
if (current !== null && current.length > 0) {
|
|
1628
|
+
current.push({ x: current[0].x, y: current[0].y });
|
|
1629
|
+
rings.push(current);
|
|
1630
|
+
current = null;
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
if (current !== null) {
|
|
1635
|
+
rings.push(current);
|
|
1636
|
+
}
|
|
1637
|
+
return rings;
|
|
1638
|
+
}
|
|
1639
|
+
return [];
|
|
1640
|
+
}
|
|
1641
|
+
function decodeValue(bytes, start, end) {
|
|
1642
|
+
let pos = start;
|
|
1643
|
+
while (pos < end) {
|
|
1644
|
+
const tag = readTag(bytes, pos, end);
|
|
1645
|
+
const fieldNumber = tag.fieldNumber;
|
|
1646
|
+
const wireType = tag.wireType;
|
|
1647
|
+
pos = tag.newPos;
|
|
1648
|
+
if (fieldNumber === ValueField.STRING && wireType === 2) {
|
|
1649
|
+
const length = readVarintLength(bytes, pos, end);
|
|
1650
|
+
pos = length.newPos;
|
|
1651
|
+
const stringEnd = advanceByLength(pos, length.value, end, "string value");
|
|
1652
|
+
return readString(bytes, pos, stringEnd - pos);
|
|
1653
|
+
} else if (fieldNumber === ValueField.FLOAT && wireType === 5) {
|
|
1654
|
+
advanceByLength(pos, 4, end, "float value");
|
|
1655
|
+
const v = new DataView(
|
|
1656
|
+
bytes.buffer,
|
|
1657
|
+
bytes.byteOffset + pos,
|
|
1658
|
+
4
|
|
1659
|
+
).getFloat32(0, true);
|
|
1660
|
+
return v;
|
|
1661
|
+
} else if (fieldNumber === ValueField.DOUBLE && wireType === 1) {
|
|
1662
|
+
advanceByLength(pos, 8, end, "double value");
|
|
1663
|
+
const v = new DataView(
|
|
1664
|
+
bytes.buffer,
|
|
1665
|
+
bytes.byteOffset + pos,
|
|
1666
|
+
8
|
|
1667
|
+
).getFloat64(0, true);
|
|
1668
|
+
return v;
|
|
1669
|
+
} else if (fieldNumber === ValueField.INT64 && wireType === 0) {
|
|
1670
|
+
const value = readBigVarint(bytes, pos, end);
|
|
1671
|
+
return toSafeNumber(value.value);
|
|
1672
|
+
} else if (fieldNumber === ValueField.UINT64 && wireType === 0) {
|
|
1673
|
+
const value = readBigVarint(bytes, pos, end);
|
|
1674
|
+
return toSafeNumber(value.value);
|
|
1675
|
+
} else if (fieldNumber === ValueField.SINT64 && wireType === 0) {
|
|
1676
|
+
const value = readBigVarint(bytes, pos, end);
|
|
1677
|
+
return toSafeNumber(zigzagBigInt(value.value));
|
|
1678
|
+
} else if (fieldNumber === ValueField.BOOL && wireType === 0) {
|
|
1679
|
+
const value = readVarint32(bytes, pos, end);
|
|
1680
|
+
return value.value !== 0;
|
|
1681
|
+
}
|
|
1682
|
+
pos = skipField(bytes, pos, wireType, end);
|
|
1683
|
+
}
|
|
1684
|
+
return void 0;
|
|
1685
|
+
}
|
|
1686
|
+
function readTag(bytes, pos, limit) {
|
|
1687
|
+
const value = readVarint32(bytes, pos, limit);
|
|
1688
|
+
return {
|
|
1689
|
+
fieldNumber: value.value >>> 3,
|
|
1690
|
+
wireType: value.value & 7,
|
|
1691
|
+
newPos: value.newPos
|
|
1692
|
+
};
|
|
1693
|
+
}
|
|
1694
|
+
function readVarint32(bytes, pos, limit) {
|
|
1695
|
+
const value = readBigVarint(bytes, pos, limit, 5);
|
|
1696
|
+
if (value.value > 0xffffffffn) {
|
|
1697
|
+
throw new RuntimeError_default("Invalid MVT uint32 varint.");
|
|
1698
|
+
}
|
|
1699
|
+
return {
|
|
1700
|
+
value: Number(value.value),
|
|
1701
|
+
newPos: value.newPos
|
|
1702
|
+
};
|
|
1703
|
+
}
|
|
1704
|
+
function readVarintLength(bytes, pos, limit) {
|
|
1705
|
+
const value = readBigVarint(bytes, pos, limit);
|
|
1706
|
+
if (value.value > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
1707
|
+
throw new RuntimeError_default("Invalid MVT length varint.");
|
|
1708
|
+
}
|
|
1709
|
+
return {
|
|
1710
|
+
value: Number(value.value),
|
|
1711
|
+
newPos: value.newPos
|
|
1712
|
+
};
|
|
1713
|
+
}
|
|
1714
|
+
function readBigVarint(bytes, pos, limit, maxBytes) {
|
|
1715
|
+
let result = 0n;
|
|
1716
|
+
let shift = 0n;
|
|
1717
|
+
let byteCount = 0;
|
|
1718
|
+
const byteLimit = maxBytes ?? 10;
|
|
1719
|
+
while (true) {
|
|
1720
|
+
if (pos >= limit || pos >= bytes.length) {
|
|
1721
|
+
throw new RuntimeError_default("Invalid MVT: truncated varint.");
|
|
1722
|
+
}
|
|
1723
|
+
const byte = bytes[pos++];
|
|
1724
|
+
result |= BigInt(byte & 127) << shift;
|
|
1725
|
+
byteCount++;
|
|
1726
|
+
if ((byte & 128) === 0) {
|
|
1727
|
+
break;
|
|
1728
|
+
}
|
|
1729
|
+
if (byteCount >= byteLimit) {
|
|
1730
|
+
throw new RuntimeError_default("Invalid MVT: varint is too long.");
|
|
1731
|
+
}
|
|
1732
|
+
shift += 7n;
|
|
1733
|
+
}
|
|
1734
|
+
return {
|
|
1735
|
+
value: result,
|
|
1736
|
+
newPos: pos
|
|
1737
|
+
};
|
|
1738
|
+
}
|
|
1739
|
+
function readString(bytes, pos, len) {
|
|
1740
|
+
const end = advanceByLength(pos, len, bytes.length, "string");
|
|
1741
|
+
return textDecoder.decode(bytes.subarray(pos, end));
|
|
1742
|
+
}
|
|
1743
|
+
function advanceByLength(pos, length, limit, fieldName) {
|
|
1744
|
+
if (!Number.isFinite(length) || length < 0) {
|
|
1745
|
+
throw new RuntimeError_default(`Invalid MVT ${fieldName}: invalid length.`);
|
|
1746
|
+
}
|
|
1747
|
+
const end = pos + length;
|
|
1748
|
+
if (!Number.isFinite(end) || end < pos || end > limit) {
|
|
1749
|
+
throw new RuntimeError_default(
|
|
1750
|
+
`Invalid MVT ${fieldName}: length exceeds available bytes.`
|
|
1751
|
+
);
|
|
1752
|
+
}
|
|
1753
|
+
return end;
|
|
1754
|
+
}
|
|
1755
|
+
function skipField(bytes, pos, wireType, limit) {
|
|
1756
|
+
if (wireType === 0) {
|
|
1757
|
+
return readBigVarint(bytes, pos, limit).newPos;
|
|
1758
|
+
} else if (wireType === 1) {
|
|
1759
|
+
return advanceByLength(pos, 8, limit, "fixed64 field");
|
|
1760
|
+
} else if (wireType === 2) {
|
|
1761
|
+
const length = readVarintLength(bytes, pos, limit);
|
|
1762
|
+
return advanceByLength(
|
|
1763
|
+
length.newPos,
|
|
1764
|
+
length.value,
|
|
1765
|
+
limit,
|
|
1766
|
+
"length-delimited field"
|
|
1767
|
+
);
|
|
1768
|
+
} else if (wireType === 5) {
|
|
1769
|
+
return advanceByLength(pos, 4, limit, "fixed32 field");
|
|
1770
|
+
}
|
|
1771
|
+
throw new RuntimeError_default(`Unsupported protobuf wire type: ${wireType}`);
|
|
1772
|
+
}
|
|
1773
|
+
function zigzag(n) {
|
|
1774
|
+
return n >>> 1 ^ -(n & 1);
|
|
1775
|
+
}
|
|
1776
|
+
function zigzagBigInt(n) {
|
|
1777
|
+
return n >> 1n ^ -(n & 1n);
|
|
1778
|
+
}
|
|
1779
|
+
function toSafeNumber(value) {
|
|
1780
|
+
if (value <= BigInt(Number.MAX_SAFE_INTEGER) && value >= BigInt(Number.MIN_SAFE_INTEGER)) {
|
|
1781
|
+
return Number(value);
|
|
1782
|
+
}
|
|
1783
|
+
return value;
|
|
1784
|
+
}
|
|
1785
|
+
var decodeMVT_default = decodeMVT;
|
|
1786
|
+
|
|
1787
|
+
// packages/engine/Source/Workers/createMvtTile.js
|
|
1788
|
+
function hasRenderableFeatures(decodedTile) {
|
|
1789
|
+
for (const layer of decodedTile.layers) {
|
|
1790
|
+
for (const feature of layer.features) {
|
|
1791
|
+
if ((feature.type === "Point" || feature.type === "LineString" || feature.type === "Polygon") && feature.geometry.length > 0) {
|
|
1792
|
+
return true;
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
return false;
|
|
1797
|
+
}
|
|
1798
|
+
function createMvtTile(parameters, transferableObjects) {
|
|
1799
|
+
const decodedTile = decodeMVT_default(parameters.arrayBuffer, parameters.format);
|
|
1800
|
+
const glb = parameters.buildGeometry !== false ? buildVectorGltfFromMVT_default(decodedTile, parameters.tileCoordinates, {
|
|
1801
|
+
featureIdProperty: parameters.featureIdProperty
|
|
1802
|
+
}) : void 0;
|
|
1803
|
+
if (glb !== void 0) {
|
|
1804
|
+
transferableObjects.push(glb.buffer);
|
|
1805
|
+
}
|
|
1806
|
+
return {
|
|
1807
|
+
glb: glb?.buffer,
|
|
1808
|
+
hasFeatures: hasRenderableFeatures(decodedTile),
|
|
1809
|
+
decodedTile: parameters.includeDecodedTile ? decodedTile : void 0
|
|
1810
|
+
};
|
|
1811
|
+
}
|
|
1812
|
+
var createMvtTile_default = createTaskProcessorWorker_default(createMvtTile);
|
|
1813
|
+
export {
|
|
1814
|
+
createMvtTile_default as default
|
|
1815
|
+
};
|