@hestia-earth/schema-convert 20.1.0 → 20.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/json.js +34 -25
- package/package.json +1 -1
package/json.js
CHANGED
|
@@ -242,19 +242,22 @@ var validateGeoJSONFormat = function (value) {
|
|
|
242
242
|
return (!allowedGeoJSONTypes.includes(value.type)
|
|
243
243
|
? throwError("Invalid GeoJSON \"type\". Allowed values are: ".concat(allowedGeoJSONTypes.join(', ')))
|
|
244
244
|
: 'geometries' in value
|
|
245
|
-
?
|
|
245
|
+
? !value.geometries.length
|
|
246
|
+
? throwError('This GeoJSON appears to be empty. Please either add coordinates or remove the field.')
|
|
247
|
+
: (value.geometries || []).every(validateGeoJSONGeometryType)
|
|
246
248
|
: 'geometry' in value
|
|
247
249
|
? validateGeoJSONGeometryType(value.geometry)
|
|
248
250
|
: 'features' in value
|
|
249
|
-
?
|
|
251
|
+
? !value.features.length
|
|
252
|
+
? throwError('This GeoJSON appears to be empty. Please either add coordinates or remove the field.')
|
|
253
|
+
: (value.features || []).every(validateGeoJSONFormat)
|
|
250
254
|
: true)
|
|
251
255
|
? value
|
|
252
256
|
: null;
|
|
253
257
|
};
|
|
254
|
-
var
|
|
255
|
-
var result;
|
|
258
|
+
var parseWtkValue = function (value) {
|
|
256
259
|
try {
|
|
257
|
-
|
|
260
|
+
return {
|
|
258
261
|
type: 'FeatureCollection',
|
|
259
262
|
features: [{
|
|
260
263
|
type: 'Feature',
|
|
@@ -263,30 +266,36 @@ var parseGeoJSONValue = function (value) {
|
|
|
263
266
|
}]
|
|
264
267
|
};
|
|
265
268
|
}
|
|
266
|
-
catch (
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
269
|
+
catch (error) {
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
var parseJsonValue = function (value) {
|
|
274
|
+
try {
|
|
275
|
+
var data = JSON.parse(value);
|
|
276
|
+
return ['Polygon', 'MultiPolygon'].includes(data.type)
|
|
277
|
+
? {
|
|
278
|
+
type: 'FeatureCollection',
|
|
279
|
+
features: [{
|
|
280
|
+
type: 'Feature',
|
|
281
|
+
properties: {},
|
|
282
|
+
geometry: data
|
|
283
|
+
}]
|
|
284
|
+
}
|
|
285
|
+
: ['Feature'].includes(data.type)
|
|
270
286
|
? {
|
|
271
287
|
type: 'FeatureCollection',
|
|
272
|
-
features: [{
|
|
273
|
-
|
|
274
|
-
properties: {},
|
|
275
|
-
geometry: data
|
|
276
|
-
}]
|
|
288
|
+
features: [__assign(__assign({}, data), { properties: {} // make sure they are set or it is invalid
|
|
289
|
+
})]
|
|
277
290
|
}
|
|
278
|
-
:
|
|
279
|
-
? {
|
|
280
|
-
type: 'FeatureCollection',
|
|
281
|
-
features: [__assign(__assign({}, data), { properties: {} // make sure they are set or it is invalid
|
|
282
|
-
})]
|
|
283
|
-
}
|
|
284
|
-
: data;
|
|
285
|
-
}
|
|
286
|
-
catch (e2) {
|
|
287
|
-
return throwError('Unable to parse GeoJSON value. Please make sure the formatting is correct.');
|
|
288
|
-
}
|
|
291
|
+
: data;
|
|
289
292
|
}
|
|
293
|
+
catch (error) {
|
|
294
|
+
return throwError('Unable to parse GeoJSON value. Please make sure the formatting is correct.');
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
var parseGeoJSONValue = function (value) {
|
|
298
|
+
var result = parseWtkValue(value) || parseJsonValue(value);
|
|
290
299
|
return result ? validateGeoJSONFormat(result) : value;
|
|
291
300
|
};
|
|
292
301
|
/**
|