@loaders.gl/gis
Advanced tools
Comparing version 3.0.0-beta.10 to 3.0.1
@@ -12,2 +12,8 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "binaryToGeojson", { | ||
enumerable: true, | ||
get: function get() { | ||
return _binaryToGeojson.binaryToGeojson; | ||
} | ||
}); | ||
Object.defineProperty(exports, "binaryToGeoJson", { | ||
@@ -19,6 +25,6 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(exports, "getSingleFeature", { | ||
Object.defineProperty(exports, "binaryToGeometry", { | ||
enumerable: true, | ||
get: function get() { | ||
return _binaryToGeojson.getSingleFeature; | ||
return _binaryToGeojson.binaryToGeometry; | ||
} | ||
@@ -25,0 +31,0 @@ }); |
@@ -6,4 +6,5 @@ "use strict"; | ||
}); | ||
exports.binaryToGeojson = binaryToGeojson; | ||
exports.binaryToGeoJson = binaryToGeoJson; | ||
exports.getSingleFeature = getSingleFeature; | ||
exports.binaryToGeometry = binaryToGeometry; | ||
@@ -16,2 +17,12 @@ 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; } } }; } | ||
function binaryToGeojson(data, options) { | ||
var globalFeatureId = options === null || options === void 0 ? void 0 : options.globalFeatureId; | ||
if (globalFeatureId !== undefined) { | ||
return getSingleFeature(data, globalFeatureId); | ||
} | ||
return parseFeatures(data, options === null || options === void 0 ? void 0 : options.type); | ||
} | ||
function binaryToGeoJson(data, type) { | ||
@@ -25,3 +36,3 @@ var format = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'feature'; | ||
case 'geometry': | ||
return parseGeometry(data); | ||
return binaryToGeometry(data); | ||
@@ -70,3 +81,3 @@ default: | ||
return null; | ||
throw new Error("featureId:".concat(globalFeatureId, " not found")); | ||
} | ||
@@ -76,18 +87,6 @@ | ||
var dataArray = normalizeInput(data, type); | ||
var returnType = deduceReturnType(dataArray); | ||
switch (returnType) { | ||
case 'Geometry': | ||
return parseGeometry(dataArray[0]); | ||
case 'FeatureCollection': | ||
return parseFeatureCollection(dataArray); | ||
default: | ||
var unexpectedInput = returnType; | ||
throw new Error(unexpectedInput); | ||
} | ||
return parseFeatureCollection(dataArray); | ||
} | ||
function parseGeometry(data, startIndex, endIndex) { | ||
function binaryToGeometry(data, startIndex, endIndex) { | ||
switch (data.type) { | ||
@@ -137,16 +136,2 @@ case 'Point': | ||
function deduceReturnType(dataArray) { | ||
if (dataArray.length > 1) { | ||
return 'FeatureCollection'; | ||
} | ||
var data = dataArray[0]; | ||
if (!(data.featureIds || data.globalFeatureIds || data.numericProps || data.properties)) { | ||
return 'Geometry'; | ||
} | ||
return 'FeatureCollection'; | ||
} | ||
function parseFeatureCollection(dataArray) { | ||
@@ -193,3 +178,3 @@ var features = []; | ||
function parseFeature(data, startIndex, endIndex) { | ||
var geometry = parseGeometry(data, startIndex, endIndex); | ||
var geometry = binaryToGeometry(data, startIndex, endIndex); | ||
var properties = parseProperties(data, startIndex, endIndex); | ||
@@ -196,0 +181,0 @@ return { |
export { geojsonToBinary } from './lib/geojson-to-binary'; | ||
export { binaryToGeoJson, getSingleFeature } from './lib/binary-to-geojson'; | ||
export { binaryToGeojson, binaryToGeoJson, binaryToGeometry } from './lib/binary-to-geojson'; | ||
export { transformBinaryCoords, transformGeoJsonCoords } from './lib/transform'; | ||
//# sourceMappingURL=index.js.map |
@@ -0,1 +1,10 @@ | ||
export function binaryToGeojson(data, options) { | ||
const globalFeatureId = options === null || options === void 0 ? void 0 : options.globalFeatureId; | ||
if (globalFeatureId !== undefined) { | ||
return getSingleFeature(data, globalFeatureId); | ||
} | ||
return parseFeatures(data, options === null || options === void 0 ? void 0 : options.type); | ||
} | ||
export function binaryToGeoJson(data, type, format = 'feature') { | ||
@@ -7,3 +16,3 @@ switch (format) { | ||
case 'geometry': | ||
return parseGeometry(data); | ||
return binaryToGeometry(data); | ||
@@ -14,3 +23,4 @@ default: | ||
} | ||
export function getSingleFeature(data, globalFeatureId) { | ||
function getSingleFeature(data, globalFeatureId) { | ||
const dataArray = normalizeInput(data); | ||
@@ -42,3 +52,3 @@ | ||
return null; | ||
throw new Error("featureId:".concat(globalFeatureId, " not found")); | ||
} | ||
@@ -48,18 +58,6 @@ | ||
const dataArray = normalizeInput(data, type); | ||
const returnType = deduceReturnType(dataArray); | ||
switch (returnType) { | ||
case 'Geometry': | ||
return parseGeometry(dataArray[0]); | ||
case 'FeatureCollection': | ||
return parseFeatureCollection(dataArray); | ||
default: | ||
const unexpectedInput = returnType; | ||
throw new Error(unexpectedInput); | ||
} | ||
return parseFeatureCollection(dataArray); | ||
} | ||
function parseGeometry(data, startIndex, endIndex) { | ||
export function binaryToGeometry(data, startIndex, endIndex) { | ||
switch (data.type) { | ||
@@ -109,16 +107,2 @@ case 'Point': | ||
function deduceReturnType(dataArray) { | ||
if (dataArray.length > 1) { | ||
return 'FeatureCollection'; | ||
} | ||
const data = dataArray[0]; | ||
if (!(data.featureIds || data.globalFeatureIds || data.numericProps || data.properties)) { | ||
return 'Geometry'; | ||
} | ||
return 'FeatureCollection'; | ||
} | ||
function parseFeatureCollection(dataArray) { | ||
@@ -154,3 +138,3 @@ const features = []; | ||
function parseFeature(data, startIndex, endIndex) { | ||
const geometry = parseGeometry(data, startIndex, endIndex); | ||
const geometry = binaryToGeometry(data, startIndex, endIndex); | ||
const properties = parseProperties(data, startIndex, endIndex); | ||
@@ -157,0 +141,0 @@ return { |
{ | ||
"name": "@loaders.gl/gis", | ||
"description": "Helpers for GIS category data", | ||
"version": "3.0.0-beta.10", | ||
"version": "3.0.1", | ||
"license": "MIT", | ||
@@ -27,4 +27,4 @@ "publishConfig": { | ||
"dependencies": { | ||
"@loaders.gl/loader-utils": "3.0.0-beta.10", | ||
"@loaders.gl/schema": "3.0.0-beta.10", | ||
"@loaders.gl/loader-utils": "3.0.1", | ||
"@loaders.gl/schema": "3.0.1", | ||
"@mapbox/vector-tile": "^1.3.1", | ||
@@ -36,3 +36,3 @@ "pbf": "^3.2.1" | ||
}, | ||
"gitHead": "8c868bde88bf63cbd412f5ac56d9957e8a867154" | ||
"gitHead": "b3e49433ffb018dc5526e75cbeaa5760e3e2eaaa" | ||
} |
@@ -5,3 +5,3 @@ // Types from `@loaders.gl/schema` | ||
export {geojsonToBinary} from './lib/geojson-to-binary'; | ||
export {binaryToGeoJson, getSingleFeature} from './lib/binary-to-geojson'; | ||
export {binaryToGeojson, binaryToGeoJson, binaryToGeometry} from './lib/binary-to-geojson'; | ||
export {transformBinaryCoords, transformGeoJsonCoords} from './lib/transform'; |
@@ -23,9 +23,27 @@ import type { | ||
type BinaryToGeoJsonOptions = { | ||
type?: BinaryGeometryType; | ||
globalFeatureId?: number; | ||
}; | ||
/** | ||
* Convert binary geometry representation to GeoJSON | ||
* @param data geometry data in binary representation | ||
* @param type Input data type: Point, LineString, or Polygon | ||
* @param format Output format, either geometry or feature | ||
* @param options | ||
* @param options.type Input data type: Point, LineString, or Polygon | ||
* @param options.featureId Global feature id. If specified, only a single feature is extracted | ||
* @return GeoJSON objects | ||
*/ | ||
export function binaryToGeojson( | ||
data: BinaryFeatures, | ||
options?: BinaryToGeoJsonOptions | ||
): Feature[] | Feature { | ||
const globalFeatureId = options?.globalFeatureId; | ||
if (globalFeatureId !== undefined) { | ||
return getSingleFeature(data, globalFeatureId); | ||
} | ||
return parseFeatures(data, options?.type); | ||
} | ||
/** @deprecated use `binaryToGeojson` or `binaryToGeometry` instead */ | ||
export function binaryToGeoJson( | ||
@@ -38,5 +56,5 @@ data: BinaryGeometry | BinaryFeatures, | ||
case 'feature': | ||
return parseFeatures(data, type); | ||
return parseFeatures(data as BinaryFeatures, type); | ||
case 'geometry': | ||
return parseGeometry(data as BinaryGeometry); | ||
return binaryToGeometry(data as BinaryGeometry); | ||
default: | ||
@@ -52,3 +70,3 @@ throw new Error(format); | ||
*/ | ||
export function getSingleFeature(data: BinaryFeatures, globalFeatureId: number) { | ||
function getSingleFeature(data: BinaryFeatures, globalFeatureId: number): Feature { | ||
const dataArray = normalizeInput(data); | ||
@@ -78,21 +96,16 @@ for (const data of dataArray) { | ||
return null; | ||
throw new Error(`featureId:${globalFeatureId} not found`); | ||
} | ||
function parseFeatures(data, type): Geometry | Feature[] { | ||
function parseFeatures(data: BinaryFeatures, type?: BinaryGeometryType): Feature[] { | ||
const dataArray = normalizeInput(data, type); | ||
const returnType = deduceReturnType(dataArray); | ||
switch (returnType) { | ||
case 'Geometry': | ||
return parseGeometry(dataArray[0]); | ||
case 'FeatureCollection': | ||
return parseFeatureCollection(dataArray); | ||
default: | ||
const unexpectedInput: never = returnType; | ||
throw new Error(unexpectedInput); | ||
} | ||
return parseFeatureCollection(dataArray); | ||
} | ||
/** Parse input binary data and return a valid GeoJSON geometry object */ | ||
function parseGeometry(data: BinaryGeometry, startIndex?: number, endIndex?: number): Geometry { | ||
export function binaryToGeometry( | ||
data: BinaryGeometry, | ||
startIndex?: number, | ||
endIndex?: number | ||
): Geometry { | ||
switch (data.type) { | ||
@@ -143,20 +156,2 @@ case 'Point': | ||
/** | ||
* Determine whether a geometry or feature collection should be returned | ||
* If the input data doesn't have property identifiers, returns a single geometry | ||
*/ | ||
function deduceReturnType(dataArray): 'FeatureCollection' | 'Geometry' { | ||
// If more than one item in dataArray, multiple geometry types, must be a featurecollection | ||
if (dataArray.length > 1) { | ||
return 'FeatureCollection'; | ||
} | ||
const data = dataArray[0]; | ||
if (!(data.featureIds || data.globalFeatureIds || data.numericProps || data.properties)) { | ||
return 'Geometry'; | ||
} | ||
return 'FeatureCollection'; | ||
} | ||
/** Parse input binary data and return an array of GeoJSON Features */ | ||
@@ -194,3 +189,3 @@ function parseFeatureCollection(dataArray): Feature[] { | ||
function parseFeature(data, startIndex?: number, endIndex?: number): Feature { | ||
const geometry = parseGeometry(data, startIndex, endIndex); | ||
const geometry = binaryToGeometry(data, startIndex, endIndex); | ||
const properties = parseProperties(data, startIndex, endIndex); | ||
@@ -197,0 +192,0 @@ return {type: 'Feature', geometry, properties}; |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
198754
2236
+ Added@loaders.gl/loader-utils@3.0.1(transitive)
+ Added@loaders.gl/schema@3.0.1(transitive)
+ Added@loaders.gl/worker-utils@3.0.1(transitive)
- Removed@loaders.gl/loader-utils@3.0.0-beta.10(transitive)
- Removed@loaders.gl/schema@3.0.0-beta.10(transitive)
- Removed@loaders.gl/worker-utils@3.0.0-beta.10(transitive)
Updated@loaders.gl/schema@3.0.1