@loaders.gl/mvt 4.4.0-alpha.1 → 4.4.0-alpha.9

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 (109) hide show
  1. package/README.md +14 -1
  2. package/dist/dist.dev.js +412 -39
  3. package/dist/dist.min.js +1 -1
  4. package/dist/index.cjs +414 -26
  5. package/dist/index.cjs.map +4 -4
  6. package/dist/index.d.ts +2 -0
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +3 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/lib/encode-mvt.d.ts +19 -0
  11. package/dist/lib/encode-mvt.d.ts.map +1 -0
  12. package/dist/lib/encode-mvt.js +15 -0
  13. package/dist/lib/encode-mvt.js.map +1 -0
  14. package/dist/lib/get-schemas-from-tilejson.js +1 -0
  15. package/dist/lib/get-schemas-from-tilejson.js.map +1 -0
  16. package/dist/lib/mapbox-vt-pbf/geojson-wrapper.d.ts +25 -0
  17. package/dist/lib/mapbox-vt-pbf/geojson-wrapper.d.ts.map +1 -0
  18. package/dist/lib/mapbox-vt-pbf/geojson-wrapper.js +73 -0
  19. package/dist/lib/mapbox-vt-pbf/geojson-wrapper.js.map +1 -0
  20. package/dist/lib/mapbox-vt-pbf/to-vector-tile.d.ts +52 -0
  21. package/dist/lib/mapbox-vt-pbf/to-vector-tile.d.ts.map +1 -0
  22. package/dist/lib/mapbox-vt-pbf/to-vector-tile.js +162 -0
  23. package/dist/lib/mapbox-vt-pbf/to-vector-tile.js.map +1 -0
  24. package/dist/lib/mvt-pbf/mvt-constants.d.ts.map +1 -0
  25. package/dist/lib/{pojo-parser → mvt-pbf}/mvt-constants.js +1 -0
  26. package/dist/lib/mvt-pbf/mvt-constants.js.map +1 -0
  27. package/dist/lib/mvt-pbf/mvt-types.d.ts.map +1 -0
  28. package/dist/lib/{pojo-parser → mvt-pbf}/mvt-types.js +1 -0
  29. package/dist/lib/mvt-pbf/mvt-types.js.map +1 -0
  30. package/dist/lib/mvt-pbf/parse-geometry-from-pbf.d.ts.map +1 -0
  31. package/dist/lib/{pojo-parser → mvt-pbf}/parse-geometry-from-pbf.js +1 -0
  32. package/dist/lib/mvt-pbf/parse-geometry-from-pbf.js.map +1 -0
  33. package/dist/lib/mvt-pbf/parse-mvt-from-pbf.d.ts.map +1 -0
  34. package/dist/lib/{pojo-parser → mvt-pbf}/parse-mvt-from-pbf.js +1 -0
  35. package/dist/lib/mvt-pbf/parse-mvt-from-pbf.js.map +1 -0
  36. package/dist/lib/mvt-pbf/write-mvt-to-pbf.d.ts +4 -0
  37. package/dist/lib/mvt-pbf/write-mvt-to-pbf.d.ts.map +1 -0
  38. package/dist/lib/mvt-pbf/write-mvt-to-pbf.js +130 -0
  39. package/dist/lib/mvt-pbf/write-mvt-to-pbf.js.map +1 -0
  40. package/dist/lib/parse-mvt.d.ts.map +1 -1
  41. package/dist/lib/parse-mvt.js +4 -1
  42. package/dist/lib/parse-mvt.js.map +1 -0
  43. package/dist/lib/parse-tilejson.js +1 -0
  44. package/dist/lib/parse-tilejson.js.map +1 -0
  45. package/dist/lib/types.js +1 -0
  46. package/dist/lib/types.js.map +1 -0
  47. package/dist/lib/utils/geometry-utils.js +1 -0
  48. package/dist/lib/utils/geometry-utils.js.map +1 -0
  49. package/dist/lib/vector-tile/vector-tile-feature.js +1 -0
  50. package/dist/lib/vector-tile/vector-tile-feature.js.map +1 -0
  51. package/dist/lib/vector-tile/vector-tile-layer.js +1 -0
  52. package/dist/lib/vector-tile/vector-tile-layer.js.map +1 -0
  53. package/dist/lib/vector-tile/vector-tile.js +1 -0
  54. package/dist/lib/vector-tile/vector-tile.js.map +1 -0
  55. package/dist/lib/vector-tiler/features/clip-features.js +1 -0
  56. package/dist/lib/vector-tiler/features/clip-features.js.map +1 -0
  57. package/dist/lib/vector-tiler/features/convert-feature.js +1 -0
  58. package/dist/lib/vector-tiler/features/convert-feature.js.map +1 -0
  59. package/dist/lib/vector-tiler/features/proto-feature.js +1 -0
  60. package/dist/lib/vector-tiler/features/proto-feature.js.map +1 -0
  61. package/dist/lib/vector-tiler/features/simplify-path.js +1 -0
  62. package/dist/lib/vector-tiler/features/simplify-path.js.map +1 -0
  63. package/dist/lib/vector-tiler/features/wrap-features.js +1 -0
  64. package/dist/lib/vector-tiler/features/wrap-features.js.map +1 -0
  65. package/dist/lib/vector-tiler/proto-tile.js +1 -0
  66. package/dist/lib/vector-tiler/proto-tile.js.map +1 -0
  67. package/dist/lib/vector-tiler/tile-to-geojson.js +1 -0
  68. package/dist/lib/vector-tiler/tile-to-geojson.js.map +1 -0
  69. package/dist/lib/vector-tiler/transform-tile.js +1 -0
  70. package/dist/lib/vector-tiler/transform-tile.js.map +1 -0
  71. package/dist/mvt-format.js +1 -0
  72. package/dist/mvt-format.js.map +1 -0
  73. package/dist/mvt-loader.js +2 -1
  74. package/dist/mvt-loader.js.map +1 -0
  75. package/dist/mvt-source.js +2 -1
  76. package/dist/mvt-source.js.map +1 -0
  77. package/dist/mvt-worker.js +6 -3
  78. package/dist/mvt-writer.d.ts +26 -0
  79. package/dist/mvt-writer.d.ts.map +1 -0
  80. package/dist/mvt-writer.js +32 -0
  81. package/dist/mvt-writer.js.map +1 -0
  82. package/dist/table-tile-source.js +1 -0
  83. package/dist/table-tile-source.js.map +1 -0
  84. package/dist/tilejson-loader.js +2 -1
  85. package/dist/tilejson-loader.js.map +1 -0
  86. package/dist/workers/mvt-worker.js +1 -0
  87. package/dist/workers/mvt-worker.js.map +1 -0
  88. package/package.json +7 -7
  89. package/src/index.ts +5 -0
  90. package/src/lib/encode-mvt.ts +31 -0
  91. package/src/lib/mapbox-vt-pbf/geojson-to-vt.ts.disabled +76 -0
  92. package/src/lib/mapbox-vt-pbf/geojson-wrapper.ts +89 -0
  93. package/src/lib/mapbox-vt-pbf/to-vector-tile.ts +229 -0
  94. package/src/lib/mvt-pbf/write-mvt-to-pbf.ts +158 -0
  95. package/src/lib/parse-mvt.ts +3 -1
  96. package/src/mvt-source.ts +1 -1
  97. package/src/mvt-writer.ts +35 -0
  98. package/dist/lib/pojo-parser/mvt-constants.d.ts.map +0 -1
  99. package/dist/lib/pojo-parser/mvt-types.d.ts.map +0 -1
  100. package/dist/lib/pojo-parser/parse-geometry-from-pbf.d.ts.map +0 -1
  101. package/dist/lib/pojo-parser/parse-mvt-from-pbf.d.ts.map +0 -1
  102. /package/dist/lib/{pojo-parser → mvt-pbf}/mvt-constants.d.ts +0 -0
  103. /package/dist/lib/{pojo-parser → mvt-pbf}/mvt-types.d.ts +0 -0
  104. /package/dist/lib/{pojo-parser → mvt-pbf}/parse-geometry-from-pbf.d.ts +0 -0
  105. /package/dist/lib/{pojo-parser → mvt-pbf}/parse-mvt-from-pbf.d.ts +0 -0
  106. /package/src/lib/{pojo-parser → mvt-pbf}/mvt-constants.ts +0 -0
  107. /package/src/lib/{pojo-parser → mvt-pbf}/mvt-types.ts +0 -0
  108. /package/src/lib/{pojo-parser → mvt-pbf}/parse-geometry-from-pbf.ts +0 -0
  109. /package/src/lib/{pojo-parser → mvt-pbf}/parse-mvt-from-pbf.ts +0 -0
