Skip to content

Commit 4746e86

Browse files
committed
fix(Feature): wrong altitude and altitude limits.
1 parent 0f5cd07 commit 4746e86

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

src/Core/Feature.js

+27-25
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ function _extendBuffer(feature, size) {
1515
}
1616
}
1717

18+
function _setGeometryValues(geom, feature, long, lat, alt, normal) {
19+
if (feature.normals) {
20+
normal.toArray(feature.normals, feature._pos);
21+
}
22+
23+
feature._pushValues(long, lat, alt);
24+
25+
if (geom.size == 3) {
26+
geom.altitude.min = Math.min(geom.altitude.min, alt);
27+
geom.altitude.max = Math.max(geom.altitude.max, alt);
28+
}
29+
}
30+
1831
const coordOut = new Coordinates('EPSG:4326', 0, 0, 0);
1932
const defaultNormal = new THREE.Vector3(0, 0, 1);
2033

@@ -113,36 +126,30 @@ export class FeatureGeometry {
113126
const last = this.indices.length - 1;
114127
return this.indices[last];
115128
}
129+
130+
baseAltitude(feature, coordinates) {
131+
const base_altitude = feature.style[typeToStyleProperty[feature.type]].base_altitude || 0;
132+
return isNaN(base_altitude) ? base_altitude(this.properties, coordinates) : base_altitude;
133+
}
134+
116135
/**
117136
* Push new coordinates in vertices buffer.
118137
* @param {Coordinates} coordIn The coordinates to push.
119138
* @param {Feature} feature - the feature containing the geometry
120139
*/
121140
pushCoordinates(coordIn, feature) {
122-
if (this.size == 3) {
123-
// set altitude from context
124-
const base_altitude = feature.style[typeToStyleProperty[feature.type]].base_altitude;
125-
coordIn.z = isNaN(base_altitude) ? base_altitude(this.properties, coordIn) : base_altitude;
126-
}
141+
coordIn.z = this.baseAltitude(feature, coordIn);
127142

128143
coordIn.as(feature.crs, coordOut);
129144

130145
feature.transformToLocalSystem(coordOut);
131146

132-
if (feature.normals) {
133-
coordOut.geodesicNormal.toArray(feature.normals, feature._pos);
134-
}
147+
_setGeometryValues(this, feature, coordOut.x, coordOut.y, coordOut.z, coordOut.geodesicNormal);
135148

136-
feature._pushValues(coordOut.x, coordOut.y, coordOut.z);
137149
// expand extent if present
138150
if (this._currentExtent) {
139151
this._currentExtent.expandByCoordinates(feature.useCrsOut ? coordOut : coordIn);
140152
}
141-
142-
if (this.size == 3) {
143-
this.altitude.min = Math.min(this.altitude.min, coordIn.z);
144-
this.altitude.max = Math.max(this.altitude.max, coordIn.z);
145-
}
146153
}
147154

148155
/**
@@ -153,24 +160,17 @@ export class FeatureGeometry {
153160
* @param {Feature} feature - the feature containing the geometry
154161
* @param {number} long The longitude coordinate.
155162
* @param {number} lat The latitude coordinate.
156-
* @param {number} [alt=0] The altitude coordinate.
157163
* @param {THREE.Vector3} [normal=THREE.Vector3(0,0,1)] the normal on coordinates.
158164
*/
159-
pushCoordinatesValues(feature, long, lat, alt = 0, normal = defaultNormal) {
160-
if (feature.normals) {
161-
normal.toArray(feature.normals, feature._pos);
162-
}
165+
pushCoordinatesValues(feature, long, lat, normal = defaultNormal) {
166+
const altitude = this.baseAltitude(feature);
167+
168+
_setGeometryValues(this, feature, long, lat, altitude, normal);
163169

164-
feature._pushValues(long, lat, alt);
165170
// expand extent if present
166171
if (this._currentExtent) {
167172
this._currentExtent.expandByValuesCoordinates(long, lat);
168173
}
169-
170-
if (this.size == 3) {
171-
this.altitude.min = Math.min(this.altitude.min, alt);
172-
this.altitude.max = Math.max(this.altitude.max, alt);
173-
}
174174
}
175175

176176
/**
@@ -518,6 +518,8 @@ export class FeatureCollection extends THREE.Object3D {
518518
ref.normals = feature.normals;
519519
ref.size = feature.size;
520520
ref.vertices = feature.vertices;
521+
ref.altitude.min = feature.altitude.min;
522+
ref.altitude.max = feature.altitude.max;
521523
ref._pos = feature._pos;
522524
this.features.push(ref);
523525
return ref;

0 commit comments

Comments
 (0)