@loaders.gl/mvt 4.0.0-beta.2 → 4.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{dist.min.js → dist.dev.js} +2258 -1731
- package/dist/helpers/binary-util-functions.js.map +1 -0
- package/dist/helpers/mapbox-util-functions.js.map +1 -0
- package/dist/index.cjs +1800 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/{esm/lib → lib}/binary-vector-tile/vector-tile-feature.js +12 -13
- package/dist/lib/binary-vector-tile/vector-tile-feature.js.map +1 -0
- package/dist/{esm/lib → lib}/binary-vector-tile/vector-tile-layer.js +9 -10
- package/dist/lib/binary-vector-tile/vector-tile-layer.js.map +1 -0
- package/dist/{esm/lib/mapbox-vector-tile → lib/binary-vector-tile}/vector-tile.js +2 -3
- package/dist/lib/binary-vector-tile/vector-tile.js.map +1 -0
- package/dist/{esm/lib → lib}/geojson-tiler/clip.js +4 -5
- package/dist/lib/geojson-tiler/clip.js.map +1 -0
- package/dist/{esm/lib → lib}/geojson-tiler/convert.js +2 -2
- package/dist/lib/geojson-tiler/convert.js.map +1 -0
- package/dist/lib/geojson-tiler/feature.js.map +1 -0
- package/dist/{esm/lib → lib}/geojson-tiler/geojson-tiler.js +11 -12
- package/dist/lib/geojson-tiler/geojson-tiler.js.map +1 -0
- package/dist/lib/geojson-tiler/simplify.js.map +1 -0
- package/dist/lib/geojson-tiler/tile.js.map +1 -0
- package/dist/lib/geojson-tiler/transform.js.map +1 -0
- package/dist/{esm/lib → lib}/geojson-tiler/wrap.js +5 -6
- package/dist/lib/geojson-tiler/wrap.js.map +1 -0
- package/dist/{esm/lib → lib}/mapbox-vector-tile/vector-tile-feature.js +12 -13
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -0
- package/dist/{esm/lib → lib}/mapbox-vector-tile/vector-tile-layer.js +9 -10
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -0
- package/dist/{esm/lib/binary-vector-tile → lib/mapbox-vector-tile}/vector-tile.js +2 -3
- package/dist/lib/mapbox-vector-tile/vector-tile.js.map +1 -0
- package/dist/{esm/lib → lib}/parse-mvt.js +2 -2
- package/dist/lib/parse-mvt.js.map +1 -0
- package/dist/lib/parse-tilejson.js.map +1 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/{esm/mvt-loader.js → mvt-loader.js} +2 -2
- package/dist/mvt-loader.js.map +1 -0
- package/dist/mvt-source.d.ts +28 -0
- package/dist/mvt-source.d.ts.map +1 -0
- package/dist/mvt-source.js +100 -0
- package/dist/mvt-source.js.map +1 -0
- package/dist/mvt-worker.js +267 -103
- package/dist/{esm/tilejson-loader.js → tilejson-loader.js} +2 -2
- package/dist/tilejson-loader.js.map +1 -0
- package/dist/{esm/workers → workers}/mvt-worker.js +1 -1
- package/dist/workers/mvt-worker.js.map +1 -0
- package/package.json +19 -10
- package/src/index.ts +2 -0
- package/src/mvt-source.ts +110 -0
- package/dist/bundle.d.ts +0 -2
- package/dist/bundle.d.ts.map +0 -1
- package/dist/es5/bundle.js +0 -6
- package/dist/es5/bundle.js.map +0 -1
- package/dist/es5/helpers/binary-util-functions.js +0 -82
- package/dist/es5/helpers/binary-util-functions.js.map +0 -1
- package/dist/es5/helpers/mapbox-util-functions.js +0 -50
- package/dist/es5/helpers/mapbox-util-functions.js.map +0 -1
- package/dist/es5/index.js +0 -33
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js +0 -168
- package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js.map +0 -1
- package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js +0 -62
- package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js.map +0 -1
- package/dist/es5/lib/binary-vector-tile/vector-tile.js +0 -28
- package/dist/es5/lib/binary-vector-tile/vector-tile.js.map +0 -1
- package/dist/es5/lib/geojson-tiler/clip.js +0 -237
- package/dist/es5/lib/geojson-tiler/clip.js.map +0 -1
- package/dist/es5/lib/geojson-tiler/convert.js +0 -161
- package/dist/es5/lib/geojson-tiler/convert.js.map +0 -1
- package/dist/es5/lib/geojson-tiler/feature.js +0 -62
- package/dist/es5/lib/geojson-tiler/feature.js.map +0 -1
- package/dist/es5/lib/geojson-tiler/geojson-tiler.js +0 -186
- package/dist/es5/lib/geojson-tiler/geojson-tiler.js.map +0 -1
- package/dist/es5/lib/geojson-tiler/simplify.js +0 -52
- package/dist/es5/lib/geojson-tiler/simplify.js.map +0 -1
- package/dist/es5/lib/geojson-tiler/tile.js +0 -121
- package/dist/es5/lib/geojson-tiler/tile.js.map +0 -1
- package/dist/es5/lib/geojson-tiler/transform.js +0 -50
- package/dist/es5/lib/geojson-tiler/transform.js.map +0 -1
- package/dist/es5/lib/geojson-tiler/wrap.js +0 -122
- package/dist/es5/lib/geojson-tiler/wrap.js.map +0 -1
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js +0 -184
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js.map +0 -1
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js +0 -62
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js.map +0 -1
- package/dist/es5/lib/mapbox-vector-tile/vector-tile.js +0 -28
- package/dist/es5/lib/mapbox-vector-tile/vector-tile.js.map +0 -1
- package/dist/es5/lib/parse-mvt.js +0 -144
- package/dist/es5/lib/parse-mvt.js.map +0 -1
- package/dist/es5/lib/parse-tilejson.js +0 -186
- package/dist/es5/lib/parse-tilejson.js.map +0 -1
- package/dist/es5/lib/types.js +0 -2
- package/dist/es5/lib/types.js.map +0 -1
- package/dist/es5/mvt-loader.js +0 -57
- package/dist/es5/mvt-loader.js.map +0 -1
- package/dist/es5/tilejson-loader.js +0 -50
- package/dist/es5/tilejson-loader.js.map +0 -1
- package/dist/es5/workers/mvt-worker.js +0 -6
- package/dist/es5/workers/mvt-worker.js.map +0 -1
- package/dist/esm/bundle.js +0 -4
- package/dist/esm/bundle.js.map +0 -1
- package/dist/esm/helpers/binary-util-functions.js.map +0 -1
- package/dist/esm/helpers/mapbox-util-functions.js.map +0 -1
- package/dist/esm/index.js +0 -4
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/lib/binary-vector-tile/LICENSE.txt +0 -31
- package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js.map +0 -1
- package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js.map +0 -1
- package/dist/esm/lib/binary-vector-tile/vector-tile.js.map +0 -1
- package/dist/esm/lib/geojson-tiler/LICENSE +0 -19
- package/dist/esm/lib/geojson-tiler/clip.js.map +0 -1
- package/dist/esm/lib/geojson-tiler/convert.js.map +0 -1
- package/dist/esm/lib/geojson-tiler/feature.js.map +0 -1
- package/dist/esm/lib/geojson-tiler/geojson-tiler.js.map +0 -1
- package/dist/esm/lib/geojson-tiler/simplify.js.map +0 -1
- package/dist/esm/lib/geojson-tiler/tile.js.map +0 -1
- package/dist/esm/lib/geojson-tiler/transform.js.map +0 -1
- package/dist/esm/lib/geojson-tiler/wrap.js.map +0 -1
- package/dist/esm/lib/mapbox-vector-tile/LICENSE.txt +0 -31
- package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js.map +0 -1
- package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js.map +0 -1
- package/dist/esm/lib/mapbox-vector-tile/vector-tile.js.map +0 -1
- package/dist/esm/lib/parse-mvt.js.map +0 -1
- package/dist/esm/lib/parse-tilejson.js.map +0 -1
- package/dist/esm/lib/types.js.map +0 -1
- package/dist/esm/mvt-loader.js.map +0 -1
- package/dist/esm/tilejson-loader.js.map +0 -1
- package/dist/esm/workers/mvt-worker.js.map +0 -1
- package/src/bundle.ts +0 -4
- /package/dist/{esm/helpers → helpers}/binary-util-functions.js +0 -0
- /package/dist/{esm/helpers → helpers}/mapbox-util-functions.js +0 -0
- /package/dist/{es5/lib → lib}/binary-vector-tile/LICENSE.txt +0 -0
- /package/dist/{es5/lib → lib}/geojson-tiler/LICENSE +0 -0
- /package/dist/{esm/lib → lib}/geojson-tiler/feature.js +0 -0
- /package/dist/{esm/lib → lib}/geojson-tiler/simplify.js +0 -0
- /package/dist/{esm/lib → lib}/geojson-tiler/tile.js +0 -0
- /package/dist/{esm/lib → lib}/geojson-tiler/transform.js +0 -0
- /package/dist/{es5/lib → lib}/mapbox-vector-tile/LICENSE.txt +0 -0
- /package/dist/{esm/lib → lib}/parse-tilejson.js +0 -0
- /package/dist/{esm/lib → lib}/types.js +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector-tile.js","names":["VectorTileLayer","VectorTile","constructor","pbf","end","layers","readFields","readTile","tag","layer","readVarint","pos","length","name"],"sources":["../../../src/lib/mapbox-vector-tile/vector-tile.ts"],"sourcesContent":["// This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.\n\nimport VectorTileLayer from './vector-tile-layer';\nimport Protobuf from 'pbf';\n\nexport default class VectorTile {\n layers: {[x: string]: VectorTileLayer};\n constructor(pbf: Protobuf, end?: number) {\n this.layers = pbf.readFields(readTile, {}, end);\n }\n}\n\n/**\n *\n * @param tag\n * @param layers\n * @param pbf\n */\nfunction readTile(tag: number, layers?: {[x: string]: VectorTileLayer}, pbf?: Protobuf): void {\n if (tag === 3) {\n if (pbf) {\n const layer = new VectorTileLayer(pbf, pbf.readVarint() + pbf.pos);\n if (layer.length && layers) {\n layers[layer.name] = layer;\n }\n }\n }\n}\n"],"mappings":"OAEOA,eAAe;AAGtB,eAAe,MAAMC,UAAU,CAAC;EAE9BC,WAAWA,CAACC,GAAa,EAAEC,GAAY,EAAE;IAAA,KADzCC,MAAM;IAEJ,IAAI,CAACA,MAAM,GAAGF,GAAG,CAACG,UAAU,CAACC,QAAQ,EAAE,CAAC,CAAC,EAAEH,GAAG,CAAC;EACjD;AACF;AAQA,SAASG,QAAQA,CAACC,GAAW,EAAEH,MAAuC,EAAEF,GAAc,EAAQ;EAC5F,IAAIK,GAAG,KAAK,CAAC,EAAE;IACb,IAAIL,GAAG,EAAE;MACP,MAAMM,KAAK,GAAG,IAAIT,eAAe,CAACG,GAAG,EAAEA,GAAG,CAACO,UAAU,CAAC,CAAC,GAAGP,GAAG,CAACQ,GAAG,CAAC;MAClE,IAAIF,KAAK,CAACG,MAAM,IAAIP,MAAM,EAAE;QAC1BA,MAAM,CAACI,KAAK,CAACI,IAAI,CAAC,GAAGJ,KAAK;MAC5B;IACF;EACF;AACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { flatGeojsonToBinary } from '@loaders.gl/gis';
|
|
2
2
|
import Protobuf from 'pbf';
|
|
3
|
-
import VectorTile from
|
|
4
|
-
import BinaryVectorTile from
|
|
3
|
+
import VectorTile from "./mapbox-vector-tile/vector-tile.js";
|
|
4
|
+
import BinaryVectorTile from "./binary-vector-tile/vector-tile.js";
|
|
5
5
|
export default function parseMVT(arrayBuffer, options) {
|
|
6
6
|
var _options$gis, _options$mvt;
|
|
7
7
|
const mvtOptions = normalizeOptions(options);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-mvt.js","names":["flatGeojsonToBinary","Protobuf","VectorTile","BinaryVectorTile","parseMVT","arrayBuffer","options","_options$gis","_options$mvt","mvtOptions","normalizeOptions","shape","gis","format","mvt","data","parseToBinary","table","type","features","parseToGeojsonFeatures","Error","flatGeoJsonFeatures","geometryInfo","parseToFlatGeoJson","binaryData","byteLength","coordLength","pointPositionsCount","pointFeaturesCount","linePositionsCount","linePathsCount","lineFeaturesCount","polygonPositionsCount","polygonObjectsCount","polygonRingsCount","polygonFeaturesCount","tile","selectedLayers","Array","isArray","layers","Object","keys","forEach","layerName","vectorTileLayer","i","length","vectorTileFeature","feature","decodedFeature","getDecodedFeatureBinary","push","getDecodedFeature","_options$mvt2","wgs84Coordinates","coordinates","tileIndex","hasTileIndex","Number","isFinite","x","y","z","toGeoJSON","transformToLocalCoordinates","layerProperty","properties","toBinaryCoordinates","transformToLocalCoordinatesBinary","line","extent","p","il"],"sources":["../../src/lib/parse-mvt.ts"],"sourcesContent":["import {flatGeojsonToBinary} from '@loaders.gl/gis';\nimport type {\n FlatFeature,\n Feature,\n GeojsonGeometryInfo,\n BinaryFeatureCollection,\n GeoJSONTable\n} from '@loaders.gl/schema';\nimport Protobuf from 'pbf';\n\nimport type {MVTMapboxCoordinates, MVTOptions, MVTLoaderOptions} from '../lib/types';\n\nimport VectorTile from './mapbox-vector-tile/vector-tile';\nimport BinaryVectorTile from './binary-vector-tile/vector-tile';\nimport VectorTileFeatureBinary from './binary-vector-tile/vector-tile-feature';\nimport VectorTileFeatureMapBox from './mapbox-vector-tile/vector-tile-feature';\n\n/**\n * Parse MVT arrayBuffer and return GeoJSON.\n *\n * @param arrayBuffer A MVT arrayBuffer\n * @param options\n * @returns A GeoJSON geometry object or a binary representation\n */\nexport default function parseMVT(arrayBuffer: ArrayBuffer, options?: MVTLoaderOptions) {\n const mvtOptions = normalizeOptions(options);\n\n const shape: string | undefined =\n options?.gis?.format || options?.mvt?.shape || (options?.shape as string);\n switch (shape) {\n case 'columnar-table': // binary + some JS arrays\n return {shape: 'columnar-table', data: parseToBinary(arrayBuffer, mvtOptions)};\n case 'geojson-table': {\n const table: GeoJSONTable = {\n shape: 'geojson-table',\n type: 'FeatureCollection',\n features: parseToGeojsonFeatures(arrayBuffer, mvtOptions)\n };\n return table;\n }\n case 'geojson':\n return parseToGeojsonFeatures(arrayBuffer, mvtOptions);\n case 'binary-geometry':\n return parseToBinary(arrayBuffer, mvtOptions);\n case 'binary':\n return parseToBinary(arrayBuffer, mvtOptions);\n default:\n throw new Error(shape || 'undefined shape');\n }\n}\n\nfunction parseToBinary(arrayBuffer: ArrayBuffer, options: MVTOptions): BinaryFeatureCollection {\n const [flatGeoJsonFeatures, geometryInfo] = parseToFlatGeoJson(arrayBuffer, options);\n\n const binaryData = flatGeojsonToBinary(flatGeoJsonFeatures, geometryInfo);\n // Add the original byteLength (as a reasonable approximation of the size of the binary data)\n // TODO decide where to store extra fields like byteLength (header etc) and document\n // @ts-ignore\n binaryData.byteLength = arrayBuffer.byteLength;\n return binaryData;\n}\n\nfunction parseToFlatGeoJson(\n arrayBuffer: ArrayBuffer,\n options: MVTOptions\n): [FlatFeature[], GeojsonGeometryInfo] {\n const features: FlatFeature[] = [];\n const geometryInfo: GeojsonGeometryInfo = {\n coordLength: 2,\n pointPositionsCount: 0,\n pointFeaturesCount: 0,\n linePositionsCount: 0,\n linePathsCount: 0,\n lineFeaturesCount: 0,\n polygonPositionsCount: 0,\n polygonObjectsCount: 0,\n polygonRingsCount: 0,\n polygonFeaturesCount: 0\n };\n\n if (arrayBuffer.byteLength <= 0) {\n return [features, geometryInfo];\n }\n\n const tile = new BinaryVectorTile(new Protobuf(arrayBuffer));\n\n const selectedLayers =\n options && Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);\n\n selectedLayers.forEach((layerName: string) => {\n const vectorTileLayer = tile.layers[layerName];\n if (!vectorTileLayer) {\n return;\n }\n\n for (let i = 0; i < vectorTileLayer.length; i++) {\n const vectorTileFeature = vectorTileLayer.feature(i, geometryInfo);\n const decodedFeature = getDecodedFeatureBinary(vectorTileFeature, options, layerName);\n features.push(decodedFeature);\n }\n });\n\n return [features, geometryInfo];\n}\n\nfunction parseToGeojsonFeatures(arrayBuffer: ArrayBuffer, options: MVTOptions): Feature[] {\n if (arrayBuffer.byteLength <= 0) {\n return [];\n }\n\n const features: MVTMapboxCoordinates[] = [];\n const tile = new VectorTile(new Protobuf(arrayBuffer));\n\n const selectedLayers = Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);\n\n selectedLayers.forEach((layerName: string) => {\n const vectorTileLayer = tile.layers[layerName];\n if (!vectorTileLayer) {\n return;\n }\n\n for (let i = 0; i < vectorTileLayer.length; i++) {\n const vectorTileFeature = vectorTileLayer.feature(i);\n const decodedFeature = getDecodedFeature(vectorTileFeature, options, layerName);\n features.push(decodedFeature);\n }\n });\n\n return features as Feature[];\n}\n\nfunction normalizeOptions(options?: MVTLoaderOptions): MVTOptions {\n if (!options?.mvt) {\n throw new Error('mvt options required');\n }\n\n // Validate\n const wgs84Coordinates = options.mvt?.coordinates === 'wgs84';\n const {tileIndex} = options.mvt;\n const hasTileIndex =\n tileIndex &&\n Number.isFinite(tileIndex.x) &&\n Number.isFinite(tileIndex.y) &&\n Number.isFinite(tileIndex.z);\n\n if (wgs84Coordinates && !hasTileIndex) {\n throw new Error('MVT Loader: WGS84 coordinates need tileIndex property');\n }\n\n return options.mvt;\n}\n\n/**\n * @param feature\n * @param options\n * @returns decoded feature\n */\nfunction getDecodedFeature(\n feature: VectorTileFeatureMapBox,\n options: MVTOptions,\n layerName: string\n): MVTMapboxCoordinates {\n const decodedFeature = feature.toGeoJSON(\n // @ts-expect-error What is going on here?\n options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinates\n );\n\n // Add layer name to GeoJSON properties\n if (options.layerProperty) {\n decodedFeature.properties[options.layerProperty] = layerName;\n }\n\n return decodedFeature;\n}\n\n/**\n * @param feature\n * @param options\n * @returns decoded binary feature\n */\nfunction getDecodedFeatureBinary(\n feature: VectorTileFeatureBinary,\n options: MVTOptions,\n layerName: string\n): FlatFeature {\n const decodedFeature = feature.toBinaryCoordinates(\n // @ts-expect-error What is going on here?\n options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinatesBinary\n );\n\n // Add layer name to GeoJSON properties\n if (options.layerProperty && decodedFeature.properties) {\n decodedFeature.properties[options.layerProperty] = layerName;\n }\n\n return decodedFeature;\n}\n\n/**\n * @param line\n * @param feature\n */\nfunction transformToLocalCoordinates(line: number[], feature: {extent: any}): void {\n // This function transforms local coordinates in a\n // [0 - bufferSize, this.extent + bufferSize] range to a\n // [0 - (bufferSize / this.extent), 1 + (bufferSize / this.extent)] range.\n // The resulting extent would be 1.\n const {extent} = feature;\n for (let i = 0; i < line.length; i++) {\n const p = line[i];\n p[0] /= extent;\n p[1] /= extent;\n }\n}\n\nfunction transformToLocalCoordinatesBinary(data: number[], feature: {extent: any}) {\n // For the binary code path, the feature data is just\n // one big flat array, so we just divide each value\n const {extent} = feature;\n for (let i = 0, il = data.length; i < il; ++i) {\n data[i] /= extent;\n }\n}\n"],"mappings":"AAAA,SAAQA,mBAAmB,QAAO,iBAAiB;AAQnD,OAAOC,QAAQ,MAAM,KAAK;AAAC,OAIpBC,UAAU;AAAA,OACVC,gBAAgB;AAWvB,eAAe,SAASC,QAAQA,CAACC,WAAwB,EAAEC,OAA0B,EAAE;EAAA,IAAAC,YAAA,EAAAC,YAAA;EACrF,MAAMC,UAAU,GAAGC,gBAAgB,CAACJ,OAAO,CAAC;EAE5C,MAAMK,KAAyB,GAC7B,CAAAL,OAAO,aAAPA,OAAO,wBAAAC,YAAA,GAAPD,OAAO,CAAEM,GAAG,cAAAL,YAAA,uBAAZA,YAAA,CAAcM,MAAM,MAAIP,OAAO,aAAPA,OAAO,wBAAAE,YAAA,GAAPF,OAAO,CAAEQ,GAAG,cAAAN,YAAA,uBAAZA,YAAA,CAAcG,KAAK,MAAKL,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEK,KAAK,CAAW;EAC3E,QAAQA,KAAK;IACX,KAAK,gBAAgB;MACnB,OAAO;QAACA,KAAK,EAAE,gBAAgB;QAAEI,IAAI,EAAEC,aAAa,CAACX,WAAW,EAAEI,UAAU;MAAC,CAAC;IAChF,KAAK,eAAe;MAAE;QACpB,MAAMQ,KAAmB,GAAG;UAC1BN,KAAK,EAAE,eAAe;UACtBO,IAAI,EAAE,mBAAmB;UACzBC,QAAQ,EAAEC,sBAAsB,CAACf,WAAW,EAAEI,UAAU;QAC1D,CAAC;QACD,OAAOQ,KAAK;MACd;IACA,KAAK,SAAS;MACZ,OAAOG,sBAAsB,CAACf,WAAW,EAAEI,UAAU,CAAC;IACxD,KAAK,iBAAiB;MACpB,OAAOO,aAAa,CAACX,WAAW,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a,CAAC,GAAGtB,SAAS;EAC9D;EAEA,OAAOM,cAAc;AACvB;AAOA,SAASC,uBAAuBA,CAC9BF,OAAgC,EAChC5C,OAAmB,EACnBuC,SAAiB,EACJ;EACb,MAAMM,cAAc,GAAGD,OAAO,CAACmB,mBAAmB,CAEhD/D,OAAO,CAACmD,WAAW,KAAK,OAAO,GAAGnD,OAAO,CAACoD,SAAS,GAAGY,iCACxD,CAAC;EAGD,IAAIhE,OAAO,CAAC6D,aAAa,IAAIhB,cAAc,CAACiB,UAAU,EAAE;IACtDjB,cAAc,CAACiB,UAAU,CAAC9D,OAAO,CAAC6D,aAAa,CAAC,GAAGtB,SAAS;EAC9D;EAEA,OAAOM,cAAc;AACvB;AAMA,SAASe,2BAA2BA,CAACK,IAAc,EAAErB,OAAsB,EAAQ;EAKjF,MAAM;IAACsB;EAAM,CAAC,GAAGtB,OAAO;EACxB,KAAK,IAAIH,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGwB,IAAI,CAACvB,MAAM,EAAED,CAAC,EAAE,EAAE;IACpC,MAAM0B,CAAC,GAAGF,IAAI,CAACxB,CAAC,CAAC;IACjB0B,CAAC,CAAC,CAAC,CAAC,IAAID,MAAM;IACdC,CAAC,CAAC,CAAC,CAAC,IAAID,MAAM;EAChB;AACF;AAEA,SAASF,iCAAiCA,CAACvD,IAAc,EAAEmC,OAAsB,EAAE;EAGjF,MAAM;IAACsB;EAAM,CAAC,GAAGtB,OAAO;EACxB,KAAK,IAAIH,CAAC,GAAG,CAAC,EAAE2B,EAAE,GAAG3D,IAAI,CAACiC,MAAM,EAAED,CAAC,GAAG2B,EAAE,EAAE,EAAE3B,CAAC,EAAE;IAC7ChC,IAAI,CAACgC,CAAC,CAAC,IAAIyB,MAAM;EACnB;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-tilejson.js","names":["isObject","x","parseTileJSON","jsonMetadata","_tileJSON$metaJson","boundingBox","parseBounds","bounds","center","parseCenter","maxZoom","safeParseFloat","maxzoom","minZoom","minzoom","tileJSON","name","description","layers","json","metaJson","JSON","parse","err","parseTilestatsLayers","tilestats","length","parseTileJSONLayers","vector_layers","Array","isArray","map","layer","id","fields","Object","entries","_ref","key","datatype","attributeTypeToFieldType","String","parseTilestatsForLayer","indexedAttributes","attributes","attr","attribute","split","fname","push","attributeToField","dominantGeometry","geometry","result","fromArrayOrString","every","isLng","isLat","undefined","isZoom","input","parseFloat","isNaN","num","Number","isFinite","data","attrTypeMap","number","type","numeric","string","vachar","float","int","int4","boolean","bool","arguments","fieldTypes","aType","toLowerCase"],"sources":["../../src/lib/parse-tilejson.ts"],"sourcesContent":["// loaders.gl, MIT license\n\n/** Parsed and typed TileJSON, merges Tilestats information if present */\nexport type TileJSON = {\n name?: string;\n description?: string;\n version?: string;\n scheme?: 'xyz' | 'tms';\n tiles?: string[];\n /** `[[w, s], [e, n]]`, indicates the limits of the bounding box using the axis units and order of the specified CRS. */\n boundingBox?: [min: [w: number, s: number], max: [e: number, n: number]];\n center: number[] | null;\n maxZoom: number | null;\n minZoom: number | null;\n htmlAttribution?: string;\n htmlLegend?: string;\n layers?: TileJSONLayer[];\n metaJson?: any | null;\n};\n\nexport type TileJSONLayer = {\n /** The name (id) of this layer (tilejson.vector_layers[].id / tilestats.layers[].layer) */\n name: string;\n\n /** The description of this layer (tilejson.layer.description) */\n description?: string;\n\n // tilestats\n\n /** The number of features in this layer (tilestats.layer.count) */\n featureCount?: number;\n /** The dominant geometry type in this layer (tilestats.layer.geometry) */\n dominantGeometry?: string;\n /** An array of details about the first 100 attributes in this layer */\n\n /** */\n minZoom?: number;\n maxZoom?: number;\n fields: TileJSONField[];\n};\n\nexport type TileJSONField = {\n /** The name of this attribute */\n name: string;\n description?: string;\n\n // tilestats\n\n type: string;\n /** min value (if there are *any* numbers in the values) */\n min?: number;\n /** max value (if there are *any* numbers in the values) */\n max?: number;\n /** An array of this attribute's first 100 unique values */\n values?: unknown[];\n};\n\n/**\n * The raw/unparsed tilestats layer type\n * @see https://github.com/mapbox/mapbox-geostats#output-the-stats\n */\ntype TilestatsLayer = {\n /** The name of this layer */\n layer: string;\n /** The number of features in this layer */\n count: number;\n /** The dominant geometry type in this layer */\n geometry: string;\n /** The number of unique attributes in this layer (max. 1000) */\n attributeCount: number;\n /** Fields for this layer */\n attributes?: TilestatsLayerAttribute[];\n};\n\n/**\n * The raw/unparsed tilestats attribute type\n * @see https://github.com/mapbox/mapbox-geostats#output-the-stats\n */\ntype TilestatsLayerAttribute = {\n /** The name of this layer */\n attribute?: string;\n /** Each attribute has one of the following types:\n * - 'string' if all its values are strings (or null).\n * - 'number' if all its values are numbers (or null).\n * - 'boolean' if all its values are booleans (or null).\n * - 'null' if its only value is null.\n * - 'mixed' if it has values of multiple types.\n * - Array and object values are coerced to strings.\n */\n type?: string;\n /** min value (if there are *any* numbers in the values) */\n min?: number;\n /** max value (if there are *any* numbers in the values) */\n max?: number;\n};\n\nconst isObject: (x: unknown) => boolean = (x) => x !== null && typeof x === 'object';\n\nexport function parseTileJSON(jsonMetadata: any): TileJSON | null {\n if (!jsonMetadata || !isObject(jsonMetadata)) {\n return null;\n }\n\n const boundingBox = parseBounds(jsonMetadata.bounds);\n const center = parseCenter(jsonMetadata.center);\n const maxZoom = safeParseFloat(jsonMetadata.maxzoom);\n const minZoom = safeParseFloat(jsonMetadata.minzoom);\n\n let tileJSON: TileJSON = {\n name: jsonMetadata.name || '',\n description: jsonMetadata.description || '',\n boundingBox,\n center,\n maxZoom,\n minZoom,\n layers: []\n };\n\n // try to parse json\n if (typeof jsonMetadata?.json === 'string') {\n try {\n tileJSON.metaJson = JSON.parse(jsonMetadata.json);\n } catch (err) {\n // do nothing\n }\n }\n\n let layers = parseTilestatsLayers(tileJSON.metaJson?.tilestats);\n // TODO - merge in description from tilejson\n if (layers.length === 0) {\n layers = parseTileJSONLayers(jsonMetadata.vector_layers); // eslint-disable-line camelcase\n }\n\n tileJSON = {\n ...tileJSON,\n layers\n };\n\n return tileJSON;\n}\n\nfunction parseTileJSONLayers(layers: any[]): TileJSONLayer[] {\n // Look for fields in vector_layers\n if (!Array.isArray(layers)) {\n return [];\n }\n return layers.map((layer) => ({\n name: layer.id || '',\n fields: Object.entries(layer.fields || []).map(([key, datatype]) => ({\n name: key,\n ...attributeTypeToFieldType(String(datatype))\n }))\n }));\n}\n\n/** parse Layers array from tilestats */\nfunction parseTilestatsLayers(tilestats: any): TileJSONLayer[] {\n if (isObject(tilestats) && Array.isArray(tilestats.layers)) {\n // we are in luck!\n return tilestats.layers.map((layer) => parseTilestatsForLayer(layer));\n }\n return [];\n}\n\nfunction parseTilestatsForLayer(layer: TilestatsLayer): TileJSONLayer {\n const fields: TileJSONField[] = [];\n const indexedAttributes: {[key: string]: TilestatsLayerAttribute[]} = {};\n\n const attributes = layer.attributes || [];\n for (const attr of attributes) {\n const name = attr.attribute;\n if (typeof name === 'string') {\n if (name.split('|').length > 1) {\n // indexed field\n const fname = name.split('|')[0];\n indexedAttributes[fname] = indexedAttributes[fname] || [];\n indexedAttributes[fname].push(attr);\n } else if (!fields[name]) {\n fields[name] = attributeToField(attr);\n } else {\n // return (fields[name], attr);\n }\n }\n }\n return {\n name: layer.layer || '',\n dominantGeometry: layer.geometry,\n fields\n };\n}\n\n/**\n * bounds should be [minLng, minLat, maxLng, maxLat]\n *`[[w, s], [e, n]]`, indicates the limits of the bounding box using the axis units and order of the specified CRS.\n */\nfunction parseBounds(\n bounds: string | number[]\n): [[east: number, south: number], [west: number, north: number]] | undefined {\n // supported formats\n // string: \"-96.657715,40.126127,-90.140061,43.516689\",\n // array: [ -180, -85.05112877980659, 180, 85.0511287798066 ]\n const result = fromArrayOrString(bounds);\n // validate bounds\n if (\n Array.isArray(result) &&\n result.length === 4 &&\n [result[0], result[2]].every(isLng) &&\n [result[1], result[3]].every(isLat)\n ) {\n return [\n [result[0], result[1]],\n [result[2], result[3]]\n ];\n }\n return undefined;\n}\n\nfunction parseCenter(center: string | number[]): number[] | null {\n // supported formats\n // string: \"-96.657715,40.126127,-90.140061,43.516689\",\n // array: [-91.505127,41.615442,14]\n const result = fromArrayOrString(center);\n if (\n Array.isArray(result) &&\n result.length === 3 &&\n isLng(result[0]) &&\n isLat(result[1]) &&\n isZoom(result[2])\n ) {\n return result;\n }\n return null;\n}\n\nfunction safeParseFloat(input: unknown): number | null {\n const result =\n typeof input === 'string' ? parseFloat(input) : typeof input === 'number' ? input : null;\n return result === null || isNaN(result) ? null : result;\n}\n\n// https://github.com/mapbox/tilejson-spec/tree/master/2.2.0\nfunction isLat(num: any): boolean {\n return Number.isFinite(num) && num <= 90 && num >= -90;\n}\nfunction isLng(num: any): boolean {\n return Number.isFinite(num) && num <= 180 && num >= -180;\n}\nfunction isZoom(num: any): boolean {\n return Number.isFinite(num) && num >= 0 && num <= 22;\n}\nfunction fromArrayOrString(data: string | number[]): number[] | null {\n if (typeof data === 'string') {\n return data.split(',').map(parseFloat);\n } else if (Array.isArray(data)) {\n return data;\n }\n return null;\n}\n\n// possible types https://github.com/mapbox/tippecanoe#modifying-feature-attributes\nconst attrTypeMap = {\n number: {\n type: 'float32'\n },\n numeric: {\n type: 'float32'\n },\n string: {\n type: 'utf8'\n },\n vachar: {\n type: 'utf8'\n },\n float: {\n type: 'float32'\n },\n int: {\n type: 'int32'\n },\n int4: {\n type: 'int32'\n },\n boolean: {\n type: 'boolean'\n },\n bool: {\n type: 'boolean'\n }\n};\n\nfunction attributeToField(attribute: TilestatsLayerAttribute = {}): TileJSONField {\n // attribute: \"_season_peaks_color\"\n // count: 1000\n // max: 0.95\n // min: 0.24375\n // type: \"number\"\n const fieldTypes = attributeTypeToFieldType(attribute.type!);\n return {\n name: attribute.attribute as string,\n // what happens if attribute type is string...\n // filterProps: getFilterProps(fieldTypes.type, attribute),\n ...fieldTypes\n };\n}\n\nfunction attributeTypeToFieldType(aType: string): {type: string} {\n const type = aType.toLowerCase();\n if (!type || !attrTypeMap[type]) {\n // console.warn(\n // `cannot convert attribute type ${type} to loaders.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"],"sourcesContent":["import type {LoaderOptions} from '@loaders.gl/loader-utils';\n\n/** For local coordinates, the tileIndex is not required */\ntype MVTLocalCoordinatesOptions = {\n /**\n * When set to `local`, the parser will return a flat array of GeoJSON objects with local coordinates decoded from tile origin.\n */\n coordinates: 'local';\n tileIndex: null;\n};\n\n/** In WGS84 coordinates, the tileIndex is required */\ntype MVTWgs84CoordinatesOptions = {\n /**\n * When set to `wgs84`, the parser will return a flat array of GeoJSON objects with coordinates in longitude, latitude decoded from the provided tile index.\n */\n coordinates?: 'wgs84';\n\n /**\n * Mandatory with `wgs84` coordinates option. An object containing tile index values (`x`, `y`,\n * `z`) to reproject features' coordinates into WGS84.\n */\n tileIndex?: {x: number; y: number; z: number};\n};\n\nexport type MVTOptions = (MVTLocalCoordinatesOptions | MVTWgs84CoordinatesOptions) & {\n /**\n * When non-`null`, the layer name of each feature is added to\n * `feature.properties[layerProperty]`. (A `feature.properties` object is created if the feature\n * has no existing properties). If set to `null`, a layer name property will not be added.\n */\n layerProperty?: string | number;\n\n /**\n * Optional list of layer names. If not `null`, only features belonging to the named layers will\n * be included in the output. If `null`, features from all layers are returned.\n */\n layers?: string[];\n shape?: 'geojson-table' | 'columnar-table' | 'geojson' | 'binary' | 'binary-geometry';\n};\n\nexport type MVTMapboxGeometry = {\n type?: string;\n id?: number;\n length: number;\n coordinates?: any[];\n};\n\nexport type MVTMapboxCoordinates = {\n type: string;\n geometry: {\n type: string;\n coordinates: MVTMapboxGeometry;\n };\n properties: {[x: string]: string | number | boolean | null};\n id?: number;\n};\n\nexport type MVTLoaderOptions = LoaderOptions & {\n mvt?: MVTOptions;\n gis?: {\n /**\n * When set to `true`, the parser will output the data in binary format. This is equivalent to loading the data as GeoJSON and then applying [geojsonToBinary](https://loaders.gl/modules/gis/docs/api-reference/geojson-to-binary).\n */\n binary?: boolean;\n /** @deprecated. Use options.mvt.shape */\n format?: 'geojson-table' | 'columnar-table' | 'geojson' | 'binary' | 'binary-geometry';\n };\n};\n"],"mappings":""}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import parseMVT from
|
|
2
|
-
const VERSION = typeof
|
|
1
|
+
import parseMVT from "./lib/parse-mvt.js";
|
|
2
|
+
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
3
3
|
export const MVTWorkerLoader = {
|
|
4
4
|
name: 'Mapbox Vector Tile',
|
|
5
5
|
id: 'mvt',
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mvt-loader.js","names":["parseMVT","VERSION","__VERSION__","MVTWorkerLoader","name","id","module","version","extensions","mimeTypes","worker","category","options","mvt","shape","coordinates","layerProperty","layers","undefined","tileIndex","MVTLoader","parse","arrayBuffer","parseSync","binary"],"sources":["../src/mvt-loader.ts"],"sourcesContent":["import type {Loader, LoaderWithParser} from '@loaders.gl/loader-utils';\nimport type {MVTLoaderOptions} from './lib/types';\n// import type {\n// Feature,\n// BinaryFeatureCollection,\n// GeoJSONTable,\n// Geometry,\n// GeoJsonProperties\n// } from '@loaders.gl/schema';\nimport parseMVT from './lib/parse-mvt';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\n/**\n * Worker loader for the Mapbox Vector Tile format\n */\nexport const MVTWorkerLoader: Loader<\n any, // BinaryFeatureCollection | GeoJSONTable | Feature<Geometry, GeoJsonProperties>,\n never,\n MVTLoaderOptions\n> = {\n name: 'Mapbox Vector Tile',\n id: 'mvt',\n module: 'mvt',\n version: VERSION,\n // Note: ArcGIS uses '.pbf' extension and 'application/octet-stream'\n extensions: ['mvt', 'pbf'],\n mimeTypes: [\n // https://www.iana.org/assignments/media-types/application/vnd.mapbox-vector-tile\n 'application/vnd.mapbox-vector-tile',\n 'application/x-protobuf'\n // 'application/octet-stream'\n ],\n worker: true,\n category: 'geometry',\n options: {\n mvt: {\n shape: 'geojson',\n coordinates: 'local',\n layerProperty: 'layerName',\n layers: undefined,\n tileIndex: null\n }\n }\n};\n\n/**\n * Loader for the Mapbox Vector Tile format\n */\nexport const MVTLoader: LoaderWithParser<\n any, // BinaryFeatureCollection | GeoJSONTable | Feature<Geometry, GeoJsonProperties>,\n never,\n MVTLoaderOptions\n> = {\n ...MVTWorkerLoader,\n parse: async (arrayBuffer, options?: MVTLoaderOptions) => parseMVT(arrayBuffer, options),\n parseSync: parseMVT,\n binary: true\n};\n"],"mappings":"OASOA,QAAQ;AAIf,MAAMC,OAAO,GAAG,OAAOC,WAAW,KAAK,WAAW,GAAGA,WAAW,GAAG,QAAQ;AAK3E,OAAO,MAAMC,eAIZ,GAAG;EACFC,IAAI,EAAE,oBAAoB;EAC1BC,EAAE,EAAE,KAAK;EACTC,MAAM,EAAE,KAAK;EACbC,OAAO,EAAEN,OAAO;EAEhBO,UAAU,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC;EAC1BC,SAAS,EAAE,CAET,oCAAoC,EACpC,wBAAwB,CAEzB;EACDC,MAAM,EAAE,IAAI;EACZC,QAAQ,EAAE,UAAU;EACpBC,OAAO,EAAE;IACPC,GAAG,EAAE;MACHC,KAAK,EAAE,SAAS;MAChBC,WAAW,EAAE,OAAO;MACpBC,aAAa,EAAE,WAAW;MAC1BC,MAAM,EAAEC,SAAS;MACjBC,SAAS,EAAE;IACb;EACF;AACF,CAAC;AAKD,OAAO,MAAMC,SAIZ,GAAG;EACF,GAAGjB,eAAe;EAClBkB,KAAK,EAAE,MAAAA,CAAOC,WAAW,EAAEV,OAA0B,KAAKZ,QAAQ,CAACsB,WAAW,EAAEV,OAAO,CAAC;EACxFW,SAAS,EAAEvB,QAAQ;EACnBwB,MAAM,EAAE;AACV,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { GetTileParameters, ImageType, DataSourceProps } from '@loaders.gl/loader-utils';
|
|
2
|
+
import type { ImageTileSource, VectorTileSource } from '@loaders.gl/loader-utils';
|
|
3
|
+
import { DataSource } from '@loaders.gl/loader-utils';
|
|
4
|
+
import { TileJSON } from '@loaders.gl/mvt';
|
|
5
|
+
import { TileLoadParameters } from '@loaders.gl/loader-utils';
|
|
6
|
+
export type MVTSourceProps = DataSourceProps & {
|
|
7
|
+
url: string;
|
|
8
|
+
attributions?: string[];
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* A PMTiles data source
|
|
12
|
+
* @note Can be either a raster or vector tile source depending on the contents of the PMTiles file.
|
|
13
|
+
*/
|
|
14
|
+
export declare class MVTSource extends DataSource implements ImageTileSource, VectorTileSource {
|
|
15
|
+
props: MVTSourceProps;
|
|
16
|
+
url: string;
|
|
17
|
+
schema: 'tms' | 'xyz';
|
|
18
|
+
metadata: Promise<TileJSON | null>;
|
|
19
|
+
constructor(props: MVTSourceProps);
|
|
20
|
+
getMetadata(): Promise<TileJSON | null>;
|
|
21
|
+
getTile(tileParams: GetTileParameters): Promise<ArrayBuffer | null>;
|
|
22
|
+
getTileData(tileParams: TileLoadParameters): Promise<unknown | null>;
|
|
23
|
+
getImageTile(tileParams: GetTileParameters): Promise<ImageType | null>;
|
|
24
|
+
getVectorTile(tileParams: GetTileParameters): Promise<unknown | null>;
|
|
25
|
+
getMetadataUrl(): string;
|
|
26
|
+
getTileURL(x: number, y: number, z: number): string;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=mvt-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mvt-source.d.ts","sourceRoot":"","sources":["../src/mvt-source.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,iBAAiB,EAAE,SAAS,EAAE,eAAe,EAAC,MAAM,0BAA0B,CAAC;AAC5F,OAAO,KAAK,EAAC,eAAe,EAAE,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAAC,UAAU,EAAc,MAAM,0BAA0B,CAAC;AAEjE,OAAO,EAA8C,QAAQ,EAAC,MAAM,iBAAiB,CAAC;AAEtF,OAAO,EAAC,kBAAkB,EAAC,MAAM,0BAA0B,CAAC;AAE5D,MAAM,MAAM,cAAc,GAAG,eAAe,GAAG;IAC7C,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB,CAAC;AAEF;;;GAGG;AACH,qBAAa,SAAU,SAAQ,UAAW,YAAW,eAAe,EAAE,gBAAgB;IACpF,KAAK,EAAE,cAAc,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,KAAK,GAAG,KAAK,CAAS;IAC9B,QAAQ,EAAE,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;gBAEvB,KAAK,EAAE,cAAc;IAS3B,WAAW,IAAI,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAYvC,OAAO,CAAC,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAcnE,WAAW,CAAC,UAAU,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAcpE,YAAY,CAAC,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;IAOtE,aAAa,CAAC,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAe3E,cAAc,IAAI,MAAM;IAIxB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM;CAS3C"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { DataSource, resolvePath } from '@loaders.gl/loader-utils';
|
|
2
|
+
import { ImageLoader } from '@loaders.gl/images';
|
|
3
|
+
import { MVTLoader, TileJSONLoader } from '@loaders.gl/mvt';
|
|
4
|
+
export class MVTSource extends DataSource {
|
|
5
|
+
constructor(props) {
|
|
6
|
+
super(props);
|
|
7
|
+
this.props = void 0;
|
|
8
|
+
this.url = void 0;
|
|
9
|
+
this.schema = 'tms';
|
|
10
|
+
this.metadata = void 0;
|
|
11
|
+
this.props = props;
|
|
12
|
+
this.url = resolvePath(props.url);
|
|
13
|
+
this.getTileData = this.getTileData.bind(this);
|
|
14
|
+
this.metadata = this.getMetadata();
|
|
15
|
+
}
|
|
16
|
+
async getMetadata() {
|
|
17
|
+
var _TileJSONLoader$parse;
|
|
18
|
+
const metadataUrl = this.getMetadataUrl();
|
|
19
|
+
const response = await this.fetch(metadataUrl);
|
|
20
|
+
if (!response.ok) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
const tileJSON = await response.text();
|
|
24
|
+
const metadata = ((_TileJSONLoader$parse = TileJSONLoader.parseTextSync) === null || _TileJSONLoader$parse === void 0 ? void 0 : _TileJSONLoader$parse.call(TileJSONLoader, JSON.stringify(tileJSON))) || null;
|
|
25
|
+
return metadata;
|
|
26
|
+
}
|
|
27
|
+
async getTile(tileParams) {
|
|
28
|
+
const {
|
|
29
|
+
x,
|
|
30
|
+
y,
|
|
31
|
+
zoom: z
|
|
32
|
+
} = tileParams;
|
|
33
|
+
const tileUrl = this.getTileURL(x, y, z);
|
|
34
|
+
const response = await this.fetch(tileUrl);
|
|
35
|
+
if (!response.ok) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
39
|
+
return arrayBuffer;
|
|
40
|
+
}
|
|
41
|
+
async getTileData(tileParams) {
|
|
42
|
+
const {
|
|
43
|
+
x,
|
|
44
|
+
y,
|
|
45
|
+
z
|
|
46
|
+
} = tileParams.index;
|
|
47
|
+
const metadata = await this.metadata;
|
|
48
|
+
switch (metadata.mimeType || 'application/vnd.mapbox-vector-tile') {
|
|
49
|
+
case 'application/vnd.mapbox-vector-tile':
|
|
50
|
+
return await this.getVectorTile({
|
|
51
|
+
x,
|
|
52
|
+
y,
|
|
53
|
+
zoom: z,
|
|
54
|
+
layers: []
|
|
55
|
+
});
|
|
56
|
+
default:
|
|
57
|
+
return await this.getImageTile({
|
|
58
|
+
x,
|
|
59
|
+
y,
|
|
60
|
+
zoom: z,
|
|
61
|
+
layers: []
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async getImageTile(tileParams) {
|
|
66
|
+
const arrayBuffer = await this.getTile(tileParams);
|
|
67
|
+
return arrayBuffer ? await ImageLoader.parse(arrayBuffer, this.loadOptions) : null;
|
|
68
|
+
}
|
|
69
|
+
async getVectorTile(tileParams) {
|
|
70
|
+
var _this$loadOptions;
|
|
71
|
+
const arrayBuffer = await this.getTile(tileParams);
|
|
72
|
+
const loadOptions = {
|
|
73
|
+
shape: 'geojson-table',
|
|
74
|
+
mvt: {
|
|
75
|
+
coordinates: 'wgs84',
|
|
76
|
+
tileIndex: {
|
|
77
|
+
x: tileParams.x,
|
|
78
|
+
y: tileParams.y,
|
|
79
|
+
z: tileParams.zoom
|
|
80
|
+
},
|
|
81
|
+
...((_this$loadOptions = this.loadOptions) === null || _this$loadOptions === void 0 ? void 0 : _this$loadOptions.mvt)
|
|
82
|
+
},
|
|
83
|
+
...this.loadOptions
|
|
84
|
+
};
|
|
85
|
+
return arrayBuffer ? await MVTLoader.parse(arrayBuffer, loadOptions) : null;
|
|
86
|
+
}
|
|
87
|
+
getMetadataUrl() {
|
|
88
|
+
return `${this.url}/tilejson.json`;
|
|
89
|
+
}
|
|
90
|
+
getTileURL(x, y, z) {
|
|
91
|
+
switch (this.schema) {
|
|
92
|
+
case 'xyz':
|
|
93
|
+
return `${this.url}/${x}/${y}/${z}`;
|
|
94
|
+
case 'tms':
|
|
95
|
+
default:
|
|
96
|
+
return `${this.url}/${z}/${x}/${y}`;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=mvt-source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mvt-source.js","names":["DataSource","resolvePath","ImageLoader","MVTLoader","TileJSONLoader","MVTSource","constructor","props","url","schema","metadata","getTileData","bind","getMetadata","_TileJSONLoader$parse","metadataUrl","getMetadataUrl","response","fetch","ok","tileJSON","text","parseTextSync","call","JSON","stringify","getTile","tileParams","x","y","zoom","z","tileUrl","getTileURL","arrayBuffer","index","mimeType","getVectorTile","layers","getImageTile","parse","loadOptions","_this$loadOptions","shape","mvt","coordinates","tileIndex"],"sources":["../src/mvt-source.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport type {GetTileParameters, ImageType, DataSourceProps} from '@loaders.gl/loader-utils';\nimport type {ImageTileSource, VectorTileSource} from '@loaders.gl/loader-utils';\nimport {DataSource, resolvePath} from '@loaders.gl/loader-utils';\nimport {ImageLoader} from '@loaders.gl/images';\nimport {MVTLoader, MVTLoaderOptions, TileJSONLoader, TileJSON} from '@loaders.gl/mvt';\n\nimport {TileLoadParameters} from '@loaders.gl/loader-utils';\n\nexport type MVTSourceProps = DataSourceProps & {\n url: string;\n attributions?: string[];\n};\n\n/**\n * A PMTiles data source\n * @note Can be either a raster or vector tile source depending on the contents of the PMTiles file.\n */\nexport class MVTSource extends DataSource implements ImageTileSource, VectorTileSource {\n props: MVTSourceProps;\n url: string;\n schema: 'tms' | 'xyz' = 'tms';\n metadata: Promise<TileJSON | null>;\n\n constructor(props: MVTSourceProps) {\n super(props);\n this.props = props;\n this.url = resolvePath(props.url);\n this.getTileData = this.getTileData.bind(this);\n this.metadata = this.getMetadata();\n }\n\n // @ts-ignore - Metadata type misalignment\n async getMetadata(): Promise<TileJSON | null> {\n const metadataUrl = this.getMetadataUrl();\n const response = await this.fetch(metadataUrl);\n if (!response.ok) {\n return null;\n }\n const tileJSON = await response.text();\n const metadata = TileJSONLoader.parseTextSync?.(JSON.stringify(tileJSON)) || null;\n // metadata.attributions = [...this.props.attributions, ...(metadata.attributions || [])];\n return metadata;\n }\n\n async getTile(tileParams: GetTileParameters): Promise<ArrayBuffer | null> {\n const {x, y, zoom: z} = tileParams;\n const tileUrl = this.getTileURL(x, y, z);\n const response = await this.fetch(tileUrl);\n if (!response.ok) {\n return null;\n }\n const arrayBuffer = await response.arrayBuffer();\n return arrayBuffer;\n }\n\n // Tile Source interface implementation: deck.gl compatible API\n // TODO - currently only handles image tiles, not vector tiles\n\n async getTileData(tileParams: TileLoadParameters): Promise<unknown | null> {\n const {x, y, z} = tileParams.index;\n const metadata = await this.metadata;\n // @ts-expect-error\n switch (metadata.mimeType || 'application/vnd.mapbox-vector-tile') {\n case 'application/vnd.mapbox-vector-tile':\n return await this.getVectorTile({x, y, zoom: z, layers: []});\n default:\n return await this.getImageTile({x, y, zoom: z, layers: []});\n }\n }\n\n // ImageTileSource interface implementation\n\n async getImageTile(tileParams: GetTileParameters): Promise<ImageType | null> {\n const arrayBuffer = await this.getTile(tileParams);\n return arrayBuffer ? await ImageLoader.parse(arrayBuffer, this.loadOptions) : null;\n }\n\n // VectorTileSource interface implementation\n\n async getVectorTile(tileParams: GetTileParameters): Promise<unknown | null> {\n const arrayBuffer = await this.getTile(tileParams);\n const loadOptions: MVTLoaderOptions = {\n shape: 'geojson-table',\n mvt: {\n coordinates: 'wgs84',\n tileIndex: {x: tileParams.x, y: tileParams.y, z: tileParams.zoom},\n ...(this.loadOptions as MVTLoaderOptions)?.mvt\n },\n ...this.loadOptions\n };\n\n return arrayBuffer ? await MVTLoader.parse(arrayBuffer, loadOptions) : null;\n }\n\n getMetadataUrl(): string {\n return `${this.url}/tilejson.json`;\n }\n\n getTileURL(x: number, y: number, z: number) {\n switch (this.schema) {\n case 'xyz':\n return `${this.url}/${x}/${y}/${z}`;\n case 'tms':\n default:\n return `${this.url}/${z}/${x}/${y}`;\n }\n }\n}\n"],"mappings":"AAIA,SAAQA,UAAU,EAAEC,WAAW,QAAO,0BAA0B;AAChE,SAAQC,WAAW,QAAO,oBAAoB;AAC9C,SAAQC,SAAS,EAAoBC,cAAc,QAAiB,iBAAiB;AAarF,OAAO,MAAMC,SAAS,SAASL,UAAU,CAA8C;EAMrFM,W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