Skip to content

Commit 17aaa8b

Browse files
committed
feature(Parser): detect if original source have elevation data.
1 parent 3767b0a commit 17aaa8b

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

src/Core/Feature.js

+3
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ function push3DValues(value0, value1, value2 = 0) {
223223
* @property {number[]} normals - All the normals of the Feature.
224224
* @property {number} size - the number of values of the array that should be associated with a coordinates.
225225
* The size is 3 with altitude and 2 without altitude.
226+
* @property {boolean} hasRawElevationData - indicates if the geographic coordinates, from original source, has an elevation,
227+
* the coordinates has a third coordinate.
226228
* @property {string} crs - Geographic or Geocentric coordinates system.
227229
* @property {FeatureGeometry[]} geometries - An array containing all {@link
228230
* FeatureGeometry}.
@@ -246,6 +248,7 @@ class Feature {
246248
this.crs = collection.crs;
247249
this.size = collection.size;
248250
this.normals = collection.crs == 'EPSG:4978' ? [] : undefined;
251+
this.hasRawElevationData = false;
249252

250253
this.transformToLocalSystem = collection.transformToLocalSystem.bind(collection);
251254
if (collection.extent) {

src/Parser/GeoJsonParser.js

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ function jsonFeatureToFeature(crsIn, json, collection) {
147147
const feature = collection.requestFeatureByType(featureType);
148148
const coordinates = jsonType != 'point' ? json.geometry.coordinates : [json.geometry.coordinates];
149149
const properties = json.properties || {};
150+
feature.hasRawElevationData = coordinates[0]?.length === 3;
150151

151152
// copy other properties
152153
for (const key of Object.keys(json)) {

src/Parser/VectorTileParser.js

+1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ function readPBF(file, options) {
136136
feature.id = layer.id;
137137
feature.order = layer.order;
138138
feature.style = options.in.styles[feature.id];
139+
feature.hasRawElevationData = false;
139140
vtFeatureToFeatureGeometry(vtFeature, feature);
140141
} else if (!collection.features.find(f => f.id === layer.id)) {
141142
feature = collection.newFeatureByReference(feature);

test/unit/geojson.js

+10
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ describe('GeoJsonParser', function () {
2525
assert.ok(collection.features[0].vertices.every((v, i) => ((i + 1) % 3) != 0 || (v + collection.position.z) != 0));
2626
}));
2727

28+
it('should detect if there is the raw elevation data', () =>
29+
parse(gpx).then((collection) => {
30+
assert.ok(collection.features[0].hasRawElevationData);
31+
}));
32+
33+
it('should detect if there is not the raw elevation data', () =>
34+
parse(holes).then((collection) => {
35+
assert.ok(!collection.features[0].hasRawElevationData);
36+
}));
37+
2838
it('should return an empty collection', () =>
2939
GeoJsonParser.parse(holes, {
3040
in: {

0 commit comments

Comments
 (0)