@loaders.gl/gis 3.1.0-alpha.4 → 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/{esm/bundle.js → bundle.js} +0 -0
- package/dist/bundle.js.map +1 -0
- package/dist/{esm/index.js → index.js} +0 -0
- package/dist/index.js.map +1 -0
- package/dist/{esm/lib → lib}/binary-to-geojson.js +2 -2
- package/dist/lib/binary-to-geojson.js.map +1 -0
- package/dist/{esm/lib → lib}/geojson-to-binary.js +1 -1
- package/dist/lib/geojson-to-binary.js.map +1 -0
- package/dist/{esm/lib → lib}/transform.js +0 -0
- package/dist/lib/transform.js.map +1 -0
- package/package.json +6 -6
- package/dist/es5/bundle.js +0 -7
- package/dist/es5/bundle.js.map +0 -1
- package/dist/es5/index.js +0 -48
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/lib/binary-to-geojson.js +0 -330
- package/dist/es5/lib/binary-to-geojson.js.map +0 -1
- package/dist/es5/lib/geojson-to-binary.js +0 -587
- package/dist/es5/lib/geojson-to-binary.js.map +0 -1
- package/dist/es5/lib/transform.js +0 -73
- package/dist/es5/lib/transform.js.map +0 -1
- package/dist/esm/bundle.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/lib/binary-to-geojson.js.map +0 -1
- package/dist/esm/lib/geojson-to-binary.js.map +0 -1
- package/dist/esm/lib/transform.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/binary-to-geojson.ts"],"names":["binaryToGeojson","data","options","globalFeatureId","undefined","getSingleFeature","parseFeatures","type","binaryToGeoJson","format","binaryToGeometry","Error","dataArray","normalizeInput","lastIndex","lastValue","featureIds","value","i","length","currValue","globalFeatureIds","parseFeature","parseFeatureCollection","startIndex","endIndex","pointToGeoJson","lineStringToGeoJson","polygonToGeoJson","unexpectedInput","isHeterogeneousType","Boolean","points","lines","polygons","parseType","features","push","geometry","properties","parseProperties","fields","parseFields","Object","assign","key","numericProps","Infinity","positions","polygonIndices","filter","x","primitivePolygonIndices","multi","coordinates","startRingIndex","endRingIndex","ringCoordinates","ringToGeoJson","startPolygonIndex","endPolygonIndex","polygonCoordinates","pathIndices","size","j","coord","Array","k","Number"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAmCO,SAASA,eAAT,CACLC,IADK,EAELC,OAFK,EAGgB;AACrB,MAAMC,eAAe,GAAGD,OAAH,aAAGA,OAAH,uBAAGA,OAAO,CAAEC,eAAjC;;AACA,MAAIA,eAAe,KAAKC,SAAxB,EAAmC;AACjC,WAAOC,gBAAgB,CAACJ,IAAD,EAAOE,eAAP,CAAvB;AACD;;AACD,SAAOG,aAAa,CAACL,IAAD,EAAOC,OAAP,aAAOA,OAAP,uBAAOA,OAAO,CAAEK,IAAhB,CAApB;AACD;;AAGM,SAASC,eAAT,CACLP,IADK,EAELM,IAFK,EAIiB;AAAA,MADtBE,MACsB,uEADW,SACX;;AACtB,UAAQA,MAAR;AACE,SAAK,SAAL;AACE,aAAOH,aAAa,CAACL,IAAD,EAAyBM,IAAzB,CAApB;;AACF,SAAK,UAAL;AACE,aAAOG,gBAAgB,CAACT,IAAD,CAAvB;;AACF;AACE,YAAM,IAAIU,KAAJ,CAAUF,MAAV,CAAN;AANJ;AAQD;;AAOD,SAASJ,gBAAT,CAA0BJ,IAA1B,EAAgDE,eAAhD,EAAkF;AAChF,MAAMS,SAAS,GAAGC,cAAc,CAACZ,IAAD,CAAhC;;AADgF,6CAE7DW,SAF6D;AAAA;;AAAA;AAEhF,wDAA8B;AAAA,UAAnBX,KAAmB;AAC5B,UAAIa,SAAS,GAAG,CAAhB;AACA,UAAIC,SAAS,GAAGd,KAAI,CAACe,UAAL,CAAgBC,KAAhB,CAAsB,CAAtB,CAAhB;;AAGA,WAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGjB,KAAI,CAACe,UAAL,CAAgBC,KAAhB,CAAsBE,MAA1C,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ACvB,MAAIA,IAAI,CAAC6D,WAAT,EAAsB;AACpB,WAAO,YAAP;AACD;;AAED,MAAI7D,IAAI,CAACgD,cAAT,EAAyB;AACvB,WAAO,SAAP;AACD;;AAED,SAAO,OAAP;AACD","sourcesContent":["import type {\n BinaryGeometry,\n BinaryFeatures,\n BinaryGeometryType,\n BinaryPointFeatures,\n BinaryLineFeatures,\n BinaryPolygonFeatures,\n BinaryAttribute\n} from '@loaders.gl/schema';\nimport type {Feature, Geometry, Position, GeoJsonProperties} from '@loaders.gl/schema';\nimport type {\n Point,\n MultiPoint,\n LineString,\n MultiLineString,\n Polygon,\n MultiPolygon\n} from '@loaders.gl/schema';\n\n// Note:L We do not handle GeometryCollection, define a limited Geometry type that always has coordinates.\n// type FeatureGeometry = Point | MultiPoint | LineString | MultiLineString | Polygon | MultiPolygon;\n\ntype BinaryToGeoJsonOptions = {\n type?: BinaryGeometryType;\n globalFeatureId?: number;\n};\n\n/**\n * Convert binary geometry representation to GeoJSON\n * @param data geometry data in binary representation\n * @param options\n * @param options.type Input data type: Point, LineString, or Polygon\n * @param options.featureId Global feature id. If specified, only a single feature is extracted\n * @return GeoJSON objects\n */\nexport function binaryToGeojson(\n data: BinaryFeatures,\n options?: BinaryToGeoJsonOptions\n): Feature[] | Feature {\n const globalFeatureId = options?.globalFeatureId;\n if (globalFeatureId !== undefined) {\n return getSingleFeature(data, globalFeatureId);\n }\n return parseFeatures(data, options?.type);\n}\n\n/** @deprecated use `binaryToGeojson` or `binaryToGeometry` instead */\nexport function binaryToGeoJson(\n data: BinaryGeometry | BinaryFeatures,\n type?: BinaryGeometryType,\n format: 'feature' | 'geometry' = 'feature'\n): Geometry | Feature[] {\n switch (format) {\n case 'feature':\n return parseFeatures(data as BinaryFeatures, type);\n case 'geometry':\n return binaryToGeometry(data as BinaryGeometry);\n default:\n throw new Error(format);\n }\n}\n\n/**\n * Return a single feature from a binary geometry representation as GeoJSON\n * @param data geometry data in binary representation\n * @return GeoJSON feature\n */\nfunction getSingleFeature(data: BinaryFeatures, globalFeatureId: number): Feature {\n const dataArray = normalizeInput(data);\n for (const data of dataArray) {\n let lastIndex = 0;\n let lastValue = data.featureIds.value[0];\n\n // Scan through data until we find matching feature\n for (let i = 0; i < data.featureIds.value.length; i++) {\n const currValue = data.featureIds.value[i];\n if (currValue === lastValue) {\n // eslint-disable-next-line no-continue\n continue;\n }\n if (globalFeatureId === data.globalFeatureIds.value[lastIndex]) {\n return parseFeature(data, lastIndex, i);\n }\n lastIndex = i;\n lastValue = currValue;\n }\n\n if (globalFeatureId === data.globalFeatureIds.value[lastIndex]) {\n return parseFeature(data, lastIndex, data.featureIds.value.length);\n }\n }\n\n throw new Error(`featureId:${globalFeatureId} not found`);\n}\n\nfunction parseFeatures(data: BinaryFeatures, type?: BinaryGeometryType): Feature[] {\n const dataArray = normalizeInput(data, type);\n return parseFeatureCollection(dataArray);\n}\n\n/** Parse input binary data and return a valid GeoJSON geometry object */\nexport function binaryToGeometry(\n data: BinaryGeometry,\n startIndex?: number,\n endIndex?: number\n): Geometry {\n switch (data.type) {\n case 'Point':\n return pointToGeoJson(data, startIndex, endIndex);\n case 'LineString':\n return lineStringToGeoJson(data, startIndex, endIndex);\n case 'Polygon':\n return polygonToGeoJson(data, startIndex, endIndex);\n default:\n const unexpectedInput: never = data;\n throw new Error(`Unsupported geometry type: ${(unexpectedInput as any)?.type}`);\n }\n}\n\ntype BinaryFeature = BinaryPointFeatures | BinaryLineFeatures | BinaryPolygonFeatures;\ntype BinaryFeaturesArray = BinaryFeature[];\n\n// Normalize features\n// Return an array of data objects, each of which have a type key\nfunction normalizeInput(data: BinaryFeatures, type?: BinaryGeometryType): BinaryFeaturesArray {\n const isHeterogeneousType = Boolean(data.points || data.lines || data.polygons);\n\n if (!isHeterogeneousType) {\n // @ts-expect-error This is a legacy check which allowed `data` to be an instance of the values\n // here. Aka the new data.points, data.lines, or data.polygons.\n data.type = type || parseType(data);\n return [data] as BinaryFeaturesArray;\n }\n\n const features: BinaryFeaturesArray = [];\n if (data.points) {\n data.points.type = 'Point';\n features.push(data.points);\n }\n if (data.lines) {\n data.lines.type = 'LineString';\n features.push(data.lines);\n }\n if (data.polygons) {\n data.polygons.type = 'Polygon';\n features.push(data.polygons);\n }\n\n return features;\n}\n\n/** Parse input binary data and return an array of GeoJSON Features */\nfunction parseFeatureCollection(dataArray): Feature[] {\n const features: Feature[] = [];\n for (const data of dataArray) {\n if (data.featureIds.value.length === 0) {\n // eslint-disable-next-line no-continue\n continue;\n }\n let lastIndex = 0;\n let lastValue = data.featureIds.value[0];\n\n // Need to deduce start, end indices of each feature\n for (let i = 0; i < data.featureIds.value.length; i++) {\n const currValue = data.featureIds.value[i];\n if (currValue === lastValue) {\n // eslint-disable-next-line no-continue\n continue;\n }\n\n features.push(parseFeature(data, lastIndex, i));\n lastIndex = i;\n lastValue = currValue;\n }\n\n // Last feature\n features.push(parseFeature(data, lastIndex, data.featureIds.value.length));\n }\n return features;\n}\n\n/** Parse input binary data and return a single GeoJSON Feature */\nfunction parseFeature(data, startIndex?: number, endIndex?: number): Feature {\n const geometry = binaryToGeometry(data, startIndex, endIndex);\n const properties = parseProperties(data, startIndex, endIndex);\n const fields = parseFields(data, startIndex, endIndex);\n return {type: 'Feature', geometry, properties, ...fields};\n}\n\n/** Parse input binary data and return an object of fields */\nfunction parseFields(data, startIndex: number = 0, endIndex?: number): GeoJsonProperties {\n return data.fields && data.fields[data.featureIds.value[startIndex]];\n}\n\n/** Parse input binary data and return an object of properties */\nfunction parseProperties(data, startIndex: number = 0, endIndex?: number): GeoJsonProperties {\n const properties = Object.assign({}, data.properties[data.featureIds.value[startIndex]]);\n for (const key in data.numericProps) {\n properties[key] = data.numericProps[key].value[startIndex];\n }\n return properties;\n}\n\n/** Parse binary data of type Polygon */\nfunction polygonToGeoJson(\n data,\n startIndex: number = -Infinity,\n endIndex: number = Infinity\n): Polygon | MultiPolygon {\n const {positions} = data;\n const polygonIndices = data.polygonIndices.value.filter((x) => x >= startIndex && x <= endIndex);\n const primitivePolygonIndices = data.primitivePolygonIndices.value.filter(\n (x) => x >= startIndex && x <= endIndex\n );\n const multi = polygonIndices.length > 2;\n\n // Polygon\n if (!multi) {\n const coordinates: Position[][] = [];\n for (let i = 0; i < primitivePolygonIndices.length - 1; i++) {\n const startRingIndex = primitivePolygonIndices[i];\n const endRingIndex = primitivePolygonIndices[i + 1];\n const ringCoordinates = ringToGeoJson(positions, startRingIndex, endRingIndex);\n coordinates.push(ringCoordinates);\n }\n\n return {type: 'Polygon', coordinates};\n }\n\n // MultiPolygon\n const coordinates: Position[][][] = [];\n for (let i = 0; i < polygonIndices.length - 1; i++) {\n const startPolygonIndex = polygonIndices[i];\n const endPolygonIndex = polygonIndices[i + 1];\n const polygonCoordinates = polygonToGeoJson(\n data,\n startPolygonIndex,\n endPolygonIndex\n ).coordinates;\n coordinates.push(polygonCoordinates as Position[][]);\n }\n\n return {type: 'MultiPolygon', coordinates};\n}\n\n/** Parse binary data of type LineString */\nfunction lineStringToGeoJson(\n data,\n startIndex: number = -Infinity,\n endIndex: number = Infinity\n): LineString | MultiLineString {\n const {positions} = data;\n const pathIndices = data.pathIndices.value.filter((x) => x >= startIndex && x <= endIndex);\n const multi = pathIndices.length > 2;\n\n if (!multi) {\n const coordinates = ringToGeoJson(positions, pathIndices[0], pathIndices[1]);\n return {type: 'LineString', coordinates};\n }\n\n const coordinates: Position[][] = [];\n for (let i = 0; i < pathIndices.length - 1; i++) {\n const ringCoordinates = ringToGeoJson(positions, pathIndices[i], pathIndices[i + 1]);\n coordinates.push(ringCoordinates);\n }\n\n return {type: 'MultiLineString', coordinates};\n}\n\n/** Parse binary data of type Point */\nfunction pointToGeoJson(data, startIndex, endIndex): Point | MultiPoint {\n const {positions} = data;\n const coordinates = ringToGeoJson(positions, startIndex, endIndex);\n const multi = coordinates.length > 1;\n\n if (multi) {\n return {type: 'MultiPoint', coordinates};\n }\n\n return {type: 'Point', coordinates: coordinates[0]};\n}\n\n/**\n * Parse a linear ring of positions to a GeoJSON linear ring\n *\n * @param positions Positions TypedArray\n * @param startIndex Start index to include in ring\n * @param endIndex End index to include in ring\n * @returns GeoJSON ring\n */\nfunction ringToGeoJson(\n positions: BinaryAttribute,\n startIndex?: number,\n endIndex?: number\n): Position[] {\n startIndex = startIndex || 0;\n endIndex = endIndex || positions.value.length / positions.size;\n\n const ringCoordinates: Position[] = [];\n for (let j = startIndex; j < endIndex; j++) {\n const coord = Array<number>();\n for (let k = j * positions.size; k < (j + 1) * positions.size; k++) {\n coord.push(Number(positions.value[k]));\n }\n ringCoordinates.push(coord);\n }\n return ringCoordinates;\n}\n\n// Deduce geometry type of data object\nfunction parseType(data) {\n if (data.pathIndices) {\n return 'LineString';\n }\n\n if (data.polygonIndices) {\n return 'Polygon';\n }\n\n return 'Point';\n}\n"],"file":"binary-to-geojson.js"}
|
|
@@ -1,587 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.geojsonToBinary = geojsonToBinary;
|
|
9
|
-
exports.TEST_EXPORTS = void 0;
|
|
10
|
-
|
|
11
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
12
|
-
|
|
13
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
14
|
-
|
|
15
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
16
|
-
|
|
17
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
18
|
-
|
|
19
|
-
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; } } }; }
|
|
20
|
-
|
|
21
|
-
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); }
|
|
22
|
-
|
|
23
|
-
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; }
|
|
24
|
-
|
|
25
|
-
function geojsonToBinary(features) {
|
|
26
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
27
|
-
var firstPassData = firstPass(features);
|
|
28
|
-
return secondPass(features, firstPassData, {
|
|
29
|
-
coordLength: options.coordLength || firstPassData.coordLength,
|
|
30
|
-
numericPropKeys: options.numericPropKeys || firstPassData.numericPropKeys,
|
|
31
|
-
PositionDataType: options.PositionDataType || Float32Array
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
var TEST_EXPORTS = {
|
|
36
|
-
firstPass: firstPass,
|
|
37
|
-
secondPass: secondPass
|
|
38
|
-
};
|
|
39
|
-
exports.TEST_EXPORTS = TEST_EXPORTS;
|
|
40
|
-
|
|
41
|
-
function firstPass(features) {
|
|
42
|
-
var pointPositionsCount = 0;
|
|
43
|
-
var pointFeaturesCount = 0;
|
|
44
|
-
var linePositionsCount = 0;
|
|
45
|
-
var linePathsCount = 0;
|
|
46
|
-
var lineFeaturesCount = 0;
|
|
47
|
-
var polygonPositionsCount = 0;
|
|
48
|
-
var polygonObjectsCount = 0;
|
|
49
|
-
var polygonRingsCount = 0;
|
|
50
|
-
var polygonFeaturesCount = 0;
|
|
51
|
-
var coordLengths = new Set();
|
|
52
|
-
var numericPropKeys = {};
|
|
53
|
-
|
|
54
|
-
var _iterator = _createForOfIteratorHelper(features),
|
|
55
|
-
_step;
|
|
56
|
-
|
|
57
|
-
try {
|
|
58
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
59
|
-
var feature = _step.value;
|
|
60
|
-
var geometry = feature.geometry;
|
|
61
|
-
|
|
62
|
-
switch (geometry.type) {
|
|
63
|
-
case 'Point':
|
|
64
|
-
pointFeaturesCount++;
|
|
65
|
-
pointPositionsCount++;
|
|
66
|
-
coordLengths.add(geometry.coordinates.length);
|
|
67
|
-
break;
|
|
68
|
-
|
|
69
|
-
case 'MultiPoint':
|
|
70
|
-
pointFeaturesCount++;
|
|
71
|
-
pointPositionsCount += geometry.coordinates.length;
|
|
72
|
-
|
|
73
|
-
var _iterator2 = _createForOfIteratorHelper(geometry.coordinates),
|
|
74
|
-
_step2;
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
78
|
-
var point = _step2.value;
|
|
79
|
-
coordLengths.add(point.length);
|
|
80
|
-
}
|
|
81
|
-
} catch (err) {
|
|
82
|
-
_iterator2.e(err);
|
|
83
|
-
} finally {
|
|
84
|
-
_iterator2.f();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
break;
|
|
88
|
-
|
|
89
|
-
case 'LineString':
|
|
90
|
-
lineFeaturesCount++;
|
|
91
|
-
linePositionsCount += geometry.coordinates.length;
|
|
92
|
-
linePathsCount++;
|
|
93
|
-
|
|
94
|
-
var _iterator3 = _createForOfIteratorHelper(geometry.coordinates),
|
|
95
|
-
_step3;
|
|
96
|
-
|
|
97
|
-
try {
|
|
98
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
99
|
-
var coord = _step3.value;
|
|
100
|
-
coordLengths.add(coord.length);
|
|
101
|
-
}
|
|
102
|
-
} catch (err) {
|
|
103
|
-
_iterator3.e(err);
|
|
104
|
-
} finally {
|
|
105
|
-
_iterator3.f();
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
break;
|
|
109
|
-
|
|
110
|
-
case 'MultiLineString':
|
|
111
|
-
lineFeaturesCount++;
|
|
112
|
-
|
|
113
|
-
var _iterator4 = _createForOfIteratorHelper(geometry.coordinates),
|
|
114
|
-
_step4;
|
|
115
|
-
|
|
116
|
-
try {
|
|
117
|
-
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
118
|
-
var line = _step4.value;
|
|
119
|
-
linePositionsCount += line.length;
|
|
120
|
-
linePathsCount++;
|
|
121
|
-
|
|
122
|
-
var _iterator5 = _createForOfIteratorHelper(line),
|
|
123
|
-
_step5;
|
|
124
|
-
|
|
125
|
-
try {
|
|
126
|
-
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
127
|
-
var _coord = _step5.value;
|
|
128
|
-
coordLengths.add(_coord.length);
|
|
129
|
-
}
|
|
130
|
-
} catch (err) {
|
|
131
|
-
_iterator5.e(err);
|
|
132
|
-
} finally {
|
|
133
|
-
_iterator5.f();
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
} catch (err) {
|
|
137
|
-
_iterator4.e(err);
|
|
138
|
-
} finally {
|
|
139
|
-
_iterator4.f();
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
break;
|
|
143
|
-
|
|
144
|
-
case 'Polygon':
|
|
145
|
-
polygonFeaturesCount++;
|
|
146
|
-
polygonObjectsCount++;
|
|
147
|
-
polygonRingsCount += geometry.coordinates.length;
|
|
148
|
-
polygonPositionsCount += flatten(geometry.coordinates).length;
|
|
149
|
-
|
|
150
|
-
var _iterator6 = _createForOfIteratorHelper(flatten(geometry.coordinates)),
|
|
151
|
-
_step6;
|
|
152
|
-
|
|
153
|
-
try {
|
|
154
|
-
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
155
|
-
var _coord2 = _step6.value;
|
|
156
|
-
coordLengths.add(_coord2.length);
|
|
157
|
-
}
|
|
158
|
-
} catch (err) {
|
|
159
|
-
_iterator6.e(err);
|
|
160
|
-
} finally {
|
|
161
|
-
_iterator6.f();
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
break;
|
|
165
|
-
|
|
166
|
-
case 'MultiPolygon':
|
|
167
|
-
polygonFeaturesCount++;
|
|
168
|
-
|
|
169
|
-
var _iterator7 = _createForOfIteratorHelper(geometry.coordinates),
|
|
170
|
-
_step7;
|
|
171
|
-
|
|
172
|
-
try {
|
|
173
|
-
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
174
|
-
var polygon = _step7.value;
|
|
175
|
-
polygonObjectsCount++;
|
|
176
|
-
polygonRingsCount += polygon.length;
|
|
177
|
-
polygonPositionsCount += flatten(polygon).length;
|
|
178
|
-
|
|
179
|
-
var _iterator8 = _createForOfIteratorHelper(flatten(polygon)),
|
|
180
|
-
_step8;
|
|
181
|
-
|
|
182
|
-
try {
|
|
183
|
-
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
184
|
-
var _coord3 = _step8.value;
|
|
185
|
-
coordLengths.add(_coord3.length);
|
|
186
|
-
}
|
|
187
|
-
} catch (err) {
|
|
188
|
-
_iterator8.e(err);
|
|
189
|
-
} finally {
|
|
190
|
-
_iterator8.f();
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
} catch (err) {
|
|
194
|
-
_iterator7.e(err);
|
|
195
|
-
} finally {
|
|
196
|
-
_iterator7.f();
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
break;
|
|
200
|
-
|
|
201
|
-
default:
|
|
202
|
-
throw new Error("Unsupported geometry type: ".concat(geometry.type));
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
if (feature.properties) {
|
|
206
|
-
for (var key in feature.properties) {
|
|
207
|
-
var val = feature.properties[key];
|
|
208
|
-
numericPropKeys[key] = numericPropKeys[key] || numericPropKeys[key] === undefined ? isNumeric(val) : numericPropKeys[key];
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
} catch (err) {
|
|
213
|
-
_iterator.e(err);
|
|
214
|
-
} finally {
|
|
215
|
-
_iterator.f();
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
return {
|
|
219
|
-
coordLength: coordLengths.size > 0 ? Math.max.apply(Math, (0, _toConsumableArray2.default)(coordLengths)) : 2,
|
|
220
|
-
pointPositionsCount: pointPositionsCount,
|
|
221
|
-
pointFeaturesCount: pointFeaturesCount,
|
|
222
|
-
linePositionsCount: linePositionsCount,
|
|
223
|
-
linePathsCount: linePathsCount,
|
|
224
|
-
lineFeaturesCount: lineFeaturesCount,
|
|
225
|
-
polygonPositionsCount: polygonPositionsCount,
|
|
226
|
-
polygonObjectsCount: polygonObjectsCount,
|
|
227
|
-
polygonRingsCount: polygonRingsCount,
|
|
228
|
-
polygonFeaturesCount: polygonFeaturesCount,
|
|
229
|
-
numericPropKeys: Object.keys(numericPropKeys).filter(function (k) {
|
|
230
|
-
return numericPropKeys[k];
|
|
231
|
-
})
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
function secondPass(features, firstPassData, options) {
|
|
236
|
-
var pointPositionsCount = firstPassData.pointPositionsCount,
|
|
237
|
-
pointFeaturesCount = firstPassData.pointFeaturesCount,
|
|
238
|
-
linePositionsCount = firstPassData.linePositionsCount,
|
|
239
|
-
linePathsCount = firstPassData.linePathsCount,
|
|
240
|
-
lineFeaturesCount = firstPassData.lineFeaturesCount,
|
|
241
|
-
polygonPositionsCount = firstPassData.polygonPositionsCount,
|
|
242
|
-
polygonObjectsCount = firstPassData.polygonObjectsCount,
|
|
243
|
-
polygonRingsCount = firstPassData.polygonRingsCount,
|
|
244
|
-
polygonFeaturesCount = firstPassData.polygonFeaturesCount;
|
|
245
|
-
var coordLength = options.coordLength,
|
|
246
|
-
numericPropKeys = options.numericPropKeys,
|
|
247
|
-
_options$PositionData = options.PositionDataType,
|
|
248
|
-
PositionDataType = _options$PositionData === void 0 ? Float32Array : _options$PositionData;
|
|
249
|
-
var GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
|
|
250
|
-
var points = {
|
|
251
|
-
positions: new PositionDataType(pointPositionsCount * coordLength),
|
|
252
|
-
globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
|
|
253
|
-
featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
|
|
254
|
-
numericProps: {},
|
|
255
|
-
properties: Array(),
|
|
256
|
-
fields: Array()
|
|
257
|
-
};
|
|
258
|
-
var lines = {
|
|
259
|
-
positions: new PositionDataType(linePositionsCount * coordLength),
|
|
260
|
-
pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
|
|
261
|
-
globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
|
|
262
|
-
featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
|
|
263
|
-
numericProps: {},
|
|
264
|
-
properties: Array(),
|
|
265
|
-
fields: Array()
|
|
266
|
-
};
|
|
267
|
-
var polygons = {
|
|
268
|
-
positions: new PositionDataType(polygonPositionsCount * coordLength),
|
|
269
|
-
polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
|
|
270
|
-
primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
|
|
271
|
-
globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
|
|
272
|
-
featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
|
|
273
|
-
numericProps: {},
|
|
274
|
-
properties: Array(),
|
|
275
|
-
fields: Array()
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
for (var _i = 0, _arr = [points, lines, polygons]; _i < _arr.length; _i++) {
|
|
279
|
-
var object = _arr[_i];
|
|
280
|
-
|
|
281
|
-
var _iterator9 = _createForOfIteratorHelper(numericPropKeys || []),
|
|
282
|
-
_step9;
|
|
283
|
-
|
|
284
|
-
try {
|
|
285
|
-
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
|
|
286
|
-
var propName = _step9.value;
|
|
287
|
-
object.numericProps[propName] = new Float32Array(object.positions.length / coordLength);
|
|
288
|
-
}
|
|
289
|
-
} catch (err) {
|
|
290
|
-
_iterator9.e(err);
|
|
291
|
-
} finally {
|
|
292
|
-
_iterator9.f();
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
lines.pathIndices[linePathsCount] = linePositionsCount;
|
|
297
|
-
polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
|
|
298
|
-
polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
|
|
299
|
-
var indexMap = {
|
|
300
|
-
pointPosition: 0,
|
|
301
|
-
pointFeature: 0,
|
|
302
|
-
linePosition: 0,
|
|
303
|
-
linePath: 0,
|
|
304
|
-
lineFeature: 0,
|
|
305
|
-
polygonPosition: 0,
|
|
306
|
-
polygonObject: 0,
|
|
307
|
-
polygonRing: 0,
|
|
308
|
-
polygonFeature: 0,
|
|
309
|
-
feature: 0
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
var _iterator10 = _createForOfIteratorHelper(features),
|
|
313
|
-
_step10;
|
|
314
|
-
|
|
315
|
-
try {
|
|
316
|
-
for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
|
|
317
|
-
var feature = _step10.value;
|
|
318
|
-
var geometry = feature.geometry;
|
|
319
|
-
var properties = feature.properties || {};
|
|
320
|
-
|
|
321
|
-
switch (geometry.type) {
|
|
322
|
-
case 'Point':
|
|
323
|
-
handlePoint(geometry.coordinates, points, indexMap, coordLength, properties);
|
|
324
|
-
points.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
325
|
-
indexMap.pointFeature++;
|
|
326
|
-
break;
|
|
327
|
-
|
|
328
|
-
case 'MultiPoint':
|
|
329
|
-
handleMultiPoint(geometry.coordinates, points, indexMap, coordLength, properties);
|
|
330
|
-
points.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
331
|
-
indexMap.pointFeature++;
|
|
332
|
-
break;
|
|
333
|
-
|
|
334
|
-
case 'LineString':
|
|
335
|
-
handleLineString(geometry.coordinates, lines, indexMap, coordLength, properties);
|
|
336
|
-
lines.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
337
|
-
indexMap.lineFeature++;
|
|
338
|
-
break;
|
|
339
|
-
|
|
340
|
-
case 'MultiLineString':
|
|
341
|
-
handleMultiLineString(geometry.coordinates, lines, indexMap, coordLength, properties);
|
|
342
|
-
lines.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
343
|
-
indexMap.lineFeature++;
|
|
344
|
-
break;
|
|
345
|
-
|
|
346
|
-
case 'Polygon':
|
|
347
|
-
handlePolygon(geometry.coordinates, polygons, indexMap, coordLength, properties);
|
|
348
|
-
polygons.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
349
|
-
indexMap.polygonFeature++;
|
|
350
|
-
break;
|
|
351
|
-
|
|
352
|
-
case 'MultiPolygon':
|
|
353
|
-
handleMultiPolygon(geometry.coordinates, polygons, indexMap, coordLength, properties);
|
|
354
|
-
polygons.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
355
|
-
indexMap.polygonFeature++;
|
|
356
|
-
break;
|
|
357
|
-
|
|
358
|
-
default:
|
|
359
|
-
throw new Error('Invalid geometry type');
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
indexMap.feature++;
|
|
363
|
-
}
|
|
364
|
-
} catch (err) {
|
|
365
|
-
_iterator10.e(err);
|
|
366
|
-
} finally {
|
|
367
|
-
_iterator10.f();
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
return makeAccessorObjects(points, lines, polygons, coordLength);
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
function handlePoint(coords, points, indexMap, coordLength, properties) {
|
|
374
|
-
points.positions.set(coords, indexMap.pointPosition * coordLength);
|
|
375
|
-
points.globalFeatureIds[indexMap.pointPosition] = indexMap.feature;
|
|
376
|
-
points.featureIds[indexMap.pointPosition] = indexMap.pointFeature;
|
|
377
|
-
fillNumericProperties(points, properties, indexMap.pointPosition, 1);
|
|
378
|
-
indexMap.pointPosition++;
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
function handleMultiPoint(coords, points, indexMap, coordLength, properties) {
|
|
382
|
-
var _iterator11 = _createForOfIteratorHelper(coords),
|
|
383
|
-
_step11;
|
|
384
|
-
|
|
385
|
-
try {
|
|
386
|
-
for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
|
|
387
|
-
var point = _step11.value;
|
|
388
|
-
handlePoint(point, points, indexMap, coordLength, properties);
|
|
389
|
-
}
|
|
390
|
-
} catch (err) {
|
|
391
|
-
_iterator11.e(err);
|
|
392
|
-
} finally {
|
|
393
|
-
_iterator11.f();
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
function handleLineString(coords, lines, indexMap, coordLength, properties) {
|
|
398
|
-
lines.pathIndices[indexMap.linePath] = indexMap.linePosition;
|
|
399
|
-
indexMap.linePath++;
|
|
400
|
-
fillCoords(lines.positions, coords, indexMap.linePosition, coordLength);
|
|
401
|
-
var nPositions = coords.length;
|
|
402
|
-
fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
|
|
403
|
-
lines.globalFeatureIds.set(new Uint32Array(nPositions).fill(indexMap.feature), indexMap.linePosition);
|
|
404
|
-
lines.featureIds.set(new Uint32Array(nPositions).fill(indexMap.lineFeature), indexMap.linePosition);
|
|
405
|
-
indexMap.linePosition += nPositions;
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
function handleMultiLineString(coords, lines, indexMap, coordLength, properties) {
|
|
409
|
-
var _iterator12 = _createForOfIteratorHelper(coords),
|
|
410
|
-
_step12;
|
|
411
|
-
|
|
412
|
-
try {
|
|
413
|
-
for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
|
|
414
|
-
var line = _step12.value;
|
|
415
|
-
handleLineString(line, lines, indexMap, coordLength, properties);
|
|
416
|
-
}
|
|
417
|
-
} catch (err) {
|
|
418
|
-
_iterator12.e(err);
|
|
419
|
-
} finally {
|
|
420
|
-
_iterator12.f();
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
function handlePolygon(coords, polygons, indexMap, coordLength, properties) {
|
|
425
|
-
polygons.polygonIndices[indexMap.polygonObject] = indexMap.polygonPosition;
|
|
426
|
-
indexMap.polygonObject++;
|
|
427
|
-
|
|
428
|
-
var _iterator13 = _createForOfIteratorHelper(coords),
|
|
429
|
-
_step13;
|
|
430
|
-
|
|
431
|
-
try {
|
|
432
|
-
for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
|
|
433
|
-
var ring = _step13.value;
|
|
434
|
-
polygons.primitivePolygonIndices[indexMap.polygonRing] = indexMap.polygonPosition;
|
|
435
|
-
indexMap.polygonRing++;
|
|
436
|
-
fillCoords(polygons.positions, ring, indexMap.polygonPosition, coordLength);
|
|
437
|
-
var nPositions = ring.length;
|
|
438
|
-
fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
|
|
439
|
-
polygons.globalFeatureIds.set(new Uint32Array(nPositions).fill(indexMap.feature), indexMap.polygonPosition);
|
|
440
|
-
polygons.featureIds.set(new Uint32Array(nPositions).fill(indexMap.polygonFeature), indexMap.polygonPosition);
|
|
441
|
-
indexMap.polygonPosition += nPositions;
|
|
442
|
-
}
|
|
443
|
-
} catch (err) {
|
|
444
|
-
_iterator13.e(err);
|
|
445
|
-
} finally {
|
|
446
|
-
_iterator13.f();
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
function handleMultiPolygon(coords, polygons, indexMap, coordLength, properties) {
|
|
451
|
-
var _iterator14 = _createForOfIteratorHelper(coords),
|
|
452
|
-
_step14;
|
|
453
|
-
|
|
454
|
-
try {
|
|
455
|
-
for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
|
|
456
|
-
var polygon = _step14.value;
|
|
457
|
-
handlePolygon(polygon, polygons, indexMap, coordLength, properties);
|
|
458
|
-
}
|
|
459
|
-
} catch (err) {
|
|
460
|
-
_iterator14.e(err);
|
|
461
|
-
} finally {
|
|
462
|
-
_iterator14.f();
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
function makeAccessorObjects(points, lines, polygons, coordLength) {
|
|
467
|
-
var returnObj = {
|
|
468
|
-
points: _objectSpread(_objectSpread({}, points), {}, {
|
|
469
|
-
positions: {
|
|
470
|
-
value: points.positions,
|
|
471
|
-
size: coordLength
|
|
472
|
-
},
|
|
473
|
-
globalFeatureIds: {
|
|
474
|
-
value: points.globalFeatureIds,
|
|
475
|
-
size: 1
|
|
476
|
-
},
|
|
477
|
-
featureIds: {
|
|
478
|
-
value: points.featureIds,
|
|
479
|
-
size: 1
|
|
480
|
-
},
|
|
481
|
-
type: 'Point'
|
|
482
|
-
}),
|
|
483
|
-
lines: _objectSpread(_objectSpread({}, lines), {}, {
|
|
484
|
-
pathIndices: {
|
|
485
|
-
value: lines.pathIndices,
|
|
486
|
-
size: 1
|
|
487
|
-
},
|
|
488
|
-
positions: {
|
|
489
|
-
value: lines.positions,
|
|
490
|
-
size: coordLength
|
|
491
|
-
},
|
|
492
|
-
globalFeatureIds: {
|
|
493
|
-
value: lines.globalFeatureIds,
|
|
494
|
-
size: 1
|
|
495
|
-
},
|
|
496
|
-
featureIds: {
|
|
497
|
-
value: lines.featureIds,
|
|
498
|
-
size: 1
|
|
499
|
-
},
|
|
500
|
-
type: 'LineString'
|
|
501
|
-
}),
|
|
502
|
-
polygons: _objectSpread(_objectSpread({}, polygons), {}, {
|
|
503
|
-
polygonIndices: {
|
|
504
|
-
value: polygons.polygonIndices,
|
|
505
|
-
size: 1
|
|
506
|
-
},
|
|
507
|
-
primitivePolygonIndices: {
|
|
508
|
-
value: polygons.primitivePolygonIndices,
|
|
509
|
-
size: 1
|
|
510
|
-
},
|
|
511
|
-
positions: {
|
|
512
|
-
value: polygons.positions,
|
|
513
|
-
size: coordLength
|
|
514
|
-
},
|
|
515
|
-
globalFeatureIds: {
|
|
516
|
-
value: polygons.globalFeatureIds,
|
|
517
|
-
size: 1
|
|
518
|
-
},
|
|
519
|
-
featureIds: {
|
|
520
|
-
value: polygons.featureIds,
|
|
521
|
-
size: 1
|
|
522
|
-
},
|
|
523
|
-
type: 'Polygon'
|
|
524
|
-
})
|
|
525
|
-
};
|
|
526
|
-
|
|
527
|
-
for (var geomType in returnObj) {
|
|
528
|
-
for (var numericProp in returnObj[geomType].numericProps) {
|
|
529
|
-
returnObj[geomType].numericProps[numericProp] = {
|
|
530
|
-
value: returnObj[geomType].numericProps[numericProp],
|
|
531
|
-
size: 1
|
|
532
|
-
};
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
return returnObj;
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
function fillNumericProperties(object, properties, index, length) {
|
|
540
|
-
for (var numericPropName in object.numericProps) {
|
|
541
|
-
if (numericPropName in properties) {
|
|
542
|
-
object.numericProps[numericPropName].set(new Array(length).fill(properties[numericPropName]), index);
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
function keepStringProperties(properties, numericKeys) {
|
|
548
|
-
var props = {};
|
|
549
|
-
|
|
550
|
-
for (var key in properties) {
|
|
551
|
-
if (!numericKeys.includes(key)) {
|
|
552
|
-
props[key] = properties[key];
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
return props;
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
function fillCoords(array, coords, startVertex, coordLength) {
|
|
560
|
-
var index = startVertex * coordLength;
|
|
561
|
-
|
|
562
|
-
var _iterator15 = _createForOfIteratorHelper(coords),
|
|
563
|
-
_step15;
|
|
564
|
-
|
|
565
|
-
try {
|
|
566
|
-
for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
|
|
567
|
-
var coord = _step15.value;
|
|
568
|
-
array.set(coord, index);
|
|
569
|
-
index += coordLength;
|
|
570
|
-
}
|
|
571
|
-
} catch (err) {
|
|
572
|
-
_iterator15.e(err);
|
|
573
|
-
} finally {
|
|
574
|
-
_iterator15.f();
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
function flatten(arrays) {
|
|
579
|
-
var _ref;
|
|
580
|
-
|
|
581
|
-
return (_ref = []).concat.apply(_ref, (0, _toConsumableArray2.default)(arrays));
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
function isNumeric(x) {
|
|
585
|
-
return Number.isFinite(x);
|
|
586
|
-
}
|
|
587
|
-
//# sourceMappingURL=geojson-to-binary.js.map
|