Added debounce
This commit is contained in:
		@@ -1,13 +1,12 @@
 | 
				
			|||||||
import {EventEmitter, Injectable} from '@angular/core';
 | 
					import {EventEmitter, Injectable} from '@angular/core';
 | 
				
			||||||
import {BehaviorSubject, combineLatest} from "rxjs";
 | 
					import {BehaviorSubject, combineLatest} from "rxjs";
 | 
				
			||||||
import {PermissionsService} from "../components/permissions/permissions.service";
 | 
					import {PermissionsService} from "../components/permissions/permissions.service";
 | 
				
			||||||
 | 
					import {debounceTime} from "rxjs/operators";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Injectable({
 | 
					@Injectable({
 | 
				
			||||||
    providedIn: 'root'
 | 
					    providedIn: 'root'
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
export class PhysicsService {
 | 
					export class PhysicsService {
 | 
				
			||||||
    private motionTimestamp;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    requireCalibration = new EventEmitter();
 | 
					    requireCalibration = new EventEmitter();
 | 
				
			||||||
    calibrate = new BehaviorSubject<number>(Infinity);
 | 
					    calibrate = new BehaviorSubject<number>(Infinity);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -21,6 +20,7 @@ export class PhysicsService {
 | 
				
			|||||||
        permissionsService.requestPermission('geolocation', 'gps_fixed', 'Can we use your location?').then(granted => {
 | 
					        permissionsService.requestPermission('geolocation', 'gps_fixed', 'Can we use your location?').then(granted => {
 | 
				
			||||||
            if(granted) {
 | 
					            if(granted) {
 | 
				
			||||||
                // Gather physical data
 | 
					                // Gather physical data
 | 
				
			||||||
 | 
					                window.addEventListener('devicemotion', motion => this.motion.next(motion));
 | 
				
			||||||
                window.addEventListener('deviceorientation', orientation => {
 | 
					                window.addEventListener('deviceorientation', orientation => {
 | 
				
			||||||
                    console.log('Orientation:', orientation);
 | 
					                    console.log('Orientation:', orientation);
 | 
				
			||||||
                    this.orientation.next(orientation);
 | 
					                    this.orientation.next(orientation);
 | 
				
			||||||
@@ -31,7 +31,7 @@ export class PhysicsService {
 | 
				
			|||||||
                });
 | 
					                });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                // Combine data into one nice package
 | 
					                // 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);
 | 
					                    console.log('Combine:', data);
 | 
				
			||||||
                    if(!data[0]) return;
 | 
					                    if(!data[0]) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -115,6 +115,7 @@ export class MapComponent implements OnDestroy, OnInit {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // Display location information & submit it
 | 
					        // Display location information & submit it
 | 
				
			||||||
        this.physicsService.info.pipe(filter(coord => !!coord)).subscribe(pos => {
 | 
					        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.position) this.center({lat: pos.latitude, lng: pos.longitude});
 | 
				
			||||||
            if (this.positionMarker.arrow) this.map.delete(this.positionMarker.arrow);
 | 
					            if (this.positionMarker.arrow) this.map.delete(this.positionMarker.arrow);
 | 
				
			||||||
            if (this.positionMarker.circle) this.map.delete(this.positionMarker.circle);
 | 
					            if (this.positionMarker.circle) this.map.delete(this.positionMarker.circle);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user