@@ -303,7 +303,8 @@ function zoomOut() {
303303 } ) ;
304304}
305305
306- function getLocation ( zoom = true ) {
306+ function getLocation ( zoom = true , followLocationOverride ) {
307+ if ( typeof followLocationOverride === "boolean" ) followLocation = followLocationOverride ;
307308 // Create the current position icon feature
308309 const iconFeature = new ol . Feature ( {
309310 geometry : new ol . geom . Point ( ol . proj . fromLonLat ( pos ?? [ 0 , 0 ] ) ) ,
@@ -416,14 +417,14 @@ function getLocation(zoom = true) {
416417 const view = map . getView ( ) ;
417418 const distanceBetweenUpdates = distance ( ol . proj . toLonLat ( view . getCenter ( ) ) , pos ) ;
418419 document . getElementById ( "distanceBetweenUpdates" ) . innerHTML = distanceBetweenUpdates . toFixed ( 2 ) + "m" ;
420+ const currentZoom = view . getZoom ( ) ;
419421 if ( distanceBetweenUpdates > 5 ) {
420422 view . animate ( {
421423 center : ol . proj . fromLonLat ( pos ) ,
422- zoom : map . getView ( ) . getZoom ( ) , // use the current zoom
424+ zoom : zoom && currentZoom < 13.5 ? 16 : currentZoom , // use the current zoom
423425 duration : 500 ,
424426 } ) ;
425- }
426- //map.getView().setCenter(ol.proj.fromLonLat(pos));
427+ } else if ( zoom ) view . setZoom ( currentZoom < 13.5 ? 16 : currentZoom ) ;
427428 }
428429
429430 if ( navigationActive && rotationMode === "route" ) updateRotation ( ) ;
@@ -454,29 +455,6 @@ function getLocation(zoom = true) {
454455 }
455456 ) ;
456457 watchPositionIDs . push ( watchPositionID ) ;
457-
458- // Pan to location only once when position has been set
459- if ( zoom ) {
460- const locationPromise = new Promise ( ( resolve , reject ) => {
461- const loop = ( ) => ( pos ? resolve ( pos ) : setTimeout ( loop ) ) ;
462- loop ( ) ;
463- } ) ;
464-
465- locationPromise . then ( pos => {
466- // Pan to location
467- const currentZoom = map . getView ( ) . getZoom ( ) ;
468-
469- const view = map . getView ( ) ;
470- view . animate ( {
471- center : ol . proj . fromLonLat ( pos ) ,
472- zoom : currentZoom < 13.5 ? 16 : currentZoom ,
473- duration : 100 ,
474- } ) ;
475-
476- // Only set the follow location at the end, so that the one time zoom works
477- if ( ! followLocation ) followLocation = true ;
478- } ) ;
479- }
480458 } else {
481459 // Browser doesn't support Geolocation
482460 console . log ( "Error: Your browser doesn't support geolocation." ) ;
0 commit comments