package/dist/index.cjs CHANGED
@@ -38,6 +38,7 @@ __export(dist_exports, {
38
38
  MVTLoader: () => MVTLoader,
39
39
  MVTSource: () => MVTSource,
40
40
  MVTWorkerLoader: () => MVTWorkerLoader,
41
+ MVTWriter: () => MVTWriter,
41
42
  TableTileSource: () => TableTileSource,
42
43
  TileJSONLoader: () => TileJSONLoader
43
44
  });
@@ -302,7 +303,7 @@ function attributeTypeToFieldType(aType) {
302
303
  }
303
304
 
304
305
  // dist/tilejson-loader.js
305
- var VERSION = true ? "4.4.0-alpha.0" : "latest";
306
+ var VERSION = true ? "4.4.0-alpha.9" : "latest";
306
307
  var TileJSONLoader = {
307
308
  dataType: null,
308
309
  batchType: null,
@@ -996,7 +997,7 @@ var MVTFormat = {
996
997
  };
997
998
 
998
999
  // dist/mvt-loader.js
999
- var VERSION2 = true ? "4.4.0-alpha.0" : "latest";
1000
+ var VERSION2 = true ? "4.4.0-alpha.9" : "latest";
1000
1001
  var MVTWorkerLoader = {
1001
1002
  ...MVTFormat,
1002
1003
  dataType: null,
@@ -1020,8 +1021,395 @@ var MVTLoader = {
1020
1021
  binary: true
1021
1022
  };
1022
1023
 
1023
- // dist/mvt-source.js
1024
+ // dist/lib/mapbox-vt-pbf/to-vector-tile.js
1025
+ var import_pbf2 = __toESM(require("pbf"), 1);
1026
+
1027
+ // dist/lib/mvt-pbf/mvt-constants.js
1028
+ var TileInfo;
1029
+ (function(TileInfo2) {
1030
+ TileInfo2[TileInfo2["layers"] = 3] = "layers";
1031
+ })(TileInfo || (TileInfo = {}));
1032
+ var LayerInfo;
1033
+ (function(LayerInfo2) {
1034
+ LayerInfo2[LayerInfo2["version"] = 15] = "version";
1035
+ LayerInfo2[LayerInfo2["name"] = 1] = "name";
1036
+ LayerInfo2[LayerInfo2["features"] = 2] = "features";
1037
+ LayerInfo2[LayerInfo2["keys"] = 3] = "keys";
1038
+ LayerInfo2[LayerInfo2["values"] = 4] = "values";
1039
+ LayerInfo2[LayerInfo2["extent"] = 5] = "extent";
1040
+ })(LayerInfo || (LayerInfo = {}));
1041
+ var FeatureInfo;
1042
+ (function(FeatureInfo2) {
1043
+ FeatureInfo2[FeatureInfo2["id"] = 1] = "id";
1044
+ FeatureInfo2[FeatureInfo2["tags"] = 2] = "tags";
1045
+ FeatureInfo2[FeatureInfo2["type"] = 3] = "type";
1046
+ FeatureInfo2[FeatureInfo2["geometry"] = 4] = "geometry";
1047
+ })(FeatureInfo || (FeatureInfo = {}));
1048
+ var GeometryType;
1049
+ (function(GeometryType2) {
1050
+ GeometryType2[GeometryType2["UNKNOWN"] = 0] = "UNKNOWN";
1051
+ GeometryType2[GeometryType2["POINT"] = 1] = "POINT";
1052
+ GeometryType2[GeometryType2["LINESTRING"] = 2] = "LINESTRING";
1053
+ GeometryType2[GeometryType2["POLYGON"] = 3] = "POLYGON";
1054
+ })(GeometryType || (GeometryType = {}));
1055
+ var PropertyType;
1056
+ (function(PropertyType2) {
1057
+ PropertyType2[PropertyType2["string_value"] = 1] = "string_value";
1058
+ PropertyType2[PropertyType2["float_value"] = 2] = "float_value";
1059
+ PropertyType2[PropertyType2["double_value"] = 3] = "double_value";
1060
+ PropertyType2[PropertyType2["int_value"] = 4] = "int_value";
1061
+ PropertyType2[PropertyType2["uint_value"] = 5] = "uint_value";
1062
+ PropertyType2[PropertyType2["sint_value"] = 6] = "sint_value";
1063
+ PropertyType2[PropertyType2["bool_value"] = 7] = "bool_value";
1064
+ })(PropertyType || (PropertyType = {}));
1065
+ var Command;
1066
+ (function(Command2) {
1067
+ Command2[Command2["MoveTo"] = 1] = "MoveTo";
1068
+ Command2[Command2["LineTo"] = 2] = "LineTo";
1069
+ Command2[Command2["ClosePath"] = 7] = "ClosePath";
1070
+ })(Command || (Command = {}));
1071
+
1072
+ // dist/lib/mvt-pbf/write-mvt-to-pbf.js
1073
+ function writeMVT(tile, pbf) {
1074
+ for (const key in tile.layers) {
1075
+ const context = {
1076
+ layer: tile.layers[key],
1077
+ keys: [],
1078
+ values: [],
1079
+ keycache: {},
1080
+ valuecache: {}
1081
+ };
1082
+ pbf.writeMessage(TileInfo.layers, writeLayer, context);
1083
+ }
1084
+ }
1085
+ function writeLayer(context, pbf) {
1086
+ const { layer } = context;
1087
+ pbf.writeVarintField(LayerInfo.version, layer.version || 1);
1088
+ pbf.writeStringField(LayerInfo.name, layer.name || "");
1089
+ pbf.writeVarintField(LayerInfo.extent, layer.extent || 4096);
1090
+ for (let i = 0; i < layer.length; i++) {
1091
+ context.feature = layer.feature(i);
1092
+ pbf.writeMessage(LayerInfo.features, writeFeature, context);
1093
+ }
1094
+ const keys = context.keys;
1095
+ for (let i = 0; i < keys.length; i++) {
1096
+ pbf.writeStringField(LayerInfo.keys, keys[i]);
1097
+ }
1098
+ const values = context.values;
1099
+ for (let i = 0; i < values.length; i++) {
1100
+ pbf.writeMessage(LayerInfo.values, writeValue, values[i]);
1101
+ }
1102
+ }
1103
+ function writeFeature(context, pbf) {
1104
+ const feature = context.feature;
1105
+ if (feature.id !== void 0) {
1106
+ pbf.writeVarintField(FeatureInfo.id, feature.id);
1107
+ }
1108
+ pbf.writeMessage(FeatureInfo.tags, writeProperties, context);
1109
+ pbf.writeVarintField(FeatureInfo.type, feature.type);
1110
+ pbf.writeMessage(FeatureInfo.geometry, writeGeometry, feature);
1111
+ }
1112
+ function writeProperties(context, pbf) {
1113
+ const feature = context.feature;
1114
+ const { keys, values, keycache, valuecache } = context;
1115
+ for (const key in feature.properties) {
1116
+ let keyIndex = keycache[key];
1117
+ if (typeof keyIndex === "undefined") {
1118
+ keys.push(key);
1119
+ keyIndex = keys.length - 1;
1120
+ keycache[key] = keyIndex;
1121
+ }
1122
+ pbf.writeVarint(keyIndex);
1123
+ let value = feature.properties[key];
1124
+ const type = typeof value;
1125
+ if (type !== "string" && type !== "boolean" && type !== "number") {
1126
+ value = JSON.stringify(value);
1127
+ }
1128
+ const valueKey = `${type}:${value}`;
1129
+ let valueIndex = valuecache[valueKey];
1130
+ if (typeof valueIndex === "undefined") {
1131
+ values.push(value);
1132
+ valueIndex = values.length - 1;
1133
+ valuecache[valueKey] = valueIndex;
1134
+ }
1135
+ pbf.writeVarint(valueIndex);
1136
+ }
1137
+ }
1138
+ function command(cmd, length) {
1139
+ return (length << 3) + (cmd & 7);
1140
+ }
1141
+ function zigzag(num) {
1142
+ return num << 1 ^ num >> 31;
1143
+ }
1144
+ function writeGeometry(feature, pbf) {
1145
+ const geometry = feature.loadGeometry();
1146
+ const type = feature.type;
1147
+ let x = 0;
1148
+ let y = 0;
1149
+ const rings = geometry.length;
1150
+ for (let r = 0; r < rings; r++) {
1151
+ const ring = geometry[r];
1152
+ let count = 1;
1153
+ if (type === 1) {
1154
+ count = ring.length;
1155
+ }
1156
+ pbf.writeVarint(command(1, count));
1157
+ const lineCount = type === 3 ? ring.length - 1 : ring.length;
1158
+ for (let i = 0; i < lineCount; i++) {
1159
+ if (i === 1 && type !== 1) {
1160
+ pbf.writeVarint(command(2, lineCount - 1));
1161
+ }
1162
+ const dx = ring[i].x - x;
1163
+ const dy = ring[i].y - y;
1164
+ pbf.writeVarint(zigzag(dx));
1165
+ pbf.writeVarint(zigzag(dy));
1166
+ x += dx;
1167
+ y += dy;
1168
+ }
1169
+ if (type === 3) {
1170
+ pbf.writeVarint(command(7, 1));
1171
+ }
1172
+ }
1173
+ }
1174
+ function writeValue(value, pbf) {
1175
+ switch (typeof value) {
1176
+ case "string":
1177
+ pbf.writeStringField(1, value);
1178
+ break;
1179
+ case "boolean":
1180
+ pbf.writeBooleanField(7, value);
1181
+ break;
1182
+ case "number":
1183
+ if (value % 1 !== 0) {
1184
+ pbf.writeDoubleField(3, value);
1185
+ } else if (value < 0) {
1186
+ pbf.writeSVarintField(6, value);
1187
+ } else {
1188
+ pbf.writeVarintField(5, value);
1189
+ }
1190
+ break;
1191
+ default:
1192
+ }
1193
+ }
1194
+
1195
+ // dist/lib/mapbox-vt-pbf/geojson-wrapper.js
1196
+ var Point = class {
1197
+ x;
1198
+ y;
1199
+ constructor(x, y) {
1200
+ this.x = x;
1201
+ this.y = y;
1202
+ }
1203
+ };
1204
+ var GeoJSONWrapper = class {
1205
+ options;
1206
+ features;
1207
+ length;
1208
+ constructor(features2, options = {}) {
1209
+ this.options = options;
1210
+ this.features = features2;
1211
+ this.length = features2.length;
1212
+ }
1213
+ feature(index) {
1214
+ return new FeatureWrapper(this.features[index], this.options.extent);
1215
+ }
1216
+ };
1217
+ var FeatureWrapper = class {
1218
+ id;
1219
+ type;
1220
+ rawGeometry;
1221
+ properties;
1222
+ extent;
1223
+ geometry = [];
1224
+ constructor(feature, extent) {
1225
+ this.id = typeof feature.id === "number" ? feature.id : void 0;
1226
+ this.type = feature.type;
1227
+ this.rawGeometry = feature.type === 1 ? [feature.geometry] : feature.geometry;
1228
+ this.properties = feature.tags;
1229
+ this.extent = extent || 4096;
1230
+ }
1231
+ loadGeometry() {
1232
+ const rings = this.rawGeometry;
1233
+ this.geometry = [];
1234
+ for (const ring of rings) {
1235
+ const newRing = [];
1236
+ for (const coord of ring) {
1237
+ newRing.push(new Point(coord[0], coord[1]));
1238
+ }
1239
+ this.geometry.push(newRing);
1240
+ }
1241
+ return this.geometry;
1242
+ }
1243
+ bbox() {
1244
+ if (!this.geometry) {
1245
+ this.loadGeometry();
1246
+ }
1247
+ const rings = this.geometry;
1248
+ let x1 = Infinity;
1249
+ let x2 = -Infinity;
1250
+ let y1 = Infinity;
1251
+ let y2 = -Infinity;
1252
+ for (const ring of rings) {
1253
+ for (const coord of ring) {
1254
+ x1 = Math.min(x1, coord.x);
1255
+ x2 = Math.max(x2, coord.x);
1256
+ y1 = Math.min(y1, coord.y);
1257
+ y2 = Math.max(y2, coord.y);
1258
+ }
1259
+ }
1260
+ return [x1, y1, x2, y2];
1261
+ }
1262
+ };
1263
+
1264
+ // dist/lib/mapbox-vt-pbf/to-vector-tile.js
1024
1265
  var import_loader_utils2 = require("@loaders.gl/loader-utils");
1266
+ function fromGeojson(geojson, options) {
1267
+ options = options || {};
1268
+ geojson = normalizeGeojson(geojson);
1269
+ const extent = options.extent || 4096;
1270
+ const features2 = convertFeaturesToVectorTileFeatures(geojson.features, extent, options.tileIndex);
1271
+ const layer = new GeoJSONWrapper(features2, { ...options, extent });
1272
+ layer.name = options.layerName || "geojsonLayer";
1273
+ layer.version = options.version || 1;
1274
+ layer.extent = options.extent || 4096;
1275
+ return fromVectorTileJs({ layers: { [layer.name]: layer } });
1276
+ }
1277
+ function fromVectorTileJs(tile) {
1278
+ const pbf = new import_pbf2.default();
1279
+ writeMVT(tile, pbf);
1280
+ const uint8Array = pbf.finish();
1281
+ return (0, import_loader_utils2.copyToArrayBuffer)(uint8Array.buffer, uint8Array.byteOffset, uint8Array.byteOffset + uint8Array.byteLength);
1282
+ }
1283
+ function normalizeGeojson(geojson) {
1284
+ if (Array.isArray(geojson)) {
1285
+ return {
1286
+ type: "FeatureCollection",
1287
+ features: geojson
1288
+ };
1289
+ }
1290
+ if (geojson.type === "Feature") {
1291
+ return {
1292
+ type: "FeatureCollection",
1293
+ features: [geojson]
1294
+ };
1295
+ }
1296
+ throw new Error("Invalid GeoJSON object");
1297
+ }
1298
+ function convertFeaturesToVectorTileFeatures(features2, extent, tileIndex) {
1299
+ if (features2.every(isVectorTileFeature)) {
1300
+ return features2;
1301
+ }
1302
+ return features2.map((feature) => convertFeatureToVectorTile(feature, extent, tileIndex));
1303
+ }
1304
+ function convertFeatureToVectorTile(feature, extent, tileIndex) {
1305
+ const geometry = feature.geometry;
1306
+ const type = getVectorTileType(geometry.type);
1307
+ return {
1308
+ id: typeof feature.id === "number" ? feature.id : void 0,
1309
+ type,
1310
+ geometry: projectGeometryToTileSpace(geometry, extent, tileIndex),
1311
+ tags: feature.properties || {}
1312
+ };
1313
+ }
1314
+ function projectGeometryToTileSpace(geometry, extent, tileIndex) {
1315
+ switch (geometry.type) {
1316
+ case "Point":
1317
+ return [projectPointToTile(geometry.coordinates, extent, tileIndex)];
1318
+ case "MultiPoint":
1319
+ return geometry.coordinates.map((coord) => projectPointToTile(coord, extent, tileIndex));
1320
+ case "LineString":
1321
+ return [
1322
+ geometry.coordinates.map((coord) => projectPointToTile(coord, extent, tileIndex))
1323
+ ];
1324
+ case "MultiLineString":
1325
+ return geometry.coordinates.map((line) => line.map((coord) => projectPointToTile(coord, extent, tileIndex)));
1326
+ case "Polygon":
1327
+ return geometry.coordinates.map((ring) => ring.map((coord) => projectPointToTile(coord, extent, tileIndex)));
1328
+ case "MultiPolygon":
1329
+ return geometry.coordinates.flatMap((polygon) => polygon.map((ring) => ring.map((coord) => projectPointToTile(coord, extent, tileIndex))));
1330
+ default:
1331
+ throw new Error(`Unsupported geometry type: ${geometry.type}`);
1332
+ }
1333
+ }
1334
+ function projectPointToTile(point, extent, tileIndex) {
1335
+ if (isNormalizedPoint(point)) {
1336
+ return [Math.round(point[0] * extent), Math.round(point[1] * extent)];
1337
+ }
1338
+ if (tileIndex && isLngLatPoint(point)) {
1339
+ return projectLngLatToTile(point, tileIndex, extent);
1340
+ }
1341
+ return [Math.round(point[0]), Math.round(point[1])];
1342
+ }
1343
+ function isNormalizedPoint(point) {
1344
+ return Math.abs(point[0]) <= 1 && Math.abs(point[1]) <= 1;
1345
+ }
1346
+ function isLngLatPoint(point) {
1347
+ return Math.abs(point[0]) <= 180 && Math.abs(point[1]) <= 90;
1348
+ }
1349
+ function projectLngLatToTile(point, tileIndex, extent) {
1350
+ const [lng, lat] = point;
1351
+ const { x, y, z } = tileIndex;
1352
+ const size = extent * Math.pow(2, z);
1353
+ const x0 = extent * x;
1354
+ const y0 = extent * y;
1355
+ const worldX = (lng + 180) / 360 * size;
1356
+ const worldY = (180 - 180 / Math.PI * Math.log(Math.tan(Math.PI / 4 + lat * Math.PI / 180 / 2))) * size / 360;
1357
+ return [Math.round(worldX - x0), Math.round(worldY - y0)];
1358
+ }
1359
+ function isVectorTileFeature(feature) {
1360
+ return typeof (feature == null ? void 0 : feature.type) === "number" && Array.isArray(feature.geometry);
1361
+ }
1362
+ function getVectorTileType(type) {
1363
+ switch (type) {
1364
+ case "Point":
1365
+ case "MultiPoint":
1366
+ return 1;
1367
+ case "LineString":
1368
+ case "MultiLineString":
1369
+ return 2;
1370
+ case "Polygon":
1371
+ case "MultiPolygon":
1372
+ return 3;
1373
+ default:
1374
+ throw new Error(`Unknown geometry type: ${type}`);
1375
+ }
1376
+ }
1377
+
1378
+ // dist/lib/encode-mvt.js
1379
+ function encodeMVT(data, options) {
1380
+ const { mvt } = options || {};
1381
+ const encodeOptions = {
1382
+ layerName: (mvt == null ? void 0 : mvt.layerName) || "geojsonLayer",
1383
+ version: (mvt == null ? void 0 : mvt.version) || 1,
1384
+ extent: (mvt == null ? void 0 : mvt.extent) || 4096,
1385
+ tileIndex: mvt == null ? void 0 : mvt.tileIndex
1386
+ };
1387
+ return fromGeojson(data, encodeOptions);
1388
+ }
1389
+
1390
+ // dist/mvt-writer.js
1391
+ var VERSION3 = true ? "4.4.0-alpha.9" : "latest";
1392
+ var MVTWriter = {
1393
+ ...MVTFormat,
1394
+ version: VERSION3,
1395
+ binary: true,
1396
+ options: {
1397
+ mvt: {
1398
+ layerName: "geojsonLayer",
1399
+ version: 1,
1400
+ extent: 4096
1401
+ }
1402
+ },
1403
+ async encode(data, options) {
1404
+ return encodeMVT(data, options);
1405
+ },
1406
+ encodeSync(data, options) {
1407
+ return encodeMVT(data, options);
1408
+ }
1409
+ };
1410
+
1411
+ // dist/mvt-source.js
1412
+ var import_loader_utils3 = require("@loaders.gl/loader-utils");
1025
1413
  var import_images = require("@loaders.gl/images");
1026
1414
  var import_mvt = require("@loaders.gl/mvt");
1027
1415
  var MVTSource = {
@@ -1040,7 +1428,7 @@ var MVTSource = {
1040
1428
  return new MVTTileSource(url, options);
1041
1429
  }
1042
1430
  };
1043
- var MVTTileSource = class extends import_loader_utils2.DataSource {
1431
+ var MVTTileSource = class extends import_loader_utils3.DataSource {
1044
1432
  metadataUrl = null;
1045
1433
  schema = "tms";
1046
1434
  metadata;
@@ -1124,8 +1512,8 @@ var MVTTileSource = class extends import_loader_utils2.DataSource {
1124
1512
  async _parseVectorTile(arrayBuffer, tileParams) {
1125
1513
  var _a;
1126
1514
  const loadOptions = {
1127
- shape: "geojson-table",
1128
1515
  mvt: {
1516
+ shape: "geojson-table",
1129
1517
  coordinates: "wgs84",
1130
1518
  tileIndex: { x: tileParams.x, y: tileParams.y, z: tileParams.z },
1131
1519
  ...(_a = this.loadOptions) == null ? void 0 : _a.mvt
@@ -1175,7 +1563,7 @@ function stringHash(s) {
1175
1563
  }
1176
1564
 
1177
1565
  // dist/table-tile-source.js
1178
- var import_loader_utils3 = require("@loaders.gl/loader-utils");
1566
+ var import_loader_utils4 = require("@loaders.gl/loader-utils");
1179
1567
  var import_schema_utils = require("@loaders.gl/schema-utils");
1180
1568
  var import_stats = require("@probe.gl/stats");
1181
1569
 
@@ -1894,7 +2282,7 @@ var TableTileSource = {
1894
2282
  return new TableVectorTileSource(tablePromise, options);
1895
2283
  }
1896
2284
  };
1897
- var _TableVectorTileSource = class extends import_loader_utils3.DataSource {
2285
+ var _TableVectorTileSource = class extends import_loader_utils4.DataSource {
1898
2286
  /** Stats for this TableVectorTileSource */
1899
2287
  stats = new import_stats.Stats({
1900
2288
  id: "table-tile-source",
@@ -1916,7 +2304,7 @@ var _TableVectorTileSource = class extends import_loader_utils3.DataSource {
1916
2304
  metadata;
1917
2305
  constructor(table, options) {
1918
2306
  super(table, options, TableTileSource.defaultOptions);
1919
- this.tableOptions = (0, import_loader_utils3.getRequiredOptions)(this.options).table;
2307
+ this.tableOptions = (0, import_loader_utils4.getRequiredOptions)(this.options).table;
1920
2308
  this.getTileData = this.getTileData.bind(this);
1921
2309
  this.ready = this.initializeTilesAsync(table);
1922
2310
  this.metadata = this.getMetadata();
@@ -1942,7 +2330,7 @@ var _TableVectorTileSource = class extends import_loader_utils3.DataSource {
1942
2330
  async getVectorTile(tileIndex) {
1943
2331
  await this.ready;
1944
2332
  const table = this.getTileSync(tileIndex);
1945
- import_loader_utils3.log.info(2, "getVectorTile", tileIndex, table)();
2333
+ import_loader_utils4.log.info(2, "getVectorTile", tileIndex, table)();
1946
2334
  return table;
1947
2335
  }
1948
2336
  async getTile(tileIndex) {
@@ -1981,21 +2369,21 @@ var _TableVectorTileSource = class extends import_loader_utils3.DataSource {
1981
2369
  if (this.tableOptions.promoteId && this.tableOptions.generateId) {
1982
2370
  throw new Error("promoteId and generateId cannot be used together.");
1983
2371
  }
1984
- import_loader_utils3.log.log(1, "TableVectorTileSource creating root tiles", this.tableOptions)();
1985
- import_loader_utils3.log.time(1, "preprocess table")();
2372
+ import_loader_utils4.log.log(1, "TableVectorTileSource creating root tiles", this.tableOptions)();
2373
+ import_loader_utils4.log.time(1, "preprocess table")();
1986
2374
  let features2 = convertFeaturesToProtoFeature(table, this.tableOptions);
1987
- import_loader_utils3.log.timeEnd(1, "preprocess table")();
1988
- import_loader_utils3.log.time(1, "generate tiles")();
2375
+ import_loader_utils4.log.timeEnd(1, "preprocess table")();
2376
+ import_loader_utils4.log.time(1, "generate tiles")();
1989
2377
  features2 = wrapFeatures(features2, this.tableOptions);
1990
2378
  if (features2.length === 0) {
1991
- import_loader_utils3.log.log(1, "TableVectorTileSource: no features generated")();
2379
+ import_loader_utils4.log.log(1, "TableVectorTileSource: no features generated")();
1992
2380
  return;
1993
2381
  }
1994
2382
  this.splitTile(features2, 0, 0, 0);
1995
2383
  const rootTile = this.tiles[0];
1996
- import_loader_utils3.log.log(1, `root tile features: ${rootTile.numFeatures}, points: ${rootTile.numPoints}`)();
1997
- import_loader_utils3.log.timeEnd(1, "generate tiles")();
1998
- import_loader_utils3.log.log(1, `TableVectorTileSource: tiles generated: ${this.stats.get("total").count}`, this.stats)();
2384
+ import_loader_utils4.log.log(1, `root tile features: ${rootTile.numFeatures}, points: ${rootTile.numPoints}`)();
2385
+ import_loader_utils4.log.timeEnd(1, "generate tiles")();
2386
+ import_loader_utils4.log.log(1, `TableVectorTileSource: tiles generated: ${this.stats.get("total").count}`, this.stats)();
1999
2387
  }
2000
2388
  /**
2001
2389
  * Return geojsonvt-style "half formed" vector tile
@@ -2015,7 +2403,7 @@ var _TableVectorTileSource = class extends import_loader_utils3.DataSource {
2015
2403
  if (this.tiles[id]) {
2016
2404
  return transformTile(this.tiles[id], extent);
2017
2405
  }
2018
- import_loader_utils3.log.log(import_loader_utils3.log, "drilling down to z%d-%d-%d", z, x, y)();
2406
+ import_loader_utils4.log.log(import_loader_utils4.log, "drilling down to z%d-%d-%d", z, x, y)();
2019
2407
  let z0 = z;
2020
2408
  let x0 = x;
2021
2409
  let y0 = y;
@@ -2029,10 +2417,10 @@ var _TableVectorTileSource = class extends import_loader_utils3.DataSource {
2029
2417
  if (!parent || !parent.sourceFeatures) {
2030
2418
  return null;
2031
2419
  }
2032
- import_loader_utils3.log.log(1, "found parent tile z%d-%d-%d", z0, x0, y0)();
2033
- import_loader_utils3.log.time(1, "drilling down")();
2420
+ import_loader_utils4.log.log(1, "found parent tile z%d-%d-%d", z0, x0, y0)();
2421
+ import_loader_utils4.log.time(1, "drilling down")();
2034
2422
  this.splitTile(parent.sourceFeatures, z0, x0, y0, z, x, y);
2035
- import_loader_utils3.log.timeEnd(1, "drilling down")();
2423
+ import_loader_utils4.log.timeEnd(1, "drilling down")();
2036
2424
  return this.tiles[id] ? transformTile(this.tiles[id], extent) : null;
2037
2425
  }
2038
2426
  /**
@@ -2055,7 +2443,7 @@ var _TableVectorTileSource = class extends import_loader_utils3.DataSource {
2055
2443
  const id = toID(z, x, y);
2056
2444
  let tile = this.tiles[id];
2057
2445
  if (!tile) {
2058
- import_loader_utils3.log.time(2, "tile creation")();
2446
+ import_loader_utils4.log.time(2, "tile creation")();
2059
2447
  tile = this.tiles[id] = createProtoTile(features2, z, x, y, this.tableOptions);
2060
2448
  this.tileCoords.push({ z, x, y });
2061
2449
  const key = `z${z}`;
@@ -2067,8 +2455,8 @@ var _TableVectorTileSource = class extends import_loader_utils3.DataSource {
2067
2455
  stat.incrementCount();
2068
2456
  stat = _TableVectorTileSource.stats.get("total");
2069
2457
  stat.incrementCount();
2070
- import_loader_utils3.log.log(2, "tile z%d-%d-%d (features: %d, points: %d, simplified: %d)", z, x, y, tile.numFeatures, tile.numPoints, tile.numSimplified)();
2071
- import_loader_utils3.log.timeEnd(2, "tile creation")();
2458
+ import_loader_utils4.log.log(2, "tile z%d-%d-%d (features: %d, points: %d, simplified: %d)", z, x, y, tile.numFeatures, tile.numPoints, tile.numSimplified)();
2459
+ import_loader_utils4.log.timeEnd(2, "tile creation")();
2072
2460
  }
2073
2461
  tile.sourceFeatures = features2;
2074
2462
  if (cz === void 0) {
@@ -2086,7 +2474,7 @@ var _TableVectorTileSource = class extends import_loader_utils3.DataSource {
2086
2474
  tile.sourceFeatures = null;
2087
2475
  if (features2.length === 0)
2088
2476
  continue;
2089
- import_loader_utils3.log.time(2, "clipping tile")();
2477
+ import_loader_utils4.log.time(2, "clipping tile")();
2090
2478
  const k1 = 0.5 * this.tableOptions.buffer / this.tableOptions.extent;
2091
2479
  const k2 = 0.5 - k1;
2092
2480
  const k3 = 0.5 + k1;
@@ -2108,7 +2496,7 @@ var _TableVectorTileSource = class extends import_loader_utils3.DataSource {
2108
2496
  br = clipFeatures(right, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, this.tableOptions);
2109
2497
  right = null;
2110
2498
  }
2111
- import_loader_utils3.log.timeEnd(2, "clipping tile")();
2499
+ import_loader_utils4.log.timeEnd(2, "clipping tile")();
2112
2500
  stack.push(tl || [], z + 1, x * 2, y * 2);
2113
2501
  stack.push(bl || [], z + 1, x * 2, y * 2 + 1);
2114
2502
  stack.push(tr || [], z + 1, x * 2 + 1, y * 2);