UNPKG

1.02 kBPlain TextView Raw
1class ZoomHistory {
2 lastZoom: number;
3 lastFloorZoom: number;
4 lastIntegerZoom: number;
5 lastIntegerZoomTime: number;
6 first: boolean;
7
8 constructor() {
9 this.first = true;
10 }
11
12 update(z: number, now: number) {
13 const floorZ = Math.floor(z);
14
15 if (this.first) {
16 this.first = false;
17 this.lastIntegerZoom = floorZ;
18 this.lastIntegerZoomTime = 0;
19 this.lastZoom = z;
20 this.lastFloorZoom = floorZ;
21 return true;
22 }
23
24 if (this.lastFloorZoom > floorZ) {
25 this.lastIntegerZoom = floorZ + 1;
26 this.lastIntegerZoomTime = now;
27 } else if (this.lastFloorZoom < floorZ) {
28 this.lastIntegerZoom = floorZ;
29 this.lastIntegerZoomTime = now;
30 }
31
32 if (z !== this.lastZoom) {
33 this.lastZoom = z;
34 this.lastFloorZoom = floorZ;
35 return true;
36 }
37
38 return false;
39 }
40}
41
42export default ZoomHistory;