loaders.gl
Version:
Framework-independent loaders for 3D graphics formats
36 lines (29 loc) • 1.65 kB
JavaScript
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
export default function normalizeKML(kml) {
// Convert coordinates to [lng, lat, z] format
for (const key in kml) {
for (const item of kml[key]) {
normalizeKMLItem(item, key);
}
}
return kml;
} // Normalizes coordinates to lng/lat format
function normalizeKMLItem(item) {
if (item.coordinates && item.coordinates.length) {
if (Array.isArray(item.coordinates[0])) {
item.coordinates = item.coordinates.map(([lat, lng, z = 0]) => [lng, lat, z]);
} else {
// Marker coordinates are just a single coord (not an array of coords)
const _item$coordinates = _slicedToArray(item.coordinates, 3),
lat = _item$coordinates[0],
lng = _item$coordinates[1],
_item$coordinates$ = _item$coordinates[2],
z = _item$coordinates$ === void 0 ? 0 : _item$coordinates$;
item.coordinates = [lng, lat, z];
}
}
}
//# sourceMappingURL=kml-normalizer.js.map