@loaders.gl/gis
Advanced tools
Comparing version 3.0.0-alpha.4 to 3.0.0-alpha.5
"use strict"; | ||
var moduleExports = require('./index'); | ||
const moduleExports = require('./index'); | ||
var _global = typeof window === 'undefined' ? global : window; | ||
const _global = typeof window === 'undefined' ? global : window; | ||
@@ -7,0 +7,0 @@ _global.loaders = _global.loaders || {}; |
@@ -8,3 +8,3 @@ "use strict"; | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _geojsonToBinary.geojsonToBinary; | ||
@@ -15,3 +15,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _binaryToGeojson.binaryToGeoJson; | ||
@@ -22,3 +22,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _transform.transformBinaryCoords; | ||
@@ -29,3 +29,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _transform.transformGeoJsonCoords; | ||
@@ -32,0 +32,0 @@ } |
@@ -8,8 +8,2 @@ "use strict"; | ||
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { 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 = o[Symbol.iterator](); }, 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; } } }; } | ||
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); } | ||
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; } | ||
function binaryToGeoJson(data, type, format) { | ||
@@ -20,3 +14,3 @@ if (format === 'geometry') { | ||
var dataArray = normalizeInput(data, type); | ||
const dataArray = normalizeInput(data, type); | ||
@@ -38,3 +32,3 @@ switch (deduceReturnType(dataArray)) { | ||
function normalizeInput(data, type) { | ||
var isHeterogeneousType = Boolean(data.points || data.lines || data.polygons); | ||
const isHeterogeneousType = Boolean(data.points || data.lines || data.polygons); | ||
@@ -46,3 +40,3 @@ if (!isHeterogeneousType) { | ||
var features = []; | ||
const features = []; | ||
@@ -72,3 +66,3 @@ if (data.points) { | ||
var data = dataArray[0]; | ||
const data = dataArray[0]; | ||
@@ -83,36 +77,25 @@ if (!(data.featureIds || data.globalFeatureIds || data.numericProps || data.properties)) { | ||
function parseFeatureCollection(dataArray) { | ||
var features = []; | ||
const features = []; | ||
var _iterator = _createForOfIteratorHelper(dataArray), | ||
_step; | ||
for (const data of dataArray) { | ||
if (data.featureIds.value.length === 0) { | ||
continue; | ||
} | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var data = _step.value; | ||
let lastIndex = 0; | ||
let lastValue = data.featureIds.value[0]; | ||
if (data.featureIds.value.length === 0) { | ||
for (let i = 0; i < data.featureIds.value.length; i++) { | ||
const currValue = data.featureIds.value[i]; | ||
if (currValue === lastValue) { | ||
continue; | ||
} | ||
var lastIndex = 0; | ||
var lastValue = data.featureIds.value[0]; | ||
features.push(parseFeature(data, lastIndex, i)); | ||
lastIndex = i; | ||
lastValue = currValue; | ||
} | ||
for (var i = 0; i < data.featureIds.value.length; i++) { | ||
var currValue = data.featureIds.value[i]; | ||
if (currValue === lastValue) { | ||
continue; | ||
} | ||
features.push(parseFeature(data, lastIndex, i)); | ||
lastIndex = i; | ||
lastValue = currValue; | ||
} | ||
features.push(parseFeature(data, lastIndex, data.featureIds.value.length)); | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
features.push(parseFeature(data, lastIndex, data.featureIds.value.length)); | ||
} | ||
@@ -124,8 +107,8 @@ | ||
function parseFeature(data, startIndex, endIndex) { | ||
var geometry = parseGeometry(data, startIndex, endIndex); | ||
var properties = parseProperties(data, startIndex, endIndex); | ||
const geometry = parseGeometry(data, startIndex, endIndex); | ||
const properties = parseProperties(data, startIndex, endIndex); | ||
return { | ||
type: 'Feature', | ||
geometry: geometry, | ||
properties: properties | ||
geometry, | ||
properties | ||
}; | ||
@@ -135,5 +118,5 @@ } | ||
function parseProperties(data, startIndex, endIndex) { | ||
var properties = Object.assign(data.properties[data.featureIds.value[startIndex]]); | ||
const properties = Object.assign(data.properties[data.featureIds.value[startIndex]]); | ||
for (var key in data.numericProps) { | ||
for (const key in data.numericProps) { | ||
properties[key] = data.numericProps[key].value[startIndex]; | ||
@@ -161,20 +144,16 @@ } | ||
function polygonToGeoJson(data) { | ||
var startIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -Infinity; | ||
var endIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Infinity; | ||
var positions = data.positions; | ||
var polygonIndices = data.polygonIndices.value.filter(function (x) { | ||
return x >= startIndex && x <= endIndex; | ||
}); | ||
var primitivePolygonIndices = data.primitivePolygonIndices.value.filter(function (x) { | ||
return x >= startIndex && x <= endIndex; | ||
}); | ||
var multi = polygonIndices.length > 2; | ||
var coordinates = []; | ||
function polygonToGeoJson(data, startIndex = -Infinity, endIndex = Infinity) { | ||
const { | ||
positions | ||
} = data; | ||
const polygonIndices = data.polygonIndices.value.filter(x => x >= startIndex && x <= endIndex); | ||
const primitivePolygonIndices = data.primitivePolygonIndices.value.filter(x => x >= startIndex && x <= endIndex); | ||
const multi = polygonIndices.length > 2; | ||
const coordinates = []; | ||
if (!multi) { | ||
for (var i = 0; i < primitivePolygonIndices.length - 1; i++) { | ||
var startRingIndex = primitivePolygonIndices[i]; | ||
var endRingIndex = primitivePolygonIndices[i + 1]; | ||
var ringCoordinates = ringToGeoJson(positions, startRingIndex, endRingIndex); | ||
for (let i = 0; i < primitivePolygonIndices.length - 1; i++) { | ||
const startRingIndex = primitivePolygonIndices[i]; | ||
const endRingIndex = primitivePolygonIndices[i + 1]; | ||
const ringCoordinates = ringToGeoJson(positions, startRingIndex, endRingIndex); | ||
coordinates.push(ringCoordinates); | ||
@@ -185,10 +164,10 @@ } | ||
type: 'Polygon', | ||
coordinates: coordinates | ||
coordinates | ||
}; | ||
} | ||
for (var _i = 0; _i < polygonIndices.length - 1; _i++) { | ||
var startPolygonIndex = polygonIndices[_i]; | ||
var endPolygonIndex = polygonIndices[_i + 1]; | ||
var polygonCoordinates = polygonToGeoJson(data, startPolygonIndex, endPolygonIndex).coordinates; | ||
for (let i = 0; i < polygonIndices.length - 1; i++) { | ||
const startPolygonIndex = polygonIndices[i]; | ||
const endPolygonIndex = polygonIndices[i + 1]; | ||
const polygonCoordinates = polygonToGeoJson(data, startPolygonIndex, endPolygonIndex).coordinates; | ||
coordinates.push(polygonCoordinates); | ||
@@ -199,28 +178,25 @@ } | ||
type: 'MultiPolygon', | ||
coordinates: coordinates | ||
coordinates | ||
}; | ||
} | ||
function lineStringToGeoJson(data) { | ||
var startIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -Infinity; | ||
var endIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Infinity; | ||
var positions = data.positions; | ||
var pathIndices = data.pathIndices.value.filter(function (x) { | ||
return x >= startIndex && x <= endIndex; | ||
}); | ||
var multi = pathIndices.length > 2; | ||
function lineStringToGeoJson(data, startIndex = -Infinity, endIndex = Infinity) { | ||
const { | ||
positions | ||
} = data; | ||
const pathIndices = data.pathIndices.value.filter(x => x >= startIndex && x <= endIndex); | ||
const multi = pathIndices.length > 2; | ||
if (!multi) { | ||
var _coordinates = ringToGeoJson(positions, pathIndices[0], pathIndices[1]); | ||
const coordinates = ringToGeoJson(positions, pathIndices[0], pathIndices[1]); | ||
return { | ||
type: 'LineString', | ||
coordinates: _coordinates | ||
coordinates | ||
}; | ||
} | ||
var coordinates = []; | ||
const coordinates = []; | ||
for (var i = 0; i < pathIndices.length - 1; i++) { | ||
var ringCoordinates = ringToGeoJson(positions, pathIndices[i], pathIndices[i + 1]); | ||
for (let i = 0; i < pathIndices.length - 1; i++) { | ||
const ringCoordinates = ringToGeoJson(positions, pathIndices[i], pathIndices[i + 1]); | ||
coordinates.push(ringCoordinates); | ||
@@ -231,3 +207,3 @@ } | ||
type: 'MultiLineString', | ||
coordinates: coordinates | ||
coordinates | ||
}; | ||
@@ -237,5 +213,7 @@ } | ||
function pointToGeoJson(data, startIndex, endIndex) { | ||
var positions = data.positions; | ||
var coordinates = ringToGeoJson(positions, startIndex, endIndex); | ||
var multi = coordinates.length > 1; | ||
const { | ||
positions | ||
} = data; | ||
const coordinates = ringToGeoJson(positions, startIndex, endIndex); | ||
const multi = coordinates.length > 1; | ||
@@ -245,3 +223,3 @@ if (multi) { | ||
type: 'MultiPoint', | ||
coordinates: coordinates | ||
coordinates | ||
}; | ||
@@ -259,5 +237,5 @@ } | ||
endIndex = endIndex || positions.value.length / positions.size; | ||
var ringCoordinates = []; | ||
const ringCoordinates = []; | ||
for (var j = startIndex; j < endIndex; j++) { | ||
for (let j = startIndex; j < endIndex; j++) { | ||
ringCoordinates.push(Array.from(positions.value.subarray(j * positions.size, (j + 1) * positions.size))); | ||
@@ -264,0 +242,0 @@ } |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -11,13 +9,4 @@ value: true | ||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); | ||
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { 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 = o[Symbol.iterator](); }, 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; } } }; } | ||
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); } | ||
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; } | ||
function geojsonToBinary(features) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var firstPassData = firstPass(features); | ||
function geojsonToBinary(features, options = {}) { | ||
const firstPassData = firstPass(features); | ||
return secondPass(features, firstPassData, { | ||
@@ -30,5 +19,5 @@ coordLength: options.coordLength || firstPassData.coordLength, | ||
var TEST_EXPORTS = { | ||
firstPass: firstPass, | ||
secondPass: secondPass | ||
const TEST_EXPORTS = { | ||
firstPass, | ||
secondPass | ||
}; | ||
@@ -38,213 +27,132 @@ exports.TEST_EXPORTS = TEST_EXPORTS; | ||
function firstPass(features) { | ||
var pointPositionsCount = 0; | ||
var pointFeaturesCount = 0; | ||
var linePositionsCount = 0; | ||
var linePathsCount = 0; | ||
var lineFeaturesCount = 0; | ||
var polygonPositionsCount = 0; | ||
var polygonObjectsCount = 0; | ||
var polygonRingsCount = 0; | ||
var polygonFeaturesCount = 0; | ||
var coordLengths = new Set(); | ||
var numericPropKeys = {}; | ||
let pointPositionsCount = 0; | ||
let pointFeaturesCount = 0; | ||
let linePositionsCount = 0; | ||
let linePathsCount = 0; | ||
let lineFeaturesCount = 0; | ||
let polygonPositionsCount = 0; | ||
let polygonObjectsCount = 0; | ||
let polygonRingsCount = 0; | ||
let polygonFeaturesCount = 0; | ||
const coordLengths = new Set(); | ||
const numericPropKeys = {}; | ||
var _iterator = _createForOfIteratorHelper(features), | ||
_step; | ||
for (const feature of features) { | ||
const geometry = feature.geometry; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var feature = _step.value; | ||
var geometry = feature.geometry; | ||
switch (geometry.type) { | ||
case 'Point': | ||
pointFeaturesCount++; | ||
pointPositionsCount++; | ||
coordLengths.add(geometry.coordinates.length); | ||
break; | ||
switch (geometry.type) { | ||
case 'Point': | ||
pointFeaturesCount++; | ||
pointPositionsCount++; | ||
coordLengths.add(geometry.coordinates.length); | ||
break; | ||
case 'MultiPoint': | ||
pointFeaturesCount++; | ||
pointPositionsCount += geometry.coordinates.length; | ||
case 'MultiPoint': | ||
pointFeaturesCount++; | ||
pointPositionsCount += geometry.coordinates.length; | ||
for (const point of geometry.coordinates) { | ||
coordLengths.add(point.length); | ||
} | ||
var _iterator2 = _createForOfIteratorHelper(geometry.coordinates), | ||
_step2; | ||
break; | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var point = _step2.value; | ||
coordLengths.add(point.length); | ||
} | ||
} catch (err) { | ||
_iterator2.e(err); | ||
} finally { | ||
_iterator2.f(); | ||
} | ||
case 'LineString': | ||
lineFeaturesCount++; | ||
linePositionsCount += geometry.coordinates.length; | ||
linePathsCount++; | ||
break; | ||
for (const coord of geometry.coordinates) { | ||
coordLengths.add(coord.length); | ||
} | ||
case 'LineString': | ||
lineFeaturesCount++; | ||
linePositionsCount += geometry.coordinates.length; | ||
break; | ||
case 'MultiLineString': | ||
lineFeaturesCount++; | ||
for (const line of geometry.coordinates) { | ||
linePositionsCount += line.length; | ||
linePathsCount++; | ||
var _iterator3 = _createForOfIteratorHelper(geometry.coordinates), | ||
_step3; | ||
try { | ||
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { | ||
var coord = _step3.value; | ||
coordLengths.add(coord.length); | ||
} | ||
} catch (err) { | ||
_iterator3.e(err); | ||
} finally { | ||
_iterator3.f(); | ||
for (const coord of line) { | ||
coordLengths.add(coord.length); | ||
} | ||
} | ||
break; | ||
break; | ||
case 'MultiLineString': | ||
lineFeaturesCount++; | ||
case 'Polygon': | ||
polygonFeaturesCount++; | ||
polygonObjectsCount++; | ||
polygonRingsCount += geometry.coordinates.length; | ||
polygonPositionsCount += flatten(geometry.coordinates).length; | ||
var _iterator4 = _createForOfIteratorHelper(geometry.coordinates), | ||
_step4; | ||
for (const coord of flatten(geometry.coordinates)) { | ||
coordLengths.add(coord.length); | ||
} | ||
try { | ||
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { | ||
var line = _step4.value; | ||
linePositionsCount += line.length; | ||
linePathsCount++; | ||
break; | ||
var _iterator5 = _createForOfIteratorHelper(line), | ||
_step5; | ||
case 'MultiPolygon': | ||
polygonFeaturesCount++; | ||
try { | ||
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) { | ||
var _coord = _step5.value; | ||
coordLengths.add(_coord.length); | ||
} | ||
} catch (err) { | ||
_iterator5.e(err); | ||
} finally { | ||
_iterator5.f(); | ||
} | ||
} | ||
} catch (err) { | ||
_iterator4.e(err); | ||
} finally { | ||
_iterator4.f(); | ||
} | ||
break; | ||
case 'Polygon': | ||
polygonFeaturesCount++; | ||
for (const polygon of geometry.coordinates) { | ||
polygonObjectsCount++; | ||
polygonRingsCount += geometry.coordinates.length; | ||
polygonPositionsCount += flatten(geometry.coordinates).length; | ||
polygonRingsCount += polygon.length; | ||
polygonPositionsCount += flatten(polygon).length; | ||
var _iterator6 = _createForOfIteratorHelper(flatten(geometry.coordinates)), | ||
_step6; | ||
try { | ||
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) { | ||
var _coord2 = _step6.value; | ||
coordLengths.add(_coord2.length); | ||
} | ||
} catch (err) { | ||
_iterator6.e(err); | ||
} finally { | ||
_iterator6.f(); | ||
for (const coord of flatten(polygon)) { | ||
coordLengths.add(coord.length); | ||
} | ||
} | ||
break; | ||
break; | ||
case 'MultiPolygon': | ||
polygonFeaturesCount++; | ||
default: | ||
throw new Error("Unsupported geometry type: ".concat(geometry.type)); | ||
} | ||
var _iterator7 = _createForOfIteratorHelper(geometry.coordinates), | ||
_step7; | ||
try { | ||
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) { | ||
var polygon = _step7.value; | ||
polygonObjectsCount++; | ||
polygonRingsCount += polygon.length; | ||
polygonPositionsCount += flatten(polygon).length; | ||
var _iterator8 = _createForOfIteratorHelper(flatten(polygon)), | ||
_step8; | ||
try { | ||
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) { | ||
var _coord3 = _step8.value; | ||
coordLengths.add(_coord3.length); | ||
} | ||
} catch (err) { | ||
_iterator8.e(err); | ||
} finally { | ||
_iterator8.f(); | ||
} | ||
} | ||
} catch (err) { | ||
_iterator7.e(err); | ||
} finally { | ||
_iterator7.f(); | ||
} | ||
break; | ||
default: | ||
throw new Error("Unsupported geometry type: ".concat(geometry.type)); | ||
if (feature.properties) { | ||
for (const key in feature.properties) { | ||
const val = feature.properties[key]; | ||
numericPropKeys[key] = numericPropKeys[key] || numericPropKeys[key] === undefined ? isNumeric(val) : numericPropKeys[key]; | ||
} | ||
if (feature.properties) { | ||
for (var key in feature.properties) { | ||
var val = feature.properties[key]; | ||
numericPropKeys[key] = numericPropKeys[key] || numericPropKeys[key] === undefined ? isNumeric(val) : numericPropKeys[key]; | ||
} | ||
} | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
return { | ||
pointPositionsCount: pointPositionsCount, | ||
pointFeaturesCount: pointFeaturesCount, | ||
linePositionsCount: linePositionsCount, | ||
linePathsCount: linePathsCount, | ||
lineFeaturesCount: lineFeaturesCount, | ||
coordLength: Math.max.apply(Math, (0, _toConsumableArray2["default"])(coordLengths)), | ||
polygonPositionsCount: polygonPositionsCount, | ||
polygonObjectsCount: polygonObjectsCount, | ||
polygonRingsCount: polygonRingsCount, | ||
polygonFeaturesCount: polygonFeaturesCount, | ||
numericPropKeys: Object.keys(numericPropKeys).filter(function (k) { | ||
return numericPropKeys[k]; | ||
}) | ||
pointPositionsCount, | ||
pointFeaturesCount, | ||
linePositionsCount, | ||
linePathsCount, | ||
lineFeaturesCount, | ||
coordLength: Math.max(...coordLengths), | ||
polygonPositionsCount, | ||
polygonObjectsCount, | ||
polygonRingsCount, | ||
polygonFeaturesCount, | ||
numericPropKeys: Object.keys(numericPropKeys).filter(k => numericPropKeys[k]) | ||
}; | ||
} | ||
function secondPass(features) { | ||
var firstPassData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var pointPositionsCount = firstPassData.pointPositionsCount, | ||
pointFeaturesCount = firstPassData.pointFeaturesCount, | ||
linePositionsCount = firstPassData.linePositionsCount, | ||
linePathsCount = firstPassData.linePathsCount, | ||
lineFeaturesCount = firstPassData.lineFeaturesCount, | ||
polygonPositionsCount = firstPassData.polygonPositionsCount, | ||
polygonObjectsCount = firstPassData.polygonObjectsCount, | ||
polygonRingsCount = firstPassData.polygonRingsCount, | ||
polygonFeaturesCount = firstPassData.polygonFeaturesCount; | ||
var coordLength = options.coordLength, | ||
numericPropKeys = options.numericPropKeys, | ||
_options$PositionData = options.PositionDataType, | ||
PositionDataType = _options$PositionData === void 0 ? Float32Array : _options$PositionData; | ||
var GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array; | ||
var points = { | ||
function secondPass(features, firstPassData = {}, options = {}) { | ||
const { | ||
pointPositionsCount, | ||
pointFeaturesCount, | ||
linePositionsCount, | ||
linePathsCount, | ||
lineFeaturesCount, | ||
polygonPositionsCount, | ||
polygonObjectsCount, | ||
polygonRingsCount, | ||
polygonFeaturesCount | ||
} = firstPassData; | ||
const { | ||
coordLength, | ||
numericPropKeys, | ||
PositionDataType = Float32Array | ||
} = options; | ||
const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array; | ||
const points = { | ||
positions: new PositionDataType(pointPositionsCount * coordLength), | ||
@@ -256,3 +164,3 @@ globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount), | ||
}; | ||
var lines = { | ||
const lines = { | ||
pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1), | ||
@@ -265,3 +173,3 @@ positions: new PositionDataType(linePositionsCount * coordLength), | ||
}; | ||
var polygons = { | ||
const polygons = { | ||
polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1), | ||
@@ -276,17 +184,5 @@ primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1), | ||
for (var _i = 0, _arr = [points, lines, polygons]; _i < _arr.length; _i++) { | ||
var object = _arr[_i]; | ||
var _iterator9 = _createForOfIteratorHelper(numericPropKeys), | ||
_step9; | ||
try { | ||
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) { | ||
var propName = _step9.value; | ||
object.numericProps[propName] = new Float32Array(object.positions.length / coordLength); | ||
} | ||
} catch (err) { | ||
_iterator9.e(err); | ||
} finally { | ||
_iterator9.f(); | ||
for (const object of [points, lines, polygons]) { | ||
for (const propName of numericPropKeys) { | ||
object.numericProps[propName] = new Float32Array(object.positions.length / coordLength); | ||
} | ||
@@ -298,3 +194,3 @@ } | ||
polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount; | ||
var indexMap = { | ||
const indexMap = { | ||
pointPosition: 0, | ||
@@ -312,58 +208,48 @@ pointFeature: 0, | ||
var _iterator10 = _createForOfIteratorHelper(features), | ||
_step10; | ||
for (const feature of features) { | ||
const geometry = feature.geometry; | ||
const properties = feature.properties || {}; | ||
try { | ||
for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) { | ||
var feature = _step10.value; | ||
var geometry = feature.geometry; | ||
var properties = feature.properties || {}; | ||
switch (geometry.type) { | ||
case 'Point': | ||
handlePoint(geometry.coordinates, points, indexMap, coordLength, properties); | ||
points.properties.push(keepStringProperties(properties, numericPropKeys)); | ||
indexMap.pointFeature++; | ||
break; | ||
switch (geometry.type) { | ||
case 'Point': | ||
handlePoint(geometry.coordinates, points, indexMap, coordLength, properties); | ||
points.properties.push(keepStringProperties(properties, numericPropKeys)); | ||
indexMap.pointFeature++; | ||
break; | ||
case 'MultiPoint': | ||
handleMultiPoint(geometry.coordinates, points, indexMap, coordLength, properties); | ||
points.properties.push(keepStringProperties(properties, numericPropKeys)); | ||
indexMap.pointFeature++; | ||
break; | ||
case 'MultiPoint': | ||
handleMultiPoint(geometry.coordinates, points, indexMap, coordLength, properties); | ||
points.properties.push(keepStringProperties(properties, numericPropKeys)); | ||
indexMap.pointFeature++; | ||
break; | ||
case 'LineString': | ||
handleLineString(geometry.coordinates, lines, indexMap, coordLength, properties); | ||
lines.properties.push(keepStringProperties(properties, numericPropKeys)); | ||
indexMap.lineFeature++; | ||
break; | ||
case 'LineString': | ||
handleLineString(geometry.coordinates, lines, indexMap, coordLength, properties); | ||
lines.properties.push(keepStringProperties(properties, numericPropKeys)); | ||
indexMap.lineFeature++; | ||
break; | ||
case 'MultiLineString': | ||
handleMultiLineString(geometry.coordinates, lines, indexMap, coordLength, properties); | ||
lines.properties.push(keepStringProperties(properties, numericPropKeys)); | ||
indexMap.lineFeature++; | ||
break; | ||
case 'MultiLineString': | ||
handleMultiLineString(geometry.coordinates, lines, indexMap, coordLength, properties); | ||
lines.properties.push(keepStringProperties(properties, numericPropKeys)); | ||
indexMap.lineFeature++; | ||
break; | ||
case 'Polygon': | ||
handlePolygon(geometry.coordinates, polygons, indexMap, coordLength, properties); | ||
polygons.properties.push(keepStringProperties(properties, numericPropKeys)); | ||
indexMap.polygonFeature++; | ||
break; | ||
case 'Polygon': | ||
handlePolygon(geometry.coordinates, polygons, indexMap, coordLength, properties); | ||
polygons.properties.push(keepStringProperties(properties, numericPropKeys)); | ||
indexMap.polygonFeature++; | ||
break; | ||
case 'MultiPolygon': | ||
handleMultiPolygon(geometry.coordinates, polygons, indexMap, coordLength, properties); | ||
polygons.properties.push(keepStringProperties(properties, numericPropKeys)); | ||
indexMap.polygonFeature++; | ||
break; | ||
case 'MultiPolygon': | ||
handleMultiPolygon(geometry.coordinates, polygons, indexMap, coordLength, properties); | ||
polygons.properties.push(keepStringProperties(properties, numericPropKeys)); | ||
indexMap.polygonFeature++; | ||
break; | ||
default: | ||
throw new Error('Invalid geometry type'); | ||
} | ||
default: | ||
throw new Error('Invalid geometry type'); | ||
} | ||
indexMap.feature++; | ||
} | ||
} catch (err) { | ||
_iterator10.e(err); | ||
} finally { | ||
_iterator10.f(); | ||
indexMap.feature++; | ||
} | ||
@@ -383,14 +269,4 @@ | ||
function handleMultiPoint(coords, points, indexMap, coordLength, properties) { | ||
var _iterator11 = _createForOfIteratorHelper(coords), | ||
_step11; | ||
try { | ||
for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) { | ||
var point = _step11.value; | ||
handlePoint(point, points, indexMap, coordLength, properties); | ||
} | ||
} catch (err) { | ||
_iterator11.e(err); | ||
} finally { | ||
_iterator11.f(); | ||
for (const point of coords) { | ||
handlePoint(point, points, indexMap, coordLength, properties); | ||
} | ||
@@ -403,3 +279,3 @@ } | ||
fillCoords(lines.positions, coords, indexMap.linePosition, coordLength); | ||
var nPositions = coords.length; | ||
const nPositions = coords.length; | ||
fillNumericProperties(lines, properties, indexMap.linePosition, nPositions); | ||
@@ -412,14 +288,4 @@ lines.globalFeatureIds.set(new Uint32Array(nPositions).fill(indexMap.feature), indexMap.linePosition); | ||
function handleMultiLineString(coords, lines, indexMap, coordLength, properties) { | ||
var _iterator12 = _createForOfIteratorHelper(coords), | ||
_step12; | ||
try { | ||
for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) { | ||
var line = _step12.value; | ||
handleLineString(line, lines, indexMap, coordLength, properties); | ||
} | ||
} catch (err) { | ||
_iterator12.e(err); | ||
} finally { | ||
_iterator12.f(); | ||
for (const line of coords) { | ||
handleLineString(line, lines, indexMap, coordLength, properties); | ||
} | ||
@@ -432,21 +298,11 @@ } | ||
var _iterator13 = _createForOfIteratorHelper(coords), | ||
_step13; | ||
try { | ||
for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) { | ||
var ring = _step13.value; | ||
polygons.primitivePolygonIndices[indexMap.polygonRing] = indexMap.polygonPosition; | ||
indexMap.polygonRing++; | ||
fillCoords(polygons.positions, ring, indexMap.polygonPosition, coordLength); | ||
var nPositions = ring.length; | ||
fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions); | ||
polygons.globalFeatureIds.set(new Uint32Array(nPositions).fill(indexMap.feature), indexMap.polygonPosition); | ||
polygons.featureIds.set(new Uint32Array(nPositions).fill(indexMap.polygonFeature), indexMap.polygonPosition); | ||
indexMap.polygonPosition += nPositions; | ||
} | ||
} catch (err) { | ||
_iterator13.e(err); | ||
} finally { | ||
_iterator13.f(); | ||
for (const ring of coords) { | ||
polygons.primitivePolygonIndices[indexMap.polygonRing] = indexMap.polygonPosition; | ||
indexMap.polygonRing++; | ||
fillCoords(polygons.positions, ring, indexMap.polygonPosition, coordLength); | ||
const nPositions = ring.length; | ||
fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions); | ||
polygons.globalFeatureIds.set(new Uint32Array(nPositions).fill(indexMap.feature), indexMap.polygonPosition); | ||
polygons.featureIds.set(new Uint32Array(nPositions).fill(indexMap.polygonFeature), indexMap.polygonPosition); | ||
indexMap.polygonPosition += nPositions; | ||
} | ||
@@ -456,14 +312,4 @@ } | ||
function handleMultiPolygon(coords, polygons, indexMap, coordLength, properties) { | ||
var _iterator14 = _createForOfIteratorHelper(coords), | ||
_step14; | ||
try { | ||
for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) { | ||
var polygon = _step14.value; | ||
handlePolygon(polygon, polygons, indexMap, coordLength, properties); | ||
} | ||
} catch (err) { | ||
_iterator14.e(err); | ||
} finally { | ||
_iterator14.f(); | ||
for (const polygon of coords) { | ||
handlePolygon(polygon, polygons, indexMap, coordLength, properties); | ||
} | ||
@@ -473,3 +319,3 @@ } | ||
function makeAccessorObjects(points, lines, polygons, coordLength) { | ||
var returnObj = { | ||
const returnObj = { | ||
points: { | ||
@@ -537,4 +383,4 @@ positions: { | ||
for (var geomType in returnObj) { | ||
for (var numericProp in returnObj[geomType].numericProps) { | ||
for (const geomType in returnObj) { | ||
for (const numericProp in returnObj[geomType].numericProps) { | ||
returnObj[geomType].numericProps[numericProp] = { | ||
@@ -551,3 +397,3 @@ value: returnObj[geomType].numericProps[numericProp], | ||
function fillNumericProperties(object, properties, index, length) { | ||
for (var numericPropName in object.numericProps) { | ||
for (const numericPropName in object.numericProps) { | ||
if (numericPropName in properties) { | ||
@@ -560,27 +406,19 @@ object.numericProps[numericPropName].set(new Array(length).fill(properties[numericPropName]), index); | ||
function keepStringProperties(properties, numericKeys) { | ||
for (var key in properties) { | ||
if (numericKeys.includes(key)) { | ||
delete properties[key]; | ||
const props = {}; | ||
for (const key in properties) { | ||
if (!numericKeys.includes(key)) { | ||
props[key] = properties[key]; | ||
} | ||
} | ||
return properties; | ||
return props; | ||
} | ||
function fillCoords(array, coords, startVertex, coordLength) { | ||
var index = startVertex * coordLength; | ||
let index = startVertex * coordLength; | ||
var _iterator15 = _createForOfIteratorHelper(coords), | ||
_step15; | ||
try { | ||
for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) { | ||
var coord = _step15.value; | ||
array.set(coord, index); | ||
index += coordLength; | ||
} | ||
} catch (err) { | ||
_iterator15.e(err); | ||
} finally { | ||
_iterator15.f(); | ||
for (const coord of coords) { | ||
array.set(coord, index); | ||
index += coordLength; | ||
} | ||
@@ -590,5 +428,3 @@ } | ||
function flatten(arrays) { | ||
var _ref; | ||
return (_ref = []).concat.apply(_ref, (0, _toConsumableArray2["default"])(arrays)); | ||
return [].concat(...arrays); | ||
} | ||
@@ -595,0 +431,0 @@ |
@@ -9,16 +9,11 @@ "use strict"; | ||
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { 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 = o[Symbol.iterator](); }, 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; } } }; } | ||
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); } | ||
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; } | ||
function transformBinaryCoords(binaryFeatures, fn) { | ||
for (var _i = 0, _Object$values = Object.values(binaryFeatures); _i < _Object$values.length; _i++) { | ||
var binaryFeature = _Object$values[_i]; | ||
var positions = binaryFeature.positions; | ||
for (const binaryFeature of Object.values(binaryFeatures)) { | ||
const { | ||
positions | ||
} = binaryFeature; | ||
for (var i = 0; i < positions.value.length; i += positions.size) { | ||
var coord = Array.from(positions.value.subarray(i, i + positions.size)); | ||
var transformedCoord = fn(coord); | ||
for (let i = 0; i < positions.value.length; i += positions.size) { | ||
const coord = Array.from(positions.value.subarray(i, i + positions.size)); | ||
const transformedCoord = fn(coord); | ||
positions.value.set(transformedCoord, i); | ||
@@ -32,14 +27,4 @@ } | ||
function transformGeoJsonCoords(features, fn) { | ||
var _iterator = _createForOfIteratorHelper(features), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var feature = _step.value; | ||
feature.geometry.coordinates = coordMap(feature.geometry.coordinates, fn); | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
for (const feature of features) { | ||
feature.geometry.coordinates = coordMap(feature.geometry.coordinates, fn); | ||
} | ||
@@ -55,3 +40,3 @@ | ||
return array.map(function (item) { | ||
return array.map(item => { | ||
return coordMap(item, fn); | ||
@@ -58,0 +43,0 @@ }); |
@@ -1,4 +0,4 @@ | ||
var moduleExports = require('./index'); | ||
const moduleExports = require('./index'); | ||
var _global = typeof window === 'undefined' ? global : window; | ||
const _global = typeof window === 'undefined' ? global : window; | ||
@@ -5,0 +5,0 @@ _global.loaders = _global.loaders || {}; |
@@ -1,7 +0,1 @@ | ||
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { 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 = o[Symbol.iterator](); }, 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; } } }; } | ||
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); } | ||
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; } | ||
export function binaryToGeoJson(data, type, format) { | ||
@@ -12,3 +6,3 @@ if (format === 'geometry') { | ||
var dataArray = normalizeInput(data, type); | ||
const dataArray = normalizeInput(data, type); | ||
@@ -30,3 +24,3 @@ switch (deduceReturnType(dataArray)) { | ||
function normalizeInput(data, type) { | ||
var isHeterogeneousType = Boolean(data.points || data.lines || data.polygons); | ||
const isHeterogeneousType = Boolean(data.points || data.lines || data.polygons); | ||
@@ -38,3 +32,3 @@ if (!isHeterogeneousType) { | ||
var features = []; | ||
const features = []; | ||
@@ -64,3 +58,3 @@ if (data.points) { | ||
var data = dataArray[0]; | ||
const data = dataArray[0]; | ||
@@ -75,36 +69,25 @@ if (!(data.featureIds || data.globalFeatureIds || data.numericProps || data.properties)) { | ||
function parseFeatureCollection(dataArray) { | ||
var features = []; | ||
const features = []; | ||
var _iterator = _createForOfIteratorHelper(dataArray), | ||
_step; | ||
for (const data of dataArray) { | ||
if (data.featureIds.value.length === 0) { | ||
continue; | ||
} | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var data = _step.value; | ||
let lastIndex = 0; | ||
let lastValue = data.featureIds.value[0]; | ||
if (data.featureIds.value.length === 0) { | ||
for (let i = 0; i < data.featureIds.value.length; i++) { | ||
const currValue = data.featureIds.value[i]; | ||
if (currValue === lastValue) { | ||
continue; | ||
} | ||
var lastIndex = 0; | ||
var lastValue = data.featureIds.value[0]; | ||
features.push(parseFeature(data, lastIndex, i)); | ||
lastIndex = i; | ||
lastValue = currValue; | ||
} | ||
for (var i = 0; i < data.featureIds.value.length; i++) { | ||
var currValue = data.featureIds.value[i]; | ||
if (currValue === lastValue) { | ||
continue; | ||
} | ||
features.push(parseFeature(data, lastIndex, i)); | ||
lastIndex = i; | ||
lastValue = currValue; | ||
} | ||
features.push(parseFeature(data, lastIndex, data.featureIds.value.length)); | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
features.push(parseFeature(data, lastIndex, data.featureIds.value.length)); | ||
} | ||
@@ -116,8 +99,8 @@ | ||
function parseFeature(data, startIndex, endIndex) { | ||
var geometry = parseGeometry(data, startIndex, endIndex); | ||
var properties = parseProperties(data, startIndex, endIndex); | ||
const geometry = parseGeometry(data, startIndex, endIndex); | ||
const properties = parseProperties(data, startIndex, endIndex); | ||
return { | ||
type: 'Feature', | ||
geometry: geometry, | ||
properties: properties | ||
geometry, | ||
properties | ||
}; | ||
@@ -127,5 +110,5 @@ } | ||
function parseProperties(data, startIndex, endIndex) { | ||
var properties = Object.assign(data.properties[data.featureIds.value[startIndex]]); | ||
const properties = Object.assign(data.properties[data.featureIds.value[startIndex]]); | ||
for (var key in data.numericProps) { | ||
for (const key in data.numericProps) { | ||
properties[key] = data.numericProps[key].value[startIndex]; | ||
@@ -153,20 +136,16 @@ } | ||
function polygonToGeoJson(data) { | ||
var startIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -Infinity; | ||
var endIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Infinity; | ||
var positions = data.positions; | ||
var polygonIndices = data.polygonIndices.value.filter(function (x) { | ||
return x >= startIndex && x <= endIndex; | ||
}); | ||
var primitivePolygonIndices = data.primitivePolygonIndices.value.filter(function (x) { | ||
return x >= startIndex && x <= endIndex; | ||
}); | ||
var multi = polygonIndices.length > 2; | ||
var coordinates = []; | ||
function polygonToGeoJson(data, startIndex = -Infinity, endIndex = Infinity) { | ||
const { | ||
positions | ||
} = data; | ||
const polygonIndices = data.polygonIndices.value.filter(x => x >= startIndex && x <= endIndex); | ||
const primitivePolygonIndices = data.primitivePolygonIndices.value.filter(x => x >= startIndex && x <= endIndex); | ||
const multi = polygonIndices.length > 2; | ||
const coordinates = []; | ||
if (!multi) { | ||
for (var i = 0; i < primitivePolygonIndices.length - 1; i++) { | ||
var startRingIndex = primitivePolygonIndices[i]; | ||
var endRingIndex = primitivePolygonIndices[i + 1]; | ||
var ringCoordinates = ringToGeoJson(positions, startRingIndex, endRingIndex); | ||
for (let i = 0; i < primitivePolygonIndices.length - 1; i++) { | ||
const startRingIndex = primitivePolygonIndices[i]; | ||
const endRingIndex = primitivePolygonIndices[i + 1]; | ||
const ringCoordinates = ringToGeoJson(positions, startRingIndex, endRingIndex); | ||
coordinates.push(ringCoordinates); | ||
@@ -177,10 +156,10 @@ } | ||
type: 'Polygon', | ||
coordinates: coordinates | ||
coordinates | ||
}; | ||
} | ||
for (var _i = 0; _i < polygonIndices.length - 1; _i++) { | ||
var startPolygonIndex = polygonIndices[_i]; | ||
var endPolygonIndex = polygonIndices[_i + 1]; | ||
var polygonCoordinates = polygonToGeoJson(data, startPolygonIndex, endPolygonIndex).coordinates; | ||
for (let i = 0; i < polygonIndices.length - 1; i++) { | ||
const startPolygonIndex = polygonIndices[i]; | ||
const endPolygonIndex = polygonIndices[i + 1]; | ||
const polygonCoordinates = polygonToGeoJson(data, startPolygonIndex, endPolygonIndex).coordinates; | ||
coordinates.push(polygonCoordinates); | ||
@@ -191,28 +170,25 @@ } | ||
type: 'MultiPolygon', | ||
coordinates: coordinates | ||
coordinates | ||
}; | ||
} | ||
function lineStringToGeoJson(data) { | ||
var startIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -Infinity; | ||
var endIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Infinity; | ||
var positions = data.positions; | ||
var pathIndices = data.pathIndices.value.filter(function (x) { | ||
return x >= startIndex && x <= endIndex; | ||
}); | ||
var multi = pathIndices.length > 2; | ||
function lineStringToGeoJson(data, startIndex = -Infinity, endIndex = Infinity) { | ||
const { | ||
positions | ||
} = data; | ||
const pathIndices = data.pathIndices.value.filter(x => x >= startIndex && x <= endIndex); | ||
const multi = pathIndices.length > 2; | ||
if (!multi) { | ||
var _coordinates = ringToGeoJson(positions, pathIndices[0], pathIndices[1]); | ||
const coordinates = ringToGeoJson(positions, pathIndices[0], pathIndices[1]); | ||
return { | ||
type: 'LineString', | ||
coordinates: _coordinates | ||
coordinates | ||
}; | ||
} | ||
var coordinates = []; | ||
const coordinates = []; | ||
for (var i = 0; i < pathIndices.length - 1; i++) { | ||
var ringCoordinates = ringToGeoJson(positions, pathIndices[i], pathIndices[i + 1]); | ||
for (let i = 0; i < pathIndices.length - 1; i++) { | ||
const ringCoordinates = ringToGeoJson(positions, pathIndices[i], pathIndices[i + 1]); | ||
coordinates.push(ringCoordinates); | ||
@@ -223,3 +199,3 @@ } | ||
type: 'MultiLineString', | ||
coordinates: coordinates | ||
coordinates | ||
}; | ||
@@ -229,5 +205,7 @@ } | ||
function pointToGeoJson(data, startIndex, endIndex) { | ||
var positions = data.positions; | ||
var coordinates = ringToGeoJson(positions, startIndex, endIndex); | ||
var multi = coordinates.length > 1; | ||
const { | ||
positions | ||
} = data; | ||
const coordinates = ringToGeoJson(positions, startIndex, endIndex); | ||
const multi = coordinates.length > 1; | ||
@@ -237,3 +215,3 @@ if (multi) { | ||
type: 'MultiPoint', | ||
coordinates: coordinates | ||
coordinates | ||
}; | ||
@@ -251,5 +229,5 @@ } | ||
endIndex = endIndex || positions.value.length / positions.size; | ||
var ringCoordinates = []; | ||
const ringCoordinates = []; | ||
for (var j = startIndex; j < endIndex; j++) { | ||
for (let j = startIndex; j < endIndex; j++) { | ||
ringCoordinates.push(Array.from(positions.value.subarray(j * positions.size, (j + 1) * positions.size))); | ||
@@ -256,0 +234,0 @@ } |
@@ -1,12 +0,3 @@ | ||
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray"; | ||
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { 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 = o[Symbol.iterator](); }, 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; } } }; } | ||
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); } | ||
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; } | ||
export function geojsonToBinary(features) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var firstPassData = firstPass(features); | ||
export function geojsonToBinary(features, options = {}) { | ||
const firstPassData = firstPass(features); | ||
return secondPass(features, firstPassData, { | ||
@@ -18,219 +9,138 @@ coordLength: options.coordLength || firstPassData.coordLength, | ||
} | ||
export var TEST_EXPORTS = { | ||
firstPass: firstPass, | ||
secondPass: secondPass | ||
export const TEST_EXPORTS = { | ||
firstPass, | ||
secondPass | ||
}; | ||
function firstPass(features) { | ||
var pointPositionsCount = 0; | ||
var pointFeaturesCount = 0; | ||
var linePositionsCount = 0; | ||
var linePathsCount = 0; | ||
var lineFeaturesCount = 0; | ||
var polygonPositionsCount = 0; | ||
var polygonObjectsCount = 0; | ||
var polygonRingsCount = 0; | ||
var polygonFeaturesCount = 0; | ||
var coordLengths = new Set(); | ||
var numericPropKeys = {}; | ||
let pointPositionsCount = 0; | ||
let pointFeaturesCount = 0; | ||
let linePositionsCount = 0; | ||
let linePathsCount = 0; | ||
let lineFeaturesCount = 0; | ||
let polygonPositionsCount = 0; | ||
let polygonObjectsCount = 0; | ||
let polygonRingsCount = 0; | ||
let polygonFeaturesCount = 0; | ||
const coordLengths = new Set(); | ||
const numericPropKeys = {}; | ||
var _iterator = _createForOfIteratorHelper(features), | ||
_step; | ||
for (const feature of features) { | ||
const geometry = feature.geometry; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var feature = _step.value; | ||
var geometry = feature.geometry; | ||
switch (geometry.type) { | ||
case 'Point': | ||
pointFeaturesCount++; | ||
pointPositionsCount++; | ||
coordLengths.add(geometry.coordinates.length); | ||
break; | ||
switch (geometry.type) { | ||
case 'Point': | ||
pointFeaturesCount++; | ||
pointPositionsCount++; | ||
coordLengths.add(geometry.coordinates.length); | ||
break; | ||
case 'MultiPoint': | ||
pointFeaturesCount++; | ||
pointPositionsCount += geometry.coordinates.length; | ||
case 'MultiPoint': | ||
pointFeaturesCount++; | ||
pointPositionsCount += geometry.coordinates.length; | ||
for (const point of geometry.coordinates) { | ||
coordLengths.add(point.length); | ||
} | ||
var _iterator2 = _createForOfIteratorHelper(geometry.coordinates), | ||
_step2; | ||
break; | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var point = _step2.value; | ||
coordLengths.add(point.length); | ||
} | ||
} catch (err) { | ||
_iterator2.e(err); | ||
} finally { | ||
_iterator2.f(); | ||
} | ||
case 'LineString': | ||
lineFeaturesCount++; | ||
linePositionsCount += geometry.coordinates.length; | ||
linePathsCount++; | ||
break; | ||
for (const coord of geometry.coordinates) { | ||
coordLengths.add(coord.length); | ||
} | ||
case 'LineString': | ||
lineFeaturesCount++; | ||
linePositionsCount += geometry.coordinates.length; | ||
break; | ||
case 'MultiLineString': | ||
lineFeaturesCount++; | ||
for (const line of geometry.coordinates) { | ||
linePositionsCount += line.length; | ||
linePathsCount++; | ||
var _iterator3 = _createForOfIteratorHelper(geometry.coordinates), | ||
_step3; | ||
try { | ||
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { | ||
var coord = _step3.value; | ||
coordLengths.add(coord.length); | ||
} | ||
} catch (err) { | ||
_iterator3.e(err); | ||
} finally { | ||
_iterator3.f(); | ||
for (const coord of line) { | ||
coordLengths.add(coord.length); | ||
} | ||
} | ||
break; | ||
break; | ||
case 'MultiLineString': | ||
lineFeaturesCount++; | ||
case 'Polygon': | ||
polygonFeaturesCount++; | ||
polygonObjectsCount++; | ||
polygonRingsCount += geometry.coordinates.length; | ||
polygonPositionsCount += flatten(geometry.coordinates).length; | ||
var _iterator4 = _createForOfIteratorHelper(geometry.coordinates), | ||
_step4; | ||
for (const coord of flatten(geometry.coordinates)) { | ||
coordLengths.add(coord.length); | ||
} | ||
try { | ||
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { | ||
var line = _step4.value; | ||
linePositionsCount += line.length; | ||
linePathsCount++; | ||
break; | ||
var _iterator5 = _createForOfIteratorHelper(line), | ||
_step5; | ||
case 'MultiPolygon': | ||
polygonFeaturesCount++; | ||
try { | ||
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) { | ||
var _coord = _step5.value; | ||
coordLengths.add(_coord.length); | ||
} | ||
} catch (err) { | ||
_iterator5.e(err); | ||
} finally { | ||
_iterator5.f(); | ||
} | ||
} | ||
} catch (err) { | ||
_iterator4.e(err); | ||
} finally { | ||
_iterator4.f(); | ||
} | ||
break; | ||
case 'Polygon': | ||
polygonFeaturesCount++; | ||
for (const polygon of geometry.coordinates) { | ||
polygonObjectsCount++; | ||
polygonRingsCount += geometry.coordinates.length; | ||
polygonPositionsCount += flatten(geometry.coordinates).length; | ||
polygonRingsCount += polygon.length; | ||
polygonPositionsCount += flatten(polygon).length; | ||
var _iterator6 = _createForOfIteratorHelper(flatten(geometry.coordinates)), | ||
_step6; | ||
try { | ||
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) { | ||
var _coord2 = _step6.value; | ||
coordLengths.add(_coord2.length); | ||
} | ||
} catch (err) { | ||
_iterator6.e(err); | ||
} finally { | ||
_iterator6.f(); | ||
for (const coord of flatten(polygon)) { | ||
coordLengths.add(coord.length); | ||
} | ||
} | ||
break; | ||
break; | ||
case 'MultiPolygon': | ||
polygonFeaturesCount++; | ||
default: | ||
throw new Error("Unsupported geometry type: ".concat(geometry.type)); | ||
} | ||
var _iterator7 = _createForOfIteratorHelper(geometry.coordinates), | ||
_step7; | ||
try { | ||
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) { | ||
var polygon = _step7.value; | ||
polygonObjectsCount++; | ||
polygonRingsCount += polygon.length; | ||
polygonPositionsCount += flatten(polygon).length; | ||
var _iterator8 = _createForOfIteratorHelper(flatten(polygon)), | ||
_step8; | ||
try { | ||
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) { | ||
var _coord3 = _step8.value; | ||
coordLengths.add(_coord3.length); | ||
} | ||
} catch (err) { | ||
_iterator8.e(err); | ||
} finally { | ||
_iterator8.f(); | ||
} | ||
} | ||
} catch (err) { | ||
_iterator7.e(err); | ||
} finally { | ||
_iterator7.f(); | ||
} | ||
break; | ||
default: | ||
throw new Error("Unsupported geometry type: ".concat(geometry.type)); | ||
if (feature.properties) { | ||
for (const key in feature.properties) { | ||
const val = feature.properties[key]; | ||
numericPropKeys[key] = numericPropKeys[key] || numericPropKeys[key] === undefined ? isNumeric(val) : numericPropKeys[key]; | ||
} | ||
if (feature.properties) { | ||
for (var key in feature.properties) { | ||
var val = feature.properties[key]; | ||
numericPropKeys[key] = numericPropKeys[key] || numericPropKeys[key] === undefined ? isNumeric(val) : numericPropKeys[key]; | ||
} | ||
} | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
return { | ||
pointPositionsCount: pointPositionsCount, | ||
pointFeaturesCount: pointFeaturesCount, | ||
linePositionsCount: linePositionsCount, | ||
linePathsCount: linePathsCount, | ||
lineFeaturesCount: lineFeaturesCount, | ||
coordLength: Math.max.apply(Math, _toConsumableArray(coordLengths)), | ||
polygonPositionsCount: polygonPositionsCount, | ||
polygonObjectsCount: polygonObjectsCount, | ||
polygonRingsCount: polygonRingsCount, | ||
polygonFeaturesCount: polygonFeaturesCount, | ||
numericPropKeys: Object.keys(numericPropKeys).filter(function (k) { | ||
return numericPropKeys[k]; | ||
}) | ||
pointPositionsCount, | ||
pointFeaturesCount, | ||
linePositionsCount, | ||
linePathsCount, | ||
lineFeaturesCount, | ||
coordLength: Math.max(...coordLengths), | ||
polygonPositionsCount, | ||
polygonObjectsCount, | ||
polygonRingsCount, | ||
polygonFeaturesCount, | ||
numericPropKeys: Object.keys(numericPropKeys).filter(k => numericPropKeys[k]) | ||
}; | ||
} | ||
function secondPass(features) { | ||
var firstPassData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var pointPositionsCount = firstPassData.pointPositionsCount, | ||
pointFeaturesCount = firstPassData.pointFeaturesCount, | ||
linePositionsCount = firstPassData.linePositionsCount, | ||
linePathsCount = firstPassData.linePathsCount, | ||
lineFeaturesCount = firstPassData.lineFeaturesCount, | ||
polygonPositionsCount = firstPassData.polygonPositionsCount, | ||
polygonObjectsCount = firstPassData.polygonObjectsCount, | ||
polygonRingsCount = firstPassData.polygonRingsCount, | ||
polygonFeaturesCount = firstPassData.polygonFeaturesCount; | ||
var coordLength = options.coordLength, | ||
numericPropKeys = options.numericPropKeys, | ||
_options$PositionData = options.PositionDataType, | ||
PositionDataType = _options$PositionData === void 0 ? Float32Array : _options$PositionData; | ||
var GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array; | ||
var points = { | ||
function secondPass(features, firstPassData = {}, options = {}) { | ||
const { | ||
pointPositionsCount, | ||
pointFeaturesCount, | ||
linePositionsCount, | ||
linePathsCount, | ||
lineFeaturesCount, | ||
polygonPositionsCount, | ||
polygonObjectsCount, | ||
polygonRingsCount, | ||
polygonFeaturesCount | ||
} = firstPassData; | ||
const { | ||
coordLength, | ||
numericPropKeys, | ||
PositionDataType = Float32Array | ||
} = options; | ||
const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array; | ||
const points = { | ||
positions: new PositionDataType(pointPositionsCount * coordLength), | ||
@@ -242,3 +152,3 @@ globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount), | ||
}; | ||
var lines = { | ||
const lines = { | ||
pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1), | ||
@@ -251,3 +161,3 @@ positions: new PositionDataType(linePositionsCount * coordLength), | ||
}; | ||
var polygons = { | ||
const polygons = { | ||
polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1), | ||
@@ -262,17 +172,5 @@ primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1), | ||
for (var _i = 0, _arr = [points, lines, polygons]; _i < _arr.length; _i++) { | ||
var object = _arr[_i]; | ||
var _iterator9 = _createForOfIteratorHelper(numericPropKeys), | ||
_step9; | ||
try { | ||
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) { | ||
var propName = _step9.value; | ||
object.numericProps[propName] = new Float32Array(object.positions.length / coordLength); | ||
} | ||
} catch (err) { | ||
_iterator9.e(err); | ||
} finally { | ||
_iterator9.f(); | ||
for (const object of [points, lines, polygons]) { | ||
for (const propName of numericPropKeys) { | ||
object.numericProps[propName] = new Float32Array(object.positions.length / coordLength); | ||
} | ||
@@ -284,3 +182,3 @@ } | ||
polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount; | ||
var indexMap = { | ||
const indexMap = { | ||
pointPosition: 0, | ||
@@ -298,58 +196,48 @@ pointFeature: 0, | ||
var _iterator10 = _createForOfIteratorHelper(features), | ||
_step10; | ||
for (const feature of features) { | ||
const geometry = feature.geometry; | ||
const properties = feature.properties || {}; | ||
try { | ||
for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) { | ||
var feature = _step10.value; | ||
var geometry = feature.geometry; | ||
var properties = feature.properties || {}; | ||
switch (geometry.type) { | ||
case 'Point': | ||
handlePoint(geometry.coordinates, points, indexMap, coordLength, properties); | ||
points.properties.push(keepStringProperties(properties, numericPropKeys)); | ||
indexMap.pointFeature++; | ||
break; | ||
switch (geometry.type) { | ||
case 'Point': | ||
handlePoint(geometry.coordinates, points, indexMap, coordLength, properties); | ||
points.properties.push(keepStringProperties(properties, numericPropKeys)); | ||
indexMap.pointFeature++; | ||
break; | ||
case 'MultiPoint': | ||
handleMultiPoint(geometry.coordinates, points, indexMap, coordLength, properties); | ||
points.properties.push(keepStringProperties(properties, numericPropKeys)); | ||
indexMap.pointFeature++; | ||
break; | ||
case 'MultiPoint': | ||
handleMultiPoint(geometry.coordinates, points, indexMap, coordLength, properties); | ||
points.properties.push(keepStringProperties(properties, numericPropKeys)); | ||
indexMap.pointFeature++; | ||
break; | ||
case 'LineString': | ||
handleLineString(geometry.coordinates, lines, indexMap, coordLength, properties); | ||
lines.properties.push(keepStringProperties(properties, numericPropKeys)); | ||
indexMap.lineFeature++; | ||
break; | ||
case 'LineString': | ||
handleLineString(geometry.coordinates, lines, indexMap, coordLength, properties); | ||
lines.properties.push(keepStringProperties(properties, numericPropKeys)); | ||
indexMap.lineFeature++; | ||
break; | ||
case 'MultiLineString': | ||
handleMultiLineString(geometry.coordinates, lines, indexMap, coordLength, properties); | ||
lines.properties.push(keepStringProperties(properties, numericPropKeys)); | ||
indexMap.lineFeature++; | ||
break; | ||
case 'MultiLineString': | ||
handleMultiLineString(geometry.coordinates, lines, indexMap, coordLength, properties); | ||
lines.properties.push(keepStringProperties(properties, numericPropKeys)); | ||
indexMap.lineFeature++; | ||
break; | ||
case 'Polygon': | ||
handlePolygon(geometry.coordinates, polygons, indexMap, coordLength, properties); | ||
polygons.properties.push(keepStringProperties(properties, numericPropKeys)); | ||
indexMap.polygonFeature++; | ||
break; | ||
case 'Polygon': | ||
handlePolygon(geometry.coordinates, polygons, indexMap, coordLength, properties); | ||
polygons.properties.push(keepStringProperties(properties, numericPropKeys)); | ||
indexMap.polygonFeature++; | ||
break; | ||
case 'MultiPolygon': | ||
handleMultiPolygon(geometry.coordinates, polygons, indexMap, coordLength, properties); | ||
polygons.properties.push(keepStringProperties(properties, numericPropKeys)); | ||
indexMap.polygonFeature++; | ||
break; | ||
case 'MultiPolygon': | ||
handleMultiPolygon(geometry.coordinates, polygons, indexMap, coordLength, properties); | ||
polygons.properties.push(keepStringProperties(properties, numericPropKeys)); | ||
indexMap.polygonFeature++; | ||
break; | ||
default: | ||
throw new Error('Invalid geometry type'); | ||
} | ||
default: | ||
throw new Error('Invalid geometry type'); | ||
} | ||
indexMap.feature++; | ||
} | ||
} catch (err) { | ||
_iterator10.e(err); | ||
} finally { | ||
_iterator10.f(); | ||
indexMap.feature++; | ||
} | ||
@@ -369,14 +257,4 @@ | ||
function handleMultiPoint(coords, points, indexMap, coordLength, properties) { | ||
var _iterator11 = _createForOfIteratorHelper(coords), | ||
_step11; | ||
try { | ||
for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) { | ||
var point = _step11.value; | ||
handlePoint(point, points, indexMap, coordLength, properties); | ||
} | ||
} catch (err) { | ||
_iterator11.e(err); | ||
} finally { | ||
_iterator11.f(); | ||
for (const point of coords) { | ||
handlePoint(point, points, indexMap, coordLength, properties); | ||
} | ||
@@ -389,3 +267,3 @@ } | ||
fillCoords(lines.positions, coords, indexMap.linePosition, coordLength); | ||
var nPositions = coords.length; | ||
const nPositions = coords.length; | ||
fillNumericProperties(lines, properties, indexMap.linePosition, nPositions); | ||
@@ -398,14 +276,4 @@ lines.globalFeatureIds.set(new Uint32Array(nPositions).fill(indexMap.feature), indexMap.linePosition); | ||
function handleMultiLineString(coords, lines, indexMap, coordLength, properties) { | ||
var _iterator12 = _createForOfIteratorHelper(coords), | ||
_step12; | ||
try { | ||
for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) { | ||
var line = _step12.value; | ||
handleLineString(line, lines, indexMap, coordLength, properties); | ||
} | ||
} catch (err) { | ||
_iterator12.e(err); | ||
} finally { | ||
_iterator12.f(); | ||
for (const line of coords) { | ||
handleLineString(line, lines, indexMap, coordLength, properties); | ||
} | ||
@@ -418,21 +286,11 @@ } | ||
var _iterator13 = _createForOfIteratorHelper(coords), | ||
_step13; | ||
try { | ||
for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) { | ||
var ring = _step13.value; | ||
polygons.primitivePolygonIndices[indexMap.polygonRing] = indexMap.polygonPosition; | ||
indexMap.polygonRing++; | ||
fillCoords(polygons.positions, ring, indexMap.polygonPosition, coordLength); | ||
var nPositions = ring.length; | ||
fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions); | ||
polygons.globalFeatureIds.set(new Uint32Array(nPositions).fill(indexMap.feature), indexMap.polygonPosition); | ||
polygons.featureIds.set(new Uint32Array(nPositions).fill(indexMap.polygonFeature), indexMap.polygonPosition); | ||
indexMap.polygonPosition += nPositions; | ||
} | ||
} catch (err) { | ||
_iterator13.e(err); | ||
} finally { | ||
_iterator13.f(); | ||
for (const ring of coords) { | ||
polygons.primitivePolygonIndices[indexMap.polygonRing] = indexMap.polygonPosition; | ||
indexMap.polygonRing++; | ||
fillCoords(polygons.positions, ring, indexMap.polygonPosition, coordLength); | ||
const nPositions = ring.length; | ||
fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions); | ||
polygons.globalFeatureIds.set(new Uint32Array(nPositions).fill(indexMap.feature), indexMap.polygonPosition); | ||
polygons.featureIds.set(new Uint32Array(nPositions).fill(indexMap.polygonFeature), indexMap.polygonPosition); | ||
indexMap.polygonPosition += nPositions; | ||
} | ||
@@ -442,14 +300,4 @@ } | ||
function handleMultiPolygon(coords, polygons, indexMap, coordLength, properties) { | ||
var _iterator14 = _createForOfIteratorHelper(coords), | ||
_step14; | ||
try { | ||
for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) { | ||
var polygon = _step14.value; | ||
handlePolygon(polygon, polygons, indexMap, coordLength, properties); | ||
} | ||
} catch (err) { | ||
_iterator14.e(err); | ||
} finally { | ||
_iterator14.f(); | ||
for (const polygon of coords) { | ||
handlePolygon(polygon, polygons, indexMap, coordLength, properties); | ||
} | ||
@@ -459,3 +307,3 @@ } | ||
function makeAccessorObjects(points, lines, polygons, coordLength) { | ||
var returnObj = { | ||
const returnObj = { | ||
points: { | ||
@@ -523,4 +371,4 @@ positions: { | ||
for (var geomType in returnObj) { | ||
for (var numericProp in returnObj[geomType].numericProps) { | ||
for (const geomType in returnObj) { | ||
for (const numericProp in returnObj[geomType].numericProps) { | ||
returnObj[geomType].numericProps[numericProp] = { | ||
@@ -537,3 +385,3 @@ value: returnObj[geomType].numericProps[numericProp], | ||
function fillNumericProperties(object, properties, index, length) { | ||
for (var numericPropName in object.numericProps) { | ||
for (const numericPropName in object.numericProps) { | ||
if (numericPropName in properties) { | ||
@@ -546,27 +394,19 @@ object.numericProps[numericPropName].set(new Array(length).fill(properties[numericPropName]), index); | ||
function keepStringProperties(properties, numericKeys) { | ||
for (var key in properties) { | ||
if (numericKeys.includes(key)) { | ||
delete properties[key]; | ||
const props = {}; | ||
for (const key in properties) { | ||
if (!numericKeys.includes(key)) { | ||
props[key] = properties[key]; | ||
} | ||
} | ||
return properties; | ||
return props; | ||
} | ||
function fillCoords(array, coords, startVertex, coordLength) { | ||
var index = startVertex * coordLength; | ||
let index = startVertex * coordLength; | ||
var _iterator15 = _createForOfIteratorHelper(coords), | ||
_step15; | ||
try { | ||
for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) { | ||
var coord = _step15.value; | ||
array.set(coord, index); | ||
index += coordLength; | ||
} | ||
} catch (err) { | ||
_iterator15.e(err); | ||
} finally { | ||
_iterator15.f(); | ||
for (const coord of coords) { | ||
array.set(coord, index); | ||
index += coordLength; | ||
} | ||
@@ -576,5 +416,3 @@ } | ||
function flatten(arrays) { | ||
var _ref; | ||
return (_ref = []).concat.apply(_ref, _toConsumableArray(arrays)); | ||
return [].concat(...arrays); | ||
} | ||
@@ -581,0 +419,0 @@ |
@@ -1,15 +0,10 @@ | ||
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { 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 = o[Symbol.iterator](); }, 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; } } }; } | ||
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); } | ||
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; } | ||
export function transformBinaryCoords(binaryFeatures, fn) { | ||
for (var _i = 0, _Object$values = Object.values(binaryFeatures); _i < _Object$values.length; _i++) { | ||
var binaryFeature = _Object$values[_i]; | ||
var positions = binaryFeature.positions; | ||
for (const binaryFeature of Object.values(binaryFeatures)) { | ||
const { | ||
positions | ||
} = binaryFeature; | ||
for (var i = 0; i < positions.value.length; i += positions.size) { | ||
var coord = Array.from(positions.value.subarray(i, i + positions.size)); | ||
var transformedCoord = fn(coord); | ||
for (let i = 0; i < positions.value.length; i += positions.size) { | ||
const coord = Array.from(positions.value.subarray(i, i + positions.size)); | ||
const transformedCoord = fn(coord); | ||
positions.value.set(transformedCoord, i); | ||
@@ -22,14 +17,4 @@ } | ||
export function transformGeoJsonCoords(features, fn) { | ||
var _iterator = _createForOfIteratorHelper(features), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var feature = _step.value; | ||
feature.geometry.coordinates = coordMap(feature.geometry.coordinates, fn); | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
for (const feature of features) { | ||
feature.geometry.coordinates = coordMap(feature.geometry.coordinates, fn); | ||
} | ||
@@ -45,3 +30,3 @@ | ||
return array.map(function (item) { | ||
return array.map(item => { | ||
return coordMap(item, fn); | ||
@@ -48,0 +33,0 @@ }); |
{ | ||
"name": "@loaders.gl/gis", | ||
"description": "Helpers for GIS category data", | ||
"version": "3.0.0-alpha.4", | ||
"version": "3.0.0-alpha.5", | ||
"license": "MIT", | ||
@@ -20,3 +20,2 @@ "publishConfig": { | ||
"module": "dist/esm/index.js", | ||
"esnext": "dist/es6/index.js", | ||
"sideEffects": false, | ||
@@ -29,3 +28,3 @@ "files": [ | ||
"dependencies": { | ||
"@loaders.gl/loader-utils": "3.0.0-alpha.4", | ||
"@loaders.gl/loader-utils": "3.0.0-alpha.5", | ||
"@mapbox/vector-tile": "^1.3.1", | ||
@@ -37,3 +36,3 @@ "pbf": "^3.2.1" | ||
}, | ||
"gitHead": "51999b245ade896a4b5750269e68154ee299d035" | ||
"gitHead": "a07341a8276a7435df4f79f035a3a2b2354e19c4" | ||
} |
@@ -394,10 +394,10 @@ // Convert GeoJSON features to flat binary arrays | ||
// Keep string properties in object | ||
// Note: this mutates the properties object | ||
function keepStringProperties(properties, numericKeys) { | ||
const props = {}; | ||
for (const key in properties) { | ||
if (numericKeys.includes(key)) { | ||
delete properties[key]; | ||
if (!numericKeys.includes(key)) { | ||
props[key] = properties[key]; | ||
} | ||
} | ||
return properties; | ||
return props; | ||
} | ||
@@ -404,0 +404,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4
172387
43
2104
+ Added@loaders.gl/loader-utils@3.0.0-alpha.5(transitive)
+ Added@loaders.gl/worker-utils@3.0.0-alpha.5(transitive)
- Removed@loaders.gl/loader-utils@3.0.0-alpha.4(transitive)