From 4ad5131d35293f3c013c0b8b58511811c00e7c62 Mon Sep 17 00:00:00 2001 From: ztimson Date: Mon, 2 Sep 2019 18:51:28 -0400 Subject: [PATCH] Added debounce --- src/app/services/physics.service.ts | 6 +++--- src/app/views/map/map.component.ts | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/app/services/physics.service.ts b/src/app/services/physics.service.ts index b32a640..189d363 100644 --- a/src/app/services/physics.service.ts +++ b/src/app/services/physics.service.ts @@ -1,13 +1,12 @@ import {EventEmitter, Injectable} from '@angular/core'; import {BehaviorSubject, combineLatest} from "rxjs"; import {PermissionsService} from "../components/permissions/permissions.service"; +import {debounceTime} from "rxjs/operators"; @Injectable({ providedIn: 'root' }) export class PhysicsService { - private motionTimestamp; - requireCalibration = new EventEmitter(); calibrate = new BehaviorSubject(Infinity); @@ -21,6 +20,7 @@ export class PhysicsService { permissionsService.requestPermission('geolocation', 'gps_fixed', 'Can we use your location?').then(granted => { if(granted) { // Gather physical data + window.addEventListener('devicemotion', motion => this.motion.next(motion)); window.addEventListener('deviceorientation', orientation => { console.log('Orientation:', orientation); this.orientation.next(orientation); @@ -31,7 +31,7 @@ export class PhysicsService { }); // Combine data into one nice package - combineLatest(this.position, this.orientation, this.calibrate).subscribe(data => { + combineLatest(this.position.pipe(debounceTime(100)), this.orientation.pipe(debounceTime(100)), this.calibrate).subscribe(data => { console.log('Combine:', data); if(!data[0]) return; diff --git a/src/app/views/map/map.component.ts b/src/app/views/map/map.component.ts index 2e7b520..da5263e 100644 --- a/src/app/views/map/map.component.ts +++ b/src/app/views/map/map.component.ts @@ -115,6 +115,7 @@ export class MapComponent implements OnDestroy, OnInit { // Display location information & submit it this.physicsService.info.pipe(filter(coord => !!coord)).subscribe(pos => { + console.log('painting'); if (!this.position) this.center({lat: pos.latitude, lng: pos.longitude}); if (this.positionMarker.arrow) this.map.delete(this.positionMarker.arrow); if (this.positionMarker.circle) this.map.delete(this.positionMarker.circle);