@@ -15,6 +15,19 @@ function _extendBuffer(feature, size) {
15
15
}
16
16
}
17
17
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
+
18
31
const coordOut = new Coordinates ( 'EPSG:4326' , 0 , 0 , 0 ) ;
19
32
const defaultNormal = new THREE . Vector3 ( 0 , 0 , 1 ) ;
20
33
@@ -113,36 +126,30 @@ export class FeatureGeometry {
113
126
const last = this . indices . length - 1 ;
114
127
return this . indices [ last ] ;
115
128
}
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
+
116
135
/**
117
136
* Push new coordinates in vertices buffer.
118
137
* @param {Coordinates } coordIn The coordinates to push.
119
138
* @param {Feature } feature - the feature containing the geometry
120
139
*/
121
140
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 ) ;
127
142
128
143
coordIn . as ( feature . crs , coordOut ) ;
129
144
130
145
feature . transformToLocalSystem ( coordOut ) ;
131
146
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 ) ;
135
148
136
- feature . _pushValues ( coordOut . x , coordOut . y , coordOut . z ) ;
137
149
// expand extent if present
138
150
if ( this . _currentExtent ) {
139
151
this . _currentExtent . expandByCoordinates ( feature . useCrsOut ? coordOut : coordIn ) ;
140
152
}
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
- }
146
153
}
147
154
148
155
/**
@@ -153,24 +160,17 @@ export class FeatureGeometry {
153
160
* @param {Feature } feature - the feature containing the geometry
154
161
* @param {number } long The longitude coordinate.
155
162
* @param {number } lat The latitude coordinate.
156
- * @param {number } [alt=0] The altitude coordinate.
157
163
* @param {THREE.Vector3 } [normal=THREE.Vector3(0,0,1)] the normal on coordinates.
158
164
*/
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 ) ;
163
169
164
- feature . _pushValues ( long , lat , alt ) ;
165
170
// expand extent if present
166
171
if ( this . _currentExtent ) {
167
172
this . _currentExtent . expandByValuesCoordinates ( long , lat ) ;
168
173
}
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
- }
174
174
}
175
175
176
176
/**
@@ -518,6 +518,8 @@ export class FeatureCollection extends THREE.Object3D {
518
518
ref . normals = feature . normals ;
519
519
ref . size = feature . size ;
520
520
ref . vertices = feature . vertices ;
521
+ ref . altitude . min = feature . altitude . min ;
522
+ ref . altitude . max = feature . altitude . max ;
521
523
ref . _pos = feature . _pos ;
522
524
this . features . push ( ref ) ;
523
525
return ref ;
0 commit comments