@loaders.gl/mvt 3.1.0-beta.2 → 3.1.0
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 +17 -13
- package/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/helpers/binary-util-functions.js +18 -18
- package/dist/es5/helpers/binary-util-functions.js.map +1 -1
- package/dist/es5/helpers/mapbox-util-functions.js +11 -11
- package/dist/es5/helpers/mapbox-util-functions.js.map +1 -1
- package/dist/es5/index.js +2 -2
- package/dist/es5/lib/binary-vector-tile/features-to-binary.js +187 -136
- package/dist/es5/lib/binary-vector-tile/features-to-binary.js.map +1 -1
- package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js +131 -104
- package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js.map +1 -1
- package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js +23 -15
- package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js.map +1 -1
- package/dist/es5/lib/binary-vector-tile/vector-tile.js +8 -8
- package/dist/es5/lib/binary-vector-tile/vector-tile.js.map +1 -1
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js +157 -147
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -1
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js +23 -15
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -1
- package/dist/es5/lib/mapbox-vector-tile/vector-tile.js +8 -8
- package/dist/es5/lib/mapbox-vector-tile/vector-tile.js.map +1 -1
- package/dist/es5/lib/parse-mvt.js +35 -33
- package/dist/es5/lib/parse-mvt.js.map +1 -1
- package/dist/es5/mvt-loader.js +38 -5
- package/dist/es5/mvt-loader.js.map +1 -1
- package/dist/esm/lib/binary-vector-tile/features-to-binary.js +18 -14
- package/dist/esm/lib/binary-vector-tile/features-to-binary.js.map +1 -1
- package/dist/esm/mvt-loader.js +1 -1
- package/dist/esm/mvt-loader.js.map +1 -1
- package/dist/lib/binary-vector-tile/features-to-binary.d.ts +0 -8
- package/dist/lib/binary-vector-tile/features-to-binary.d.ts.map +1 -1
- package/dist/lib/binary-vector-tile/features-to-binary.js +21 -16
- package/dist/lib/types.d.ts +4 -0
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/mvt-worker.js +17 -13
- package/package.json +4 -4
- package/src/lib/binary-vector-tile/features-to-binary.ts +25 -16
- package/src/lib/types.ts +6 -0
|
@@ -7,28 +7,35 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.default = exports.TEST_EXPORTS = void 0;
|
|
9
9
|
|
|
10
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
+
|
|
12
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
+
|
|
10
14
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
15
|
|
|
12
16
|
var _binaryUtilFunctions = require("../../helpers/binary-util-functions");
|
|
13
17
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
19
|
+
|
|
20
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
21
|
+
|
|
22
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
23
|
+
|
|
24
|
+
var endPos;
|
|
25
|
+
var cmd;
|
|
26
|
+
var cmdLen;
|
|
27
|
+
var length;
|
|
28
|
+
var x;
|
|
29
|
+
var y;
|
|
30
|
+
var i;
|
|
31
|
+
var TEST_EXPORTS = {
|
|
22
32
|
classifyRings: _binaryUtilFunctions.classifyRings
|
|
23
33
|
};
|
|
24
34
|
exports.TEST_EXPORTS = TEST_EXPORTS;
|
|
25
35
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
constructor(pbf, end, extent, keys, values, firstPassData) {
|
|
36
|
+
var VectorTileFeature = function () {
|
|
37
|
+
function VectorTileFeature(pbf, end, extent, keys, values, firstPassData) {
|
|
38
|
+
(0, _classCallCheck2.default)(this, VectorTileFeature);
|
|
32
39
|
(0, _defineProperty2.default)(this, "properties", void 0);
|
|
33
40
|
(0, _defineProperty2.default)(this, "extent", void 0);
|
|
34
41
|
(0, _defineProperty2.default)(this, "type", void 0);
|
|
@@ -50,113 +57,133 @@ class VectorTileFeature {
|
|
|
50
57
|
pbf.readFields(_binaryUtilFunctions.readFeature, this, end);
|
|
51
58
|
}
|
|
52
59
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
60
|
+
(0, _createClass2.default)(VectorTileFeature, [{
|
|
61
|
+
key: "loadGeometry",
|
|
62
|
+
value: function loadGeometry() {
|
|
63
|
+
var pbf = this._pbf;
|
|
64
|
+
pbf.pos = this._geometry;
|
|
65
|
+
endPos = pbf.readVarint() + pbf.pos;
|
|
66
|
+
cmd = 1;
|
|
67
|
+
length = 0;
|
|
68
|
+
x = 0;
|
|
69
|
+
y = 0;
|
|
70
|
+
i = 0;
|
|
71
|
+
var lines = [];
|
|
72
|
+
var data = [];
|
|
73
|
+
|
|
74
|
+
while (pbf.pos < endPos) {
|
|
75
|
+
if (length <= 0) {
|
|
76
|
+
cmdLen = pbf.readVarint();
|
|
77
|
+
cmd = cmdLen & 0x7;
|
|
78
|
+
length = cmdLen >> 3;
|
|
79
|
+
}
|
|
71
80
|
|
|
72
|
-
|
|
81
|
+
length--;
|
|
73
82
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
83
|
+
if (cmd === 1 || cmd === 2) {
|
|
84
|
+
x += pbf.readSVarint();
|
|
85
|
+
y += pbf.readSVarint();
|
|
77
86
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
87
|
+
if (cmd === 1) {
|
|
88
|
+
lines.push(i);
|
|
89
|
+
}
|
|
81
90
|
|
|
82
|
-
|
|
83
|
-
i += 2;
|
|
84
|
-
} else if (cmd === 7) {
|
|
85
|
-
if (i > 0) {
|
|
86
|
-
const start = lines[lines.length - 1];
|
|
87
|
-
data.push(data[start], data[start + 1]);
|
|
91
|
+
data.push(x, y);
|
|
88
92
|
i += 2;
|
|
93
|
+
} else if (cmd === 7) {
|
|
94
|
+
if (i > 0) {
|
|
95
|
+
var start = lines[lines.length - 1];
|
|
96
|
+
data.push(data[start], data[start + 1]);
|
|
97
|
+
i += 2;
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
throw new Error("unknown command ".concat(cmd));
|
|
89
101
|
}
|
|
90
|
-
} else {
|
|
91
|
-
throw new Error("unknown command ".concat(cmd));
|
|
92
102
|
}
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
data: data,
|
|
106
|
+
lines: lines
|
|
107
|
+
};
|
|
93
108
|
}
|
|
109
|
+
}, {
|
|
110
|
+
key: "_toBinaryCoordinates",
|
|
111
|
+
value: function _toBinaryCoordinates(transform) {
|
|
112
|
+
var geom = this.loadGeometry();
|
|
113
|
+
transform(geom.data, this);
|
|
114
|
+
var coordLength = 2;
|
|
115
|
+
|
|
116
|
+
switch (this.type) {
|
|
117
|
+
case 1:
|
|
118
|
+
this._firstPassData.pointFeaturesCount++;
|
|
119
|
+
this._firstPassData.pointPositionsCount += geom.lines.length;
|
|
120
|
+
break;
|
|
121
|
+
|
|
122
|
+
case 2:
|
|
123
|
+
this._firstPassData.lineFeaturesCount++;
|
|
124
|
+
this._firstPassData.linePathsCount += geom.lines.length;
|
|
125
|
+
this._firstPassData.linePositionsCount += geom.data.length / coordLength;
|
|
126
|
+
break;
|
|
127
|
+
|
|
128
|
+
case 3:
|
|
129
|
+
var classified = (0, _binaryUtilFunctions.classifyRings)(geom);
|
|
130
|
+
this._firstPassData.polygonFeaturesCount++;
|
|
131
|
+
this._firstPassData.polygonObjectsCount += classified.lines.length;
|
|
132
|
+
|
|
133
|
+
var _iterator = _createForOfIteratorHelper(classified.lines),
|
|
134
|
+
_step;
|
|
135
|
+
|
|
136
|
+
try {
|
|
137
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
138
|
+
var lines = _step.value;
|
|
139
|
+
this._firstPassData.polygonRingsCount += lines.length;
|
|
140
|
+
}
|
|
141
|
+
} catch (err) {
|
|
142
|
+
_iterator.e(err);
|
|
143
|
+
} finally {
|
|
144
|
+
_iterator.f();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
this._firstPassData.polygonPositionsCount += classified.data.length / coordLength;
|
|
148
|
+
geom = classified;
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
94
151
|
|
|
95
|
-
|
|
96
|
-
data,
|
|
97
|
-
lines
|
|
98
|
-
};
|
|
99
|
-
}
|
|
152
|
+
geom.type = VectorTileFeature.types[this.type];
|
|
100
153
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const coordLength = 2;
|
|
105
|
-
|
|
106
|
-
switch (this.type) {
|
|
107
|
-
case 1:
|
|
108
|
-
this._firstPassData.pointFeaturesCount++;
|
|
109
|
-
this._firstPassData.pointPositionsCount += geom.lines.length;
|
|
110
|
-
break;
|
|
111
|
-
|
|
112
|
-
case 2:
|
|
113
|
-
this._firstPassData.lineFeaturesCount++;
|
|
114
|
-
this._firstPassData.linePathsCount += geom.lines.length;
|
|
115
|
-
this._firstPassData.linePositionsCount += geom.data.length / coordLength;
|
|
116
|
-
break;
|
|
117
|
-
|
|
118
|
-
case 3:
|
|
119
|
-
const classified = (0, _binaryUtilFunctions.classifyRings)(geom);
|
|
120
|
-
this._firstPassData.polygonFeaturesCount++;
|
|
121
|
-
this._firstPassData.polygonObjectsCount += classified.lines.length;
|
|
122
|
-
|
|
123
|
-
for (const lines of classified.lines) {
|
|
124
|
-
this._firstPassData.polygonRingsCount += lines.length;
|
|
125
|
-
}
|
|
154
|
+
if (geom.lines.length > 1) {
|
|
155
|
+
geom.type = "Multi".concat(geom.type);
|
|
156
|
+
}
|
|
126
157
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
158
|
+
var result = {
|
|
159
|
+
type: 'Feature',
|
|
160
|
+
geometry: geom,
|
|
161
|
+
properties: this.properties
|
|
162
|
+
};
|
|
131
163
|
|
|
132
|
-
|
|
164
|
+
if (this.id !== null) {
|
|
165
|
+
result.id = this.id;
|
|
166
|
+
}
|
|
133
167
|
|
|
134
|
-
|
|
135
|
-
geom.type = "Multi".concat(geom.type);
|
|
168
|
+
return result;
|
|
136
169
|
}
|
|
170
|
+
}, {
|
|
171
|
+
key: "toBinaryCoordinates",
|
|
172
|
+
value: function toBinaryCoordinates(options) {
|
|
173
|
+
if (typeof options === 'function') {
|
|
174
|
+
return this._toBinaryCoordinates(options);
|
|
175
|
+
}
|
|
137
176
|
|
|
138
|
-
|
|
139
|
-
type: 'Feature',
|
|
140
|
-
geometry: geom,
|
|
141
|
-
properties: this.properties
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
if (this.id !== null) {
|
|
145
|
-
result.id = this.id;
|
|
177
|
+
return this._toBinaryCoordinates(_binaryUtilFunctions.project);
|
|
146
178
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
toBinaryCoordinates(options) {
|
|
152
|
-
if (typeof options === 'function') {
|
|
153
|
-
return this._toBinaryCoordinates(options);
|
|
179
|
+
}], [{
|
|
180
|
+
key: "types",
|
|
181
|
+
get: function get() {
|
|
182
|
+
return ['Unknown', 'Point', 'LineString', 'Polygon'];
|
|
154
183
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
184
|
+
}]);
|
|
185
|
+
return VectorTileFeature;
|
|
186
|
+
}();
|
|
160
187
|
|
|
161
188
|
exports.default = VectorTileFeature;
|
|
162
189
|
//# sourceMappingURL=vector-tile-feature.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/binary-vector-tile/vector-tile-feature.ts"],"names":["endPos","cmd","cmdLen","length","x","y","i","TEST_EXPORTS","classifyRings","VectorTileFeature","types","constructor","pbf","end","extent","keys","values","firstPassData","properties","type","id","_pbf","_geometry","_keys","_values","_firstPassData","readFields","readFeature","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","project"],"mappings":";;;;;;;;;;;AAIA;;AAGA,IAAIA,MAAJ;AACA,IAAIC,GAAJ;AACA,IAAIC,MAAJ;AACA,IAAIC,MAAJ;AACA,IAAIC,CAAJ;AACA,IAAIC,CAAJ;AACA,IAAIC,CAAJ;AAEO,MAAMC,YAAY,GAAG;AAC1BC,EAAAA,aAAa,EAAbA;AAD0B,CAArB;;;AAIQ,MAAMC,iBAAN,CAAwB;AAUrB,aAALC,KAAK,GAAG;AACjB,WAAO,CAAC,SAAD,EAAY,OAAZ,EAAqB,YAArB,EAAmC,SAAnC,CAAP;AACD;;AAGDC,EAAAA,WAAW,CACTC,GADS,EAETC,GAFS,EAGTC,MAHS,EAITC,IAJS,EAKTC,MALS,EAMTC,aANS,EAOT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,SAAKC,UAAL,GAAkB,EAAlB;AACA,SAAKJ,MAAL,GAAcA,MAAd;AACA,SAAKK,IAAL,GAAY,CAAZ;AACA,SAAKC,EAAL,GAAU,IAAV;AAGA,SAAKC,IAAL,GAAYT,GAAZ;AACA,SAAKU,SAAL,GAAiB,CAAC,CAAlB;AACA,SAAKC,KAAL,GAAaR,IAAb;AACA,SAAKS,OAAL,GAAeR,MAAf;AACA,SAAKS,cAAL,GAAsBR,aAAtB;AAEAL,IAAAA,GAAG,CAACc,UAAJ,CAAeC,gCAAf,EAA4B,IAA5B,EAAkCd,GAAlC;AACD;;AAGDe,EAAAA,YAAY,GAAsB;AAChC,UAAMhB,GAAG,GAAG,KAAKS,IAAjB;AACAT,IAAAA,GAAG,CAACiB,GAAJ,GAAU,KAAKP,SAAf;AAEAtB,IAAAA,MAAM,GAAGY,GAAG,CAACkB,UAAJ,KAAmBlB,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Z;;AACA,QAAIoB,IAAI,CAACR,KAAL,CAAW5B,MAAX,GAAoB,CAAxB,EAA2B;AACzBoC,MAAAA,IAAI,CAACpB,IAAL,kBAAoBoB,IAAI,CAACpB,IAAzB;AACD;;AAED,UAAMgC,MAA4B,GAAG;AACnChC,MAAAA,IAAI,EAAE,SAD6B;AAEnCiC,MAAAA,QAAQ,EAAEb,IAFyB;AAGnCrB,MAAAA,UAAU,EAAE,KAAKA;AAHkB,KAArC;;AAMA,QAAI,KAAKE,EAAL,KAAY,IAAhB,EAAsB;AACpB+B,MAAAA,MAAM,CAAC/B,EAAP,GAAY,KAAKA,EAAjB;AACD;;AAED,WAAO+B,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,CAA0BkB,4BAA1B,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":["endPos","cmd","cmdLen","length","x","y","i","TEST_EXPORTS","classifyRings","VectorTileFeature","pbf","end","extent","keys","values","firstPassData","properties","type","id","_pbf","_geometry","_keys","_values","_firstPassData","readFields","readFeature","pos","readVarint","lines","data","readSVarint","push","start","Error","transform","geom","loadGeometry","coordLength","pointFeaturesCount","pointPositionsCount","lineFeaturesCount","linePathsCount","linePositionsCount","classified","polygonFeaturesCount","polygonObjectsCount","polygonRingsCount","polygonPositionsCount","types","result","geometry","options","_toBinaryCoordinates","project"],"mappings":";;;;;;;;;;;;;;;AAIA;;;;;;;;AAGA,IAAIA,MAAJ;AACA,IAAIC,GAAJ;AACA,IAAIC,MAAJ;AACA,IAAIC,MAAJ;AACA,IAAIC,CAAJ;AACA,IAAIC,CAAJ;AACA,IAAIC,CAAJ;AAEO,IAAMC,YAAY,GAAG;AAC1BC,EAAAA,aAAa,EAAbA;AAD0B,CAArB;;;IAIcC,iB;AAenB,6BACEC,GADF,EAEEC,GAFF,EAGEC,MAHF,EAIEC,IAJF,EAKEC,MALF,EAMEC,aANF,EAOE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,SAAKC,UAAL,GAAkB,EAAlB;AACA,SAAKJ,MAAL,GAAcA,MAAd;AACA,SAAKK,IAAL,GAAY,CAAZ;AACA,SAAKC,EAAL,GAAU,IAAV;AAGA,SAAKC,IAAL,GAAYT,GAAZ;AACA,SAAKU,SAAL,GAAiB,CAAC,CAAlB;AACA,SAAKC,KAAL,GAAaR,IAAb;AACA,SAAKS,OAAL,GAAeR,MAAf;AACA,SAAKS,cAAL,GAAsBR,aAAtB;AAEAL,IAAAA,GAAG,CAACc,UAAJ,CAAeC,gCAAf,EAA4B,IAA5B,EAAkCd,GAAlC;AACD;;;;WAGD,wBAAkC;AAChC,UAAMD,GAAG,GAAG,KAAKS,IAAjB;AACAT,MAAAA,GAAG,CAACgB,GAAJ,GAAU,KAAKN,SAAf;AAEApB,MAAAA,MAAM,GAAGU,GAAG,CAACiB,UAAJ,KAAmBjB,GAAG,CAACgB,GAAhC;AACAzB,MAAAA,GAAG,GAAG,CAAN;AACAE,MAAAA,MAAM,GAAG,CAAT;AACAC,MAAAA,CAAC,GAAG,C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CAAWzB,MAAX,GAAoB,CAAxB,EAA2B;AACzBgC,QAAAA,IAAI,CAAClB,IAAL,kBAAoBkB,IAAI,CAAClB,IAAzB;AACD;;AAED,UAAMgC,MAA4B,GAAG;AACnChC,QAAAA,IAAI,EAAE,SAD6B;AAEnCiC,QAAAA,QAAQ,EAAEf,IAFyB;AAGnCnB,QAAAA,UAAU,EAAE,KAAKA;AAHkB,OAArC;;AAMA,UAAI,KAAKE,EAAL,KAAY,IAAhB,EAAsB;AACpB+B,QAAAA,MAAM,CAAC/B,EAAP,GAAY,KAAKA,EAAjB;AACD;;AAED,aAAO+B,MAAP;AACD;;;WAED,6BACEE,OADF,EAEwB;AACtB,UAAI,OAAOA,OAAP,KAAmB,UAAvB,EAAmC;AACjC,eAAO,KAAKC,oBAAL,CAA0BD,OAA1B,CAAP;AACD;;AACD,aAAO,KAAKC,oBAAL,CAA0BC,4BAA1B,CAAP;AACD;;;SA3KD,eAAmB;AACjB,aAAO,CAAC,SAAD,EAAY,OAAZ,EAAqB,YAArB,EAAmC,SAAnC,CAAP;AACD","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"}
|
|
@@ -7,12 +7,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
9
|
|
|
10
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
+
|
|
12
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
+
|
|
10
14
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
15
|
|
|
12
16
|
var _vectorTileFeature = _interopRequireDefault(require("./vector-tile-feature"));
|
|
13
17
|
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
var VectorTileLayer = function () {
|
|
19
|
+
function VectorTileLayer(pbf, end) {
|
|
20
|
+
(0, _classCallCheck2.default)(this, VectorTileLayer);
|
|
16
21
|
(0, _defineProperty2.default)(this, "version", void 0);
|
|
17
22
|
(0, _defineProperty2.default)(this, "name", void 0);
|
|
18
23
|
(0, _defineProperty2.default)(this, "extent", void 0);
|
|
@@ -33,19 +38,22 @@ class VectorTileLayer {
|
|
|
33
38
|
this.length = this._features.length;
|
|
34
39
|
}
|
|
35
40
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
(0, _createClass2.default)(VectorTileLayer, [{
|
|
42
|
+
key: "feature",
|
|
43
|
+
value: function feature(i, firstPassData) {
|
|
44
|
+
if (i < 0 || i >= this._features.length) {
|
|
45
|
+
throw new Error('feature index out of bounds');
|
|
46
|
+
}
|
|
40
47
|
|
|
41
|
-
|
|
48
|
+
this._pbf.pos = this._features[i];
|
|
42
49
|
|
|
43
|
-
|
|
50
|
+
var end = this._pbf.readVarint() + this._pbf.pos;
|
|
44
51
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
52
|
+
return new _vectorTileFeature.default(this._pbf, end, this.extent, this._keys, this._values, firstPassData);
|
|
53
|
+
}
|
|
54
|
+
}]);
|
|
55
|
+
return VectorTileLayer;
|
|
56
|
+
}();
|
|
49
57
|
|
|
50
58
|
exports.default = VectorTileLayer;
|
|
51
59
|
|
|
@@ -56,11 +64,11 @@ function readLayer(tag, layer, pbf) {
|
|
|
56
64
|
}
|
|
57
65
|
|
|
58
66
|
function readValueMessage(pbf) {
|
|
59
|
-
|
|
60
|
-
|
|
67
|
+
var value = null;
|
|
68
|
+
var end = pbf.readVarint() + pbf.pos;
|
|
61
69
|
|
|
62
70
|
while (pbf.pos < end) {
|
|
63
|
-
|
|
71
|
+
var tag = pbf.readVarint() >> 3;
|
|
64
72
|
value = tag === 1 ? pbf.readString() : tag === 2 ? pbf.readFloat() : tag === 3 ? pbf.readDouble() : tag === 4 ? pbf.readVarint64() : tag === 5 ? pbf.readVarint() : tag === 6 ? pbf.readSVarint() : tag === 7 ? pbf.readBoolean() : null;
|
|
65
73
|
}
|
|
66
74
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/binary-vector-tile/vector-tile-layer.ts"],"names":["VectorTileLayer","
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/binary-vector-tile/vector-tile-layer.ts"],"names":["VectorTileLayer","pbf","end","version","name","extent","length","_pbf","_keys","_values","_features","readFields","readLayer","i","firstPassData","Error","pos","readVarint","VectorTileFeature","tag","layer","readString","push","readValueMessage","value","readFloat","readDouble","readVarint64","readSVarint","readBoolean"],"mappings":";;;;;;;;;;;;;;;AAGA;;IAIqBA,e;AASnB,2BAAYC,GAAZ,EAA2BC,GAA3B,EAAwC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEtC,SAAKC,OAAL,GAAe,CAAf;AACA,SAAKC,IAAL,GAAY,EAAZ;AACA,SAAKC,MAAL,GAAc,IAAd;AACA,SAAKC,MAAL,GAAc,CAAd;AAGA,SAAKC,IAAL,GAAYN,GAAZ;AACA,SAAKO,KAAL,GAAa,EAAb;AACA,SAAKC,OAAL,GAAe,EAAf;AACA,SAAKC,SAAL,GAAiB,EAAjB;AAEAT,IAAAA,GAAG,CAACU,UAAJ,CAAeC,SAAf,EAA0B,IAA1B,EAAgCV,GAAhC;AAEA,SAAKI,MAAL,GAAc,KAAKI,SAAL,CAAeJ,MAA7B;AACD;;;;WASD,i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AOD,SAASsB,gBAAT,CAA0BtB,GAA1B,EAAyC;AACvC,MAAIuB,KAAuC,GAAG,IAA9C;AACA,MAAMtB,GAAG,GAAGD,GAAG,CAACgB,UAAJ,KAAmBhB,GAAG,CAACe,GAAnC;;AAEA,SAAOf,GAAG,CAACe,GAAJ,GAAUd,GAAjB,EAAsB;AACpB,QAAMiB,GAAG,GAAGlB,GAAG,CAACgB,UAAJ,MAAoB,CAAhC;AAEAO,IAAAA,KAAK,GACHL,GAAG,KAAK,CAAR,GACIlB,GAAG,CAACoB,UAAJ,EADJ,GAEIF,GAAG,KAAK,CAAR,GACAlB,GAAG,CAACwB,SAAJ,EADA,GAEAN,GAAG,KAAK,CAAR,GACAlB,GAAG,CAACyB,UAAJ,EADA,GAEAP,GAAG,KAAK,CAAR,GACAlB,GAAG,CAAC0B,YAAJ,EADA,GAEAR,GAAG,KAAK,CAAR,GACAlB,GAAG,CAACgB,UAAJ,EADA,GAEAE,GAAG,KAAK,CAAR,GACAlB,GAAG,CAAC2B,WAAJ,EADA,GAEAT,GAAG,KAAK,CAAR,GACAlB,GAAG,CAAC4B,WAAJ,EADA,GAEA,IAfN;AAgBD;;AAED,SAAOL,KAAP;AACD","sourcesContent":["/* eslint-disable indent */\n// This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.\n\nimport VectorTileFeature from './vector-tile-feature';\nimport Protobuf from 'pbf';\nimport {MvtFirstPassedData} from '../types';\n\nexport default class VectorTileLayer {\n version: number;\n name: string;\n extent: number;\n length: number;\n _pbf: Protobuf;\n _keys: string[];\n _values: (string | number | boolean | null)[];\n _features: number[];\n constructor(pbf: Protobuf, end: number) {\n // Public\n this.version = 1;\n this.name = '';\n this.extent = 4096;\n this.length = 0;\n\n // Private\n this._pbf = pbf;\n this._keys = [];\n this._values = [];\n this._features = [];\n\n pbf.readFields(readLayer, this, end);\n\n this.length = this._features.length;\n }\n\n /**\n * return feature `i` from this layer as a `VectorTileFeature`\n *\n * @param index\n * @param firstPassData\n * @returns {VectorTileFeature}\n */\n feature(i: number, firstPassData: MvtFirstPassedData): VectorTileFeature {\n if (i < 0 || i >= this._features.length) {\n throw new Error('feature index out of bounds');\n }\n\n this._pbf.pos = this._features[i];\n\n const end = this._pbf.readVarint() + this._pbf.pos;\n return new VectorTileFeature(\n this._pbf,\n end,\n this.extent,\n this._keys,\n this._values,\n firstPassData\n );\n }\n}\n\n/**\n *\n * @param tag\n * @param layer\n * @param pbf\n */\nfunction readLayer(tag: number, layer?: VectorTileLayer, pbf?: Protobuf): void {\n if (layer && pbf) {\n if (tag === 15) layer.version = pbf.readVarint();\n else if (tag === 1) layer.name = pbf.readString();\n else if (tag === 5) layer.extent = pbf.readVarint();\n else if (tag === 2) layer._features.push(pbf.pos);\n else if (tag === 3) layer._keys.push(pbf.readString());\n else if (tag === 4) layer._values.push(readValueMessage(pbf));\n }\n}\n\n/**\n *\n * @param pbf\n * @returns value\n */\nfunction readValueMessage(pbf: Protobuf) {\n let value: string | number | boolean | null = null;\n const end = pbf.readVarint() + pbf.pos;\n\n while (pbf.pos < end) {\n const tag = pbf.readVarint() >> 3;\n\n value =\n tag === 1\n ? pbf.readString()\n : tag === 2\n ? pbf.readFloat()\n : tag === 3\n ? pbf.readDouble()\n : tag === 4\n ? pbf.readVarint64()\n : tag === 5\n ? pbf.readVarint()\n : tag === 6\n ? pbf.readSVarint()\n : tag === 7\n ? pbf.readBoolean()\n : null;\n }\n\n return value;\n}\n"],"file":"vector-tile-layer.js"}
|
|
@@ -7,24 +7,24 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
9
|
|
|
10
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
+
|
|
10
12
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
13
|
|
|
12
14
|
var _vectorTileLayer = _interopRequireDefault(require("./vector-tile-layer"));
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
16
|
+
var VectorTile = function VectorTile(pbf, end) {
|
|
17
|
+
(0, _classCallCheck2.default)(this, VectorTile);
|
|
18
|
+
(0, _defineProperty2.default)(this, "layers", void 0);
|
|
19
|
+
this.layers = pbf.readFields(readTile, {}, end);
|
|
20
|
+
};
|
|
21
21
|
|
|
22
22
|
exports.default = VectorTile;
|
|
23
23
|
|
|
24
24
|
function readTile(tag, layers, pbf) {
|
|
25
25
|
if (tag === 3) {
|
|
26
26
|
if (pbf) {
|
|
27
|
-
|
|
27
|
+
var layer = new _vectorTileLayer.default(pbf, pbf.readVarint() + pbf.pos);
|
|
28
28
|
|
|
29
29
|
if (layer.length && layers) {
|
|
30
30
|
layers[layer.name] = layer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/binary-vector-tile/vector-tile.ts"],"names":["VectorTile","
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/binary-vector-tile/vector-tile.ts"],"names":["VectorTile","pbf","end","layers","readFields","readTile","tag","layer","VectorTileLayer","readVarint","pos","length","name"],"mappings":";;;;;;;;;;;;;AAEA;;IAGqBA,U,GAEnB,oBAAYC,GAAZ,EAA2BC,GAA3B,EAAyC;AAAA;AAAA;AACvC,OAAKC,MAAL,GAAcF,GAAG,CAACG,UAAJ,CAAeC,QAAf,EAAyB,EAAzB,EAA6BH,GAA7B,CAAd;AACD,C;;;;AASH,SAASG,QAAT,CAAkBC,GAAlB,EAA+BH,MAA/B,EAAwEF,GAAxE,EAA8F;AAC5F,MAAIK,GAAG,KAAK,CAAZ,EAAe;AACb,QAAIL,GAAJ,EAAS;AACP,UAAMM,KAAK,GAAG,IAAIC,wBAAJ,CAAoBP,GAApB,EAAyBA,GAAG,CAACQ,UAAJ,KAAmBR,GAAG,CAACS,GAAhD,CAAd;;AACA,UAAIH,KAAK,CAACI,MAAN,IAAgBR,MAApB,EAA4B;AAC1BA,QAAAA,MAAM,CAACI,KAAK,CAACK,IAAP,CAAN,GAAqBL,KAArB;AACD;AACF;AACF;AACF","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"],"file":"vector-tile.js"}
|