@loaders.gl/mvt 3.1.0-alpha.1 → 4.0.0-alpha.1
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/bundle.js +2 -4
- package/dist/bundle.js.map +1 -1
- package/dist/lib/binary-vector-tile/vector-tile-feature.js +2 -2
- package/dist/lib/binary-vector-tile/vector-tile-feature.js.map +1 -1
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +3 -3
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -1
- package/dist/mvt-loader.js +1 -1
- package/dist/mvt-worker.js +2286 -3
- package/package.json +6 -6
- package/src/bundle.ts +2 -3
- package/dist/dist.min.js +0 -4
- package/dist/dist.min.js.map +0 -1
- package/dist/mvt-worker.js.map +0 -1
package/dist/bundle.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
const moduleExports = require('./index');
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
_global.loaders = _global.loaders || {};
|
|
6
|
-
module.exports = Object.assign(_global.loaders, moduleExports);
|
|
3
|
+
globalThis.loaders = globalThis.loaders || {};
|
|
4
|
+
module.exports = Object.assign(globalThis.loaders, moduleExports);
|
|
7
5
|
//# sourceMappingURL=bundle.js.map
|
package/dist/bundle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/bundle.ts"],"names":["moduleExports","require","
|
|
1
|
+
{"version":3,"sources":["../src/bundle.ts"],"names":["moduleExports","require","globalThis","loaders","module","exports","Object","assign"],"mappings":"AACA,MAAMA,aAAa,GAAGC,OAAO,CAAC,SAAD,CAA7B;;AACAC,UAAU,CAACC,OAAX,GAAqBD,UAAU,CAACC,OAAX,IAAsB,EAA3C;AACAC,MAAM,CAACC,OAAP,GAAiBC,MAAM,CAACC,MAAP,CAAcL,UAAU,CAACC,OAAzB,EAAkCH,aAAlC,CAAjB","sourcesContent":["// @ts-nocheck\nconst moduleExports = require('./index');\nglobalThis.loaders = globalThis.loaders || {};\nmodule.exports = Object.assign(globalThis.loaders, moduleExports);\n"],"file":"bundle.js"}
|
|
@@ -84,7 +84,7 @@ export default class VectorTileFeature {
|
|
|
84
84
|
i += 2;
|
|
85
85
|
}
|
|
86
86
|
} else {
|
|
87
|
-
throw new Error(
|
|
87
|
+
throw new Error("unknown command ".concat(cmd));
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
|
|
@@ -128,7 +128,7 @@ export default class VectorTileFeature {
|
|
|
128
128
|
geom.type = VectorTileFeature.types[this.type];
|
|
129
129
|
|
|
130
130
|
if (geom.lines.length > 1) {
|
|
131
|
-
geom.type =
|
|
131
|
+
geom.type = "Multi".concat(geom.type);
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
const result = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/binary-vector-tile/vector-tile-feature.ts"],"names":["classifyRings","project","readFeature","endPos","cmd","cmdLen","length","x","y","i","TEST_EXPORTS","VectorTileFeature","types","constructor","pbf","end","extent","keys","values","firstPassData","properties","type","id","_pbf","_geometry","_keys","_values","_firstPassData","readFields","loadGeometry","pos","readVarint","lines","data","readSVarint","push","start","Error","_toBinaryCoordinates","transform","geom","coordLength","pointFeaturesCount","pointPositionsCount","lineFeaturesCount","linePathsCount","linePositionsCount","classified","polygonFeaturesCount","polygonObjectsCount","polygonRingsCount","polygonPositionsCount","result","geometry","toBinaryCoordinates","options"],"mappings":";AAIA,SAAQA,aAAR,EAAuBC,OAAvB,EAAgCC,WAAhC,QAAkD,qCAAlD;AAGA,IAAIC,MAAJ;AACA,IAAIC,GAAJ;AACA,IAAIC,MAAJ;AACA,IAAIC,MAAJ;AACA,IAAIC,CAAJ;AACA,IAAIC,CAAJ;AACA,IAAIC,CAAJ;AAEA,OAAO,MAAMC,YAAY,GAAG;AAC1BV,EAAAA;AAD0B,CAArB;AAIP,eAAe,MAAMW,iBAAN,CAAwB;AAU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KA,EAAjB;AACD;;AAED,WAAO8B,MAAP;AACD;;AAEDE,EAAAA,mBAAmB,CACjBC,OADiB,EAEK;AACtB,QAAI,OAAOA,OAAP,KAAmB,UAAvB,EAAmC;AACjC,aAAO,KAAKjB,oBAAL,CAA0BiB,OAA1B,CAAP;AACD;;AACD,WAAO,KAAKjB,oBAAL,CAA0BrC,OAA1B,CAAP;AACD;;AArLoC","sourcesContent":["// This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.\n\nimport Protobuf from 'pbf';\nimport {MvtBinaryCoordinates, MvtBinaryGeometry, MvtFirstPassedData} from '../types';\nimport {classifyRings, project, readFeature} from '../../helpers/binary-util-functions';\n\n// Reduce GC by reusing variables\nlet endPos: number;\nlet cmd: number;\nlet cmdLen: number;\nlet length: number;\nlet x: number;\nlet y: number;\nlet i: number;\n\nexport const TEST_EXPORTS = {\n classifyRings\n};\n\nexport default class VectorTileFeature {\n properties: {[x: string]: string | number | boolean | null};\n extent: any;\n type: number;\n id: number | null;\n _pbf: Protobuf;\n _geometry: number;\n _keys: string[];\n _values: (string | number | boolean | null)[];\n _firstPassData: MvtFirstPassedData;\n static get types() {\n return ['Unknown', 'Point', 'LineString', 'Polygon'];\n }\n\n // eslint-disable-next-line max-params\n constructor(\n pbf: Protobuf,\n end: number,\n extent: any,\n keys: string[],\n values: (string | number | boolean | null)[],\n firstPassData: MvtFirstPassedData\n ) {\n // Public\n this.properties = {};\n this.extent = extent;\n this.type = 0;\n this.id = null;\n\n // Private\n this._pbf = pbf;\n this._geometry = -1;\n this._keys = keys;\n this._values = values;\n this._firstPassData = firstPassData;\n\n pbf.readFields(readFeature, this, end);\n }\n\n // eslint-disable-next-line complexity, max-statements\n loadGeometry(): MvtBinaryGeometry {\n const pbf = this._pbf;\n pbf.pos = this._geometry;\n\n endPos = pbf.readVarint() + pbf.pos;\n cmd = 1;\n length = 0;\n x = 0;\n y = 0;\n i = 0;\n\n // Note: I attempted to replace the `data` array with a\n // Float32Array, but performance was worse, both using\n // `set()` and direct index access. Also, we cannot\n // know how large the buffer should be, so it would\n // increase memory usage\n const lines: number[] = []; // Indices where lines start\n const data: number[] = []; // Flat array of coordinate data\n\n while (pbf.pos < endPos) {\n if (length <= 0) {\n cmdLen = pbf.readVarint();\n cmd = cmdLen & 0x7;\n length = cmdLen >> 3;\n }\n\n length--;\n\n if (cmd === 1 || cmd === 2) {\n x += pbf.readSVarint();\n y += pbf.readSVarint();\n\n if (cmd === 1) {\n // New line\n lines.push(i);\n }\n data.push(x, y);\n i += 2;\n } else if (cmd === 7) {\n // Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90\n if (i > 0) {\n const start = lines[lines.length - 1]; // start index of polygon\n data.push(data[start], data[start + 1]); // closePolygon\n i += 2;\n }\n } else {\n throw new Error(`unknown command ${cmd}`);\n }\n }\n\n return {data, lines};\n }\n\n /**\n *\n * @param transform\n * @returns result\n */\n _toBinaryCoordinates(transform) {\n // Expands the protobuf data to an intermediate `lines`\n // data format, which maps closely to the binary data buffers.\n // It is similar to GeoJSON, but rather than storing the coordinates\n // in multidimensional arrays, we have a 1D `data` with all the\n // coordinates, and then index into this using the `lines`\n // parameter, e.g.\n //\n // geometry: {\n // type: 'Point', data: [1,2], lines: [0]\n // }\n // geometry: {\n // type: 'LineString', data: [1,2,3,4,...], lines: [0]\n // }\n // geometry: {\n // type: 'Polygon', data: [1,2,3,4,...], lines: [[0, 2]]\n // }\n // Thus the lines member lets us look up the relevant range\n // from the data array.\n // The Multi* versions of the above types share the same data\n // structure, just with multiple elements in the lines array\n let geom = this.loadGeometry();\n\n // Apply the supplied transformation to data\n transform(geom.data, this);\n\n const coordLength = 2;\n\n // eslint-disable-next-line default-case\n switch (this.type) {\n case 1: // Point\n this._firstPassData.pointFeaturesCount++;\n this._firstPassData.pointPositionsCount += geom.lines.length;\n break;\n\n case 2: // LineString\n this._firstPassData.lineFeaturesCount++;\n this._firstPassData.linePathsCount += geom.lines.length;\n this._firstPassData.linePositionsCount += geom.data.length / coordLength;\n break;\n\n case 3: // Polygon\n const classified = classifyRings(geom);\n\n // Unlike Point & LineString geom.lines is a 2D array, thanks\n // to the classifyRings method\n this._firstPassData.polygonFeaturesCount++;\n this._firstPassData.polygonObjectsCount += classified.lines.length;\n\n for (const lines of classified.lines) {\n this._firstPassData.polygonRingsCount += lines.length;\n }\n this._firstPassData.polygonPositionsCount += classified.data.length / coordLength;\n\n geom = classified;\n break;\n }\n\n geom.type = VectorTileFeature.types[this.type];\n if (geom.lines.length > 1) {\n geom.type = `Multi${geom.type}`;\n }\n\n const result: MvtBinaryCoordinates = {\n type: 'Feature',\n geometry: geom,\n properties: this.properties\n };\n\n if (this.id !== null) {\n result.id = this.id;\n }\n\n return result;\n }\n\n toBinaryCoordinates(\n options: {x: number; y: number; z: number} | ((data: number[], feature: {extent: any}) => void)\n ): MvtBinaryCoordinates {\n if (typeof options === 'function') {\n return this._toBinaryCoordinates(options);\n }\n return this._toBinaryCoordinates(project);\n }\n}\n"],"file":"vector-tile-feature.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/binary-vector-tile/vector-tile-feature.ts"],"names":["classifyRings","project","readFeature","endPos","cmd","cmdLen","length","x","y","i","TEST_EXPORTS","VectorTileFeature","types","constructor","pbf","end","extent","keys","values","firstPassData","properties","type","id","_pbf","_geometry","_keys","_values","_firstPassData","readFields","loadGeometry","pos","readVarint","lines","data","readSVarint","push","start","Error","_toBinaryCoordinates","transform","geom","coordLength","pointFeaturesCount","pointPositionsCount","lineFeaturesCount","linePathsCount","linePositionsCount","classified","polygonFeaturesCount","polygonObjectsCount","polygonRingsCount","polygonPositionsCount","result","geometry","toBinaryCoordinates","options"],"mappings":";AAIA,SAAQA,aAAR,EAAuBC,OAAvB,EAAgCC,WAAhC,QAAkD,qCAAlD;AAGA,IAAIC,MAAJ;AACA,IAAIC,GAAJ;AACA,IAAIC,MAAJ;AACA,IAAIC,MAAJ;AACA,IAAIC,CAAJ;AACA,IAAIC,CAAJ;AACA,IAA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,QAAI,KAAKE,EAAL,KAAY,IAAhB,EAAsB;AACpB8B,MAAAA,MAAM,CAAC9B,EAAP,GAAY,KAAKA,EAAjB;AACD;;AAED,WAAO8B,MAAP;AACD;;AAEDE,EAAAA,mBAAmB,CACjBC,OADiB,EAEK;AACtB,QAAI,OAAOA,OAAP,KAAmB,UAAvB,EAAmC;AACjC,aAAO,KAAKjB,oBAAL,CAA0BiB,OAA1B,CAAP;AACD;;AACD,WAAO,KAAKjB,oBAAL,CAA0BrC,OAA1B,CAAP;AACD;;AArLoC","sourcesContent":["// This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.\n\nimport Protobuf from 'pbf';\nimport {MvtBinaryCoordinates, MvtBinaryGeometry, MvtFirstPassedData} from '../types';\nimport {classifyRings, project, readFeature} from '../../helpers/binary-util-functions';\n\n// Reduce GC by reusing variables\nlet endPos: number;\nlet cmd: number;\nlet cmdLen: number;\nlet length: number;\nlet x: number;\nlet y: number;\nlet i: number;\n\nexport const TEST_EXPORTS = {\n classifyRings\n};\n\nexport default class VectorTileFeature {\n properties: {[x: string]: string | number | boolean | null};\n extent: any;\n type: number;\n id: number | null;\n _pbf: Protobuf;\n _geometry: number;\n _keys: string[];\n _values: (string | number | boolean | null)[];\n _firstPassData: MvtFirstPassedData;\n static get types() {\n return ['Unknown', 'Point', 'LineString', 'Polygon'];\n }\n\n // eslint-disable-next-line max-params\n constructor(\n pbf: Protobuf,\n end: number,\n extent: any,\n keys: string[],\n values: (string | number | boolean | null)[],\n firstPassData: MvtFirstPassedData\n ) {\n // Public\n this.properties = {};\n this.extent = extent;\n this.type = 0;\n this.id = null;\n\n // Private\n this._pbf = pbf;\n this._geometry = -1;\n this._keys = keys;\n this._values = values;\n this._firstPassData = firstPassData;\n\n pbf.readFields(readFeature, this, end);\n }\n\n // eslint-disable-next-line complexity, max-statements\n loadGeometry(): MvtBinaryGeometry {\n const pbf = this._pbf;\n pbf.pos = this._geometry;\n\n endPos = pbf.readVarint() + pbf.pos;\n cmd = 1;\n length = 0;\n x = 0;\n y = 0;\n i = 0;\n\n // Note: I attempted to replace the `data` array with a\n // Float32Array, but performance was worse, both using\n // `set()` and direct index access. Also, we cannot\n // know how large the buffer should be, so it would\n // increase memory usage\n const lines: number[] = []; // Indices where lines start\n const data: number[] = []; // Flat array of coordinate data\n\n while (pbf.pos < endPos) {\n if (length <= 0) {\n cmdLen = pbf.readVarint();\n cmd = cmdLen & 0x7;\n length = cmdLen >> 3;\n }\n\n length--;\n\n if (cmd === 1 || cmd === 2) {\n x += pbf.readSVarint();\n y += pbf.readSVarint();\n\n if (cmd === 1) {\n // New line\n lines.push(i);\n }\n data.push(x, y);\n i += 2;\n } else if (cmd === 7) {\n // Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90\n if (i > 0) {\n const start = lines[lines.length - 1]; // start index of polygon\n data.push(data[start], data[start + 1]); // closePolygon\n i += 2;\n }\n } else {\n throw new Error(`unknown command ${cmd}`);\n }\n }\n\n return {data, lines};\n }\n\n /**\n *\n * @param transform\n * @returns result\n */\n _toBinaryCoordinates(transform) {\n // Expands the protobuf data to an intermediate `lines`\n // data format, which maps closely to the binary data buffers.\n // It is similar to GeoJSON, but rather than storing the coordinates\n // in multidimensional arrays, we have a 1D `data` with all the\n // coordinates, and then index into this using the `lines`\n // parameter, e.g.\n //\n // geometry: {\n // type: 'Point', data: [1,2], lines: [0]\n // }\n // geometry: {\n // type: 'LineString', data: [1,2,3,4,...], lines: [0]\n // }\n // geometry: {\n // type: 'Polygon', data: [1,2,3,4,...], lines: [[0, 2]]\n // }\n // Thus the lines member lets us look up the relevant range\n // from the data array.\n // The Multi* versions of the above types share the same data\n // structure, just with multiple elements in the lines array\n let geom = this.loadGeometry();\n\n // Apply the supplied transformation to data\n transform(geom.data, this);\n\n const coordLength = 2;\n\n // eslint-disable-next-line default-case\n switch (this.type) {\n case 1: // Point\n this._firstPassData.pointFeaturesCount++;\n this._firstPassData.pointPositionsCount += geom.lines.length;\n break;\n\n case 2: // LineString\n this._firstPassData.lineFeaturesCount++;\n this._firstPassData.linePathsCount += geom.lines.length;\n this._firstPassData.linePositionsCount += geom.data.length / coordLength;\n break;\n\n case 3: // Polygon\n const classified = classifyRings(geom);\n\n // Unlike Point & LineString geom.lines is a 2D array, thanks\n // to the classifyRings method\n this._firstPassData.polygonFeaturesCount++;\n this._firstPassData.polygonObjectsCount += classified.lines.length;\n\n for (const lines of classified.lines) {\n this._firstPassData.polygonRingsCount += lines.length;\n }\n this._firstPassData.polygonPositionsCount += classified.data.length / coordLength;\n\n geom = classified;\n break;\n }\n\n geom.type = VectorTileFeature.types[this.type];\n if (geom.lines.length > 1) {\n geom.type = `Multi${geom.type}`;\n }\n\n const result: MvtBinaryCoordinates = {\n type: 'Feature',\n geometry: geom,\n properties: this.properties\n };\n\n if (this.id !== null) {\n result.id = this.id;\n }\n\n return result;\n }\n\n toBinaryCoordinates(\n options: {x: number; y: number; z: number} | ((data: number[], feature: {extent: any}) => void)\n ): MvtBinaryCoordinates {\n if (typeof options === 'function') {\n return this._toBinaryCoordinates(options);\n }\n return this._toBinaryCoordinates(project);\n }\n}\n"],"file":"vector-tile-feature.js"}
|
|
@@ -68,7 +68,7 @@ export default class VectorTileFeature {
|
|
|
68
68
|
line.push(line[0].slice());
|
|
69
69
|
}
|
|
70
70
|
} else {
|
|
71
|
-
throw new Error(
|
|
71
|
+
throw new Error("unknown command ".concat(cmd));
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
|
|
@@ -106,7 +106,7 @@ export default class VectorTileFeature {
|
|
|
106
106
|
if (y < y1) y1 = y;
|
|
107
107
|
if (y > y2) y2 = y;
|
|
108
108
|
} else if (cmd !== 7) {
|
|
109
|
-
throw new Error(
|
|
109
|
+
throw new Error("unknown command ".concat(cmd));
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
|
|
@@ -153,7 +153,7 @@ export default class VectorTileFeature {
|
|
|
153
153
|
if (coords.length === 1) {
|
|
154
154
|
coords = coords[0];
|
|
155
155
|
} else {
|
|
156
|
-
type =
|
|
156
|
+
type = "Multi".concat(type);
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
const result = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/mapbox-vector-tile/vector-tile-feature.ts"],"names":["readFeature","classifyRings","VectorTileFeature","types","constructor","pbf","end","extent","keys","values","properties","type","id","_pbf","_geometry","_keys","_values","readFields","loadGeometry","pos","readVarint","cmd","length","x","y","lines","line","cmdLen","readSVarint","push","slice","Error","bbox","x1","Infinity","x2","y1","y2","_toGeoJSON","transform","coords","i","j","points","result","geometry","coordinates","toGeoJSON","options","z","size","Math","pow","x0","y0","project","p","PI","atan","exp"],"mappings":";AAGA,SAAQA,WAAR,EAAqBC,aAArB,QAAyC,qCAAzC;AAEA,eAAe,MAAMC,iBAAN,CAAwB;AASrB,aAALC,KAAK,GAAG;AACjB,WAAO,CAAC,SAAD,EAAY,OAAZ,EAAqB,YAArB,EAAmC,SAAnC,CAAP;AACD;;AAEDC,EAAAA,WAAW,CACTC,GADS,EAETC,GAFS,EAGTC,MAHS,EAITC,IAJS,EAKTC,MALS,EAMT;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAEA,SAAKC,UAAL,GAAkB,EAAlB;AACA,SAAKH,MAAL,GAAcA,MAAd;AACA,SAAKI,IAAL,GAAY,CAAZ;AACA,SAAKC,EAAL,GAAU,IAAV;AAGA,SAAKC,IAAL,GAAYR,GAAZ;AACA,SAAKS,SAAL,GAAiB,CAAC,CAAlB;AACA,SAAKC,KAAL,GAAaP,IAAb;AACA,SAAKQ,OAAL,GAAeP,MAAf;AAEAJ,IAAAA,GAAG,CAACY,UAAJ,CAAejB,WAAf,EAA4B,IAA5B,EAAkCM,GAAlC;AACD;;AAGDY,EAAAA,YAAY,GAAsB;AAChC,UAAMb,GAAG,GAAG,KAAKQ,IAAjB;AACAR,IAAAA,GAAG,CAACc,GAAJ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AAC,CAAD,CAAD,GAAQ,CAACA,CAAC,CAAC,CAAD,CAAD,GAAOH,EAAR,IAAc,GAAf,GAAsBH,IAAtB,GAA6B,GAApC;AACA,cAAMb,EAAE,GAAG,MAAO,CAACmB,CAAC,CAAC,CAAD,CAAD,GAAOF,EAAR,IAAc,GAAf,GAAsBJ,IAAvC;AACAM,QAAAA,CAAC,CAAC,CAAD,CAAD,GAAQ,MAAML,IAAI,CAACM,EAAZ,GAAkBN,IAAI,CAACO,IAAL,CAAUP,IAAI,CAACQ,GAAL,CAAUtB,EAAE,GAAGc,IAAI,CAACM,EAAX,GAAiB,GAA1B,CAAV,CAAlB,GAA8D,EAArE;AACD;AACF;;AACD,WAAO,KAAKnB,UAAL,CAAgBiB,OAAhB,CAAP;AACD;;AApMoC","sourcesContent":["// This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.\nimport Protobuf from 'pbf';\nimport {MvtMapboxCoordinates, MvtMapboxGeometry} from '../types';\nimport {readFeature, classifyRings} from '../../helpers/mapbox-util-functions';\n\nexport default class VectorTileFeature {\n properties: {[x: string]: string | number | boolean | null};\n extent: any;\n type: number;\n id: number | null;\n _pbf: Protobuf;\n _geometry: number;\n _keys: string[];\n _values: (string | number | boolean | null)[];\n static get types() {\n return ['Unknown', 'Point', 'LineString', 'Polygon'];\n }\n\n constructor(\n pbf: Protobuf,\n end: number,\n extent: any,\n keys: string[],\n values: (string | number | boolean | null)[]\n ) {\n // Public\n this.properties = {};\n this.extent = extent;\n this.type = 0;\n this.id = null;\n\n // Private\n this._pbf = pbf;\n this._geometry = -1;\n this._keys = keys;\n this._values = values;\n\n pbf.readFields(readFeature, this, end);\n }\n\n // eslint-disable-next-line complexity, max-statements\n loadGeometry(): MvtMapboxGeometry {\n const pbf = this._pbf;\n pbf.pos = this._geometry;\n\n const end = pbf.readVarint() + pbf.pos;\n let cmd = 1;\n let length = 0;\n let x = 0;\n let y = 0;\n const lines: number[][][] = [];\n let line: number[][] | undefined;\n\n while (pbf.pos < end) {\n if (length <= 0) {\n const cmdLen = pbf.readVarint();\n cmd = cmdLen & 0x7;\n length = cmdLen >> 3;\n }\n\n length--;\n\n if (cmd === 1 || cmd === 2) {\n x += pbf.readSVarint();\n y += pbf.readSVarint();\n\n if (cmd === 1) {\n // moveTo\n if (line) lines.push(line);\n line = [];\n }\n if (line) line.push([x, y]);\n } else if (cmd === 7) {\n // Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90\n if (line) {\n line.push(line[0].slice()); // closePolygon\n }\n } else {\n throw new Error(`unknown command ${cmd}`);\n }\n }\n\n if (line) lines.push(line);\n\n return lines;\n }\n\n // eslint-disable-next-line max-statements\n bbox() {\n const pbf = this._pbf;\n pbf.pos = this._geometry;\n\n const end = pbf.readVarint() + pbf.pos;\n let cmd = 1;\n let length = 0;\n let x = 0;\n let y = 0;\n let x1 = Infinity;\n let x2 = -Infinity;\n let y1 = Infinity;\n let y2 = -Infinity;\n\n while (pbf.pos < end) {\n if (length <= 0) {\n const cmdLen = pbf.readVarint();\n cmd = cmdLen & 0x7;\n length = cmdLen >> 3;\n }\n\n length--;\n\n if (cmd === 1 || cmd === 2) {\n x += pbf.readSVarint();\n y += pbf.readSVarint();\n if (x < x1) x1 = x;\n if (x > x2) x2 = x;\n if (y < y1) y1 = y;\n if (y > y2) y2 = y;\n } else if (cmd !== 7) {\n throw new Error(`unknown command ${cmd}`);\n }\n }\n\n return [x1, y1, x2, y2];\n }\n\n _toGeoJSON(transform) {\n let coords = this.loadGeometry();\n let type = VectorTileFeature.types[this.type];\n let i: number;\n let j: number;\n\n // eslint-disable-next-line default-case\n switch (this.type) {\n case 1:\n const points: number[] = [];\n for (i = 0; i < coords.length; i++) {\n points[i] = coords[i][0];\n }\n coords = points;\n transform(coords, this);\n break;\n\n case 2:\n for (i = 0; i < coords.length; i++) {\n transform(coords[i], this);\n }\n break;\n\n case 3:\n coords = classifyRings(coords);\n for (i = 0; i < coords.length; i++) {\n for (j = 0; j < coords[i].length; j++) {\n transform(coords[i][j], this);\n }\n }\n break;\n }\n\n if (coords.length === 1) {\n coords = coords[0];\n } else {\n type = `Multi${type}`;\n }\n\n const result: MvtMapboxCoordinates = {\n type: 'Feature',\n geometry: {\n type,\n coordinates: coords\n },\n properties: this.properties\n };\n\n if (this.id !== null) {\n result.id = this.id;\n }\n\n return result;\n }\n\n toGeoJSON(\n options: {x: number; y: number; z: number} | ((data: number[], feature: {extent: any}) => void)\n ): MvtMapboxCoordinates {\n if (typeof options === 'function') {\n return this._toGeoJSON(options);\n }\n const {x, y, z} = options;\n const size = this.extent * Math.pow(2, z);\n const x0 = this.extent * x;\n const y0 = this.extent * y;\n\n function project(line: number[]) {\n for (let j = 0; j < line.length; j++) {\n const p = line[j];\n p[0] = ((p[0] + x0) * 360) / size - 180;\n const y2 = 180 - ((p[1] + y0) * 360) / size;\n p[1] = (360 / Math.PI) * Math.atan(Math.exp((y2 * Math.PI) / 180)) - 90;\n }\n }\n return this._toGeoJSON(project);\n }\n}\n"],"file":"vector-tile-feature.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/mapbox-vector-tile/vector-tile-feature.ts"],"names":["readFeature","classifyRings","VectorTileFeature","types","constructor","pbf","end","extent","keys","values","properties","type","id","_pbf","_geometry","_keys","_values","readFields","loadGeometry","pos","readVarint","cmd","length","x","y","lines","line","cmdLen","readSVarint","push","slice","Error","bbox","x1","Infinity","x2","y1","y2","_toGeoJSON","transform","coords","i","j","points","result","geometry","coordinates","toGeoJSON","options","z","size","Math","pow","x0","y0","project","p","PI","atan","exp"],"mappings":";AAGA,SAAQA,WAAR,EAAqBC,aAArB,QAAyC,qCAAzC;AAEA,eAAe,MAAMC,iBAAN,CAAwB;AASrB,aAALC,KAAK,GAAG;AACjB,WAAO,CAAC,SAAD,EAAY,OAAZ,EAAqB,YAArB,EAAmC,SAAnC,CAAP;AACD;;AAEDC,EAAAA,WAAW,CACTC,GADS,EAETC,GAFS,EAGTC,MAHS,EAITC,IAJS,EAKTC,MALS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A,CAAJ;AAAOyB,MAAAA;AAAP,QAAYD,OAAlB;AACA,UAAME,IAAI,GAAG,KAAK3C,MAAL,GAAc4C,IAAI,CAACC,GAAL,CAAS,CAAT,EAAYH,CAAZ,CAA3B;AACA,UAAMI,EAAE,GAAG,KAAK9C,MAAL,GAAcgB,CAAzB;AACA,UAAM+B,EAAE,GAAG,KAAK/C,MAAL,GAAciB,CAAzB;;AAEA,aAAS+B,OAAT,CAAiB7B,IAAjB,EAAiC;AAC/B,WAAK,IAAIgB,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGhB,IAAI,CAACJ,MAAzB,EAAiCoB,CAAC,EAAlC,EAAsC;AACpC,cAAMc,CAAC,GAAG9B,IAAI,CAACgB,CAAD,CAAd;AACAc,QAAAA,CAAC,CAAC,CAAD,CAAD,GAAQ,CAACA,CAAC,CAAC,CAAD,CAAD,GAAOH,EAAR,IAAc,GAAf,GAAsBH,IAAtB,GAA6B,GAApC;AACA,cAAMb,EAAE,GAAG,MAAO,CAACmB,CAAC,CAAC,CAAD,CAAD,GAAOF,EAAR,IAAc,GAAf,GAAsBJ,IAAvC;AACAM,QAAAA,CAAC,CAAC,CAAD,CAAD,GAAQ,MAAML,IAAI,CAACM,EAAZ,GAAkBN,IAAI,CAACO,IAAL,CAAUP,IAAI,CAACQ,GAAL,CAAUtB,EAAE,GAAGc,IAAI,CAACM,EAAX,GAAiB,GAA1B,CAAV,CAAlB,GAA8D,EAArE;AACD;AACF;;AACD,WAAO,KAAKnB,UAAL,CAAgBiB,OAAhB,CAAP;AACD;;AApMoC","sourcesContent":["// This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.\nimport Protobuf from 'pbf';\nimport {MvtMapboxCoordinates, MvtMapboxGeometry} from '../types';\nimport {readFeature, classifyRings} from '../../helpers/mapbox-util-functions';\n\nexport default class VectorTileFeature {\n properties: {[x: string]: string | number | boolean | null};\n extent: any;\n type: number;\n id: number | null;\n _pbf: Protobuf;\n _geometry: number;\n _keys: string[];\n _values: (string | number | boolean | null)[];\n static get types() {\n return ['Unknown', 'Point', 'LineString', 'Polygon'];\n }\n\n constructor(\n pbf: Protobuf,\n end: number,\n extent: any,\n keys: string[],\n values: (string | number | boolean | null)[]\n ) {\n // Public\n this.properties = {};\n this.extent = extent;\n this.type = 0;\n this.id = null;\n\n // Private\n this._pbf = pbf;\n this._geometry = -1;\n this._keys = keys;\n this._values = values;\n\n pbf.readFields(readFeature, this, end);\n }\n\n // eslint-disable-next-line complexity, max-statements\n loadGeometry(): MvtMapboxGeometry {\n const pbf = this._pbf;\n pbf.pos = this._geometry;\n\n const end = pbf.readVarint() + pbf.pos;\n let cmd = 1;\n let length = 0;\n let x = 0;\n let y = 0;\n const lines: number[][][] = [];\n let line: number[][] | undefined;\n\n while (pbf.pos < end) {\n if (length <= 0) {\n const cmdLen = pbf.readVarint();\n cmd = cmdLen & 0x7;\n length = cmdLen >> 3;\n }\n\n length--;\n\n if (cmd === 1 || cmd === 2) {\n x += pbf.readSVarint();\n y += pbf.readSVarint();\n\n if (cmd === 1) {\n // moveTo\n if (line) lines.push(line);\n line = [];\n }\n if (line) line.push([x, y]);\n } else if (cmd === 7) {\n // Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90\n if (line) {\n line.push(line[0].slice()); // closePolygon\n }\n } else {\n throw new Error(`unknown command ${cmd}`);\n }\n }\n\n if (line) lines.push(line);\n\n return lines;\n }\n\n // eslint-disable-next-line max-statements\n bbox() {\n const pbf = this._pbf;\n pbf.pos = this._geometry;\n\n const end = pbf.readVarint() + pbf.pos;\n let cmd = 1;\n let length = 0;\n let x = 0;\n let y = 0;\n let x1 = Infinity;\n let x2 = -Infinity;\n let y1 = Infinity;\n let y2 = -Infinity;\n\n while (pbf.pos < end) {\n if (length <= 0) {\n const cmdLen = pbf.readVarint();\n cmd = cmdLen & 0x7;\n length = cmdLen >> 3;\n }\n\n length--;\n\n if (cmd === 1 || cmd === 2) {\n x += pbf.readSVarint();\n y += pbf.readSVarint();\n if (x < x1) x1 = x;\n if (x > x2) x2 = x;\n if (y < y1) y1 = y;\n if (y > y2) y2 = y;\n } else if (cmd !== 7) {\n throw new Error(`unknown command ${cmd}`);\n }\n }\n\n return [x1, y1, x2, y2];\n }\n\n _toGeoJSON(transform) {\n let coords = this.loadGeometry();\n let type = VectorTileFeature.types[this.type];\n let i: number;\n let j: number;\n\n // eslint-disable-next-line default-case\n switch (this.type) {\n case 1:\n const points: number[] = [];\n for (i = 0; i < coords.length; i++) {\n points[i] = coords[i][0];\n }\n coords = points;\n transform(coords, this);\n break;\n\n case 2:\n for (i = 0; i < coords.length; i++) {\n transform(coords[i], this);\n }\n break;\n\n case 3:\n coords = classifyRings(coords);\n for (i = 0; i < coords.length; i++) {\n for (j = 0; j < coords[i].length; j++) {\n transform(coords[i][j], this);\n }\n }\n break;\n }\n\n if (coords.length === 1) {\n coords = coords[0];\n } else {\n type = `Multi${type}`;\n }\n\n const result: MvtMapboxCoordinates = {\n type: 'Feature',\n geometry: {\n type,\n coordinates: coords\n },\n properties: this.properties\n };\n\n if (this.id !== null) {\n result.id = this.id;\n }\n\n return result;\n }\n\n toGeoJSON(\n options: {x: number; y: number; z: number} | ((data: number[], feature: {extent: any}) => void)\n ): MvtMapboxCoordinates {\n if (typeof options === 'function') {\n return this._toGeoJSON(options);\n }\n const {x, y, z} = options;\n const size = this.extent * Math.pow(2, z);\n const x0 = this.extent * x;\n const y0 = this.extent * y;\n\n function project(line: number[]) {\n for (let j = 0; j < line.length; j++) {\n const p = line[j];\n p[0] = ((p[0] + x0) * 360) / size - 180;\n const y2 = 180 - ((p[1] + y0) * 360) / size;\n p[1] = (360 / Math.PI) * Math.atan(Math.exp((y2 * Math.PI) / 180)) - 90;\n }\n }\n return this._toGeoJSON(project);\n }\n}\n"],"file":"vector-tile-feature.js"}
|
package/dist/mvt-loader.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import parseMVT from './lib/parse-mvt';
|
|
2
|
-
const VERSION = typeof "
|
|
2
|
+
const VERSION = typeof "4.0.0-alpha.1" !== 'undefined' ? "4.0.0-alpha.1" : 'latest';
|
|
3
3
|
export const MVTWorkerLoader = {
|
|
4
4
|
name: 'Mapbox Vector Tile',
|
|
5
5
|
id: 'mvt',
|