Skip to content

Commit

Permalink
feature(Parser): detect if original source have elevation data.
Browse files Browse the repository at this point in the history
  • Loading branch information
gchoqueux committed Mar 15, 2023
1 parent 3767b0a commit 17aaa8b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Core/Feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ function push3DValues(value0, value1, value2 = 0) {
* @property {number[]} normals - All the normals of the Feature.
* @property {number} size - the number of values of the array that should be associated with a coordinates.
* The size is 3 with altitude and 2 without altitude.
* @property {boolean} hasRawElevationData - indicates if the geographic coordinates, from original source, has an elevation,
* the coordinates has a third coordinate.
* @property {string} crs - Geographic or Geocentric coordinates system.
* @property {FeatureGeometry[]} geometries - An array containing all {@link
* FeatureGeometry}.
Expand All @@ -246,6 +248,7 @@ class Feature {
this.crs = collection.crs;
this.size = collection.size;
this.normals = collection.crs == 'EPSG:4978' ? [] : undefined;
this.hasRawElevationData = false;

this.transformToLocalSystem = collection.transformToLocalSystem.bind(collection);
if (collection.extent) {
Expand Down
1 change: 1 addition & 0 deletions src/Parser/GeoJsonParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ function jsonFeatureToFeature(crsIn, json, collection) {
const feature = collection.requestFeatureByType(featureType);
const coordinates = jsonType != 'point' ? json.geometry.coordinates : [json.geometry.coordinates];
const properties = json.properties || {};
feature.hasRawElevationData = coordinates[0]?.length === 3;

// copy other properties
for (const key of Object.keys(json)) {
Expand Down
1 change: 1 addition & 0 deletions src/Parser/VectorTileParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ function readPBF(file, options) {
feature.id = layer.id;
feature.order = layer.order;
feature.style = options.in.styles[feature.id];
feature.hasRawElevationData = false;
vtFeatureToFeatureGeometry(vtFeature, feature);
} else if (!collection.features.find(f => f.id === layer.id)) {
feature = collection.newFeatureByReference(feature);
Expand Down
10 changes: 10 additions & 0 deletions test/unit/geojson.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ describe('GeoJsonParser', function () {
assert.ok(collection.features[0].vertices.every((v, i) => ((i + 1) % 3) != 0 || (v + collection.position.z) != 0));
}));

it('should detect if there is the raw elevation data', () =>
parse(gpx).then((collection) => {
assert.ok(collection.features[0].hasRawElevationData);
}));

it('should detect if there is not the raw elevation data', () =>
parse(holes).then((collection) => {
assert.ok(!collection.features[0].hasRawElevationData);
}));

it('should return an empty collection', () =>
GeoJsonParser.parse(holes, {
in: {
Expand Down

0 comments on commit 17aaa8b

Please sign in to comment.