@@ -175,19 +175,28 @@ class MapControls3D extends React.Component {
175175 setViewToExtent = ( bounds , angle = 0 ) => {
176176 this . leaveFirstPerson ( ) ;
177177
178- const center = {
179- x : 0.5 * ( bounds [ 0 ] + bounds [ 2 ] ) ,
180- y : 0.5 * ( bounds [ 1 ] + bounds [ 3 ] )
181- } ;
182- center . z = this . props . sceneContext . getTerrainHeightFromMap ( [ center . x , center . y ] ) ?? 0 ;
183-
184- // Camera height to width bbox width
185178 const fov = CAMERA_FOV / 180 * Math . PI ;
186179 const cameraHeight = ( bounds [ 2 ] - bounds [ 0 ] ) / ( 2 * Math . tan ( fov / 2 ) ) ;
187180
188- const camerapos = new Vector3 ( center . x , center . y , center . z + cameraHeight ) ;
189- const target = new Vector3 ( center . x , center . y , center . z ) ;
190- this . controls . animateTo ( camerapos , target , angle ) ;
181+ const center = {
182+ x : 0.5 * ( bounds [ 0 ] + bounds [ 2 ] ) ,
183+ y : 0.5 * ( bounds [ 1 ] + bounds [ 3 ] ) ,
184+ } ;
185+ const camerapos = new Vector3 ( center . x , center . y , cameraHeight ) ;
186+ const target = new Vector3 ( center . x , center . y , 0 ) ;
187+ const h = this . props . sceneContext . getTerrainHeightFromMap ( [ center . x , center . y ] ) ;
188+ // Fall back to getTerrainHeightFromDTM if map is not yet loaded
189+ if ( h === undefined ) {
190+ this . props . sceneContext . getTerrainHeightFromDTM ( [ center . x , center . y ] ) . then ( h2 => {
191+ camerapos . z += h2 ;
192+ target . z += h2 ;
193+ this . controls . animateTo ( camerapos , target , angle ) ;
194+ } )
195+ } else {
196+ camerapos . z += h ;
197+ target . z += h ;
198+ this . controls . animateTo ( camerapos , target , angle ) ;
199+ }
191200 } ;
192201 pan = ( ev , dx , dy ) => {
193202 const panInterval = setInterval ( ( ) => {
0 commit comments