-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArrowPageModel.js
84 lines (71 loc) · 2.74 KB
/
ArrowPageModel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { decorate, observable } from "mobx";
import RNSimpleCompass from 'react-native-simple-compass';
import Utils from './Utils';
import Calculate from './Caluclate';
import Geolocation from 'react-native-geolocation-service';
export default class ArrowPageModel {
static instance = null;
static getInstance() {
if (this.instance === null) {
this.instance = new ArrowPageModel();
}
return this.instance;
}
isShowingDirection = false; // used by
destination = { latitude: -1, longitude: -1 };
// const degree_update_rate = 3; // Number of degrees changed before the callback is triggered
setDestination(dest) {
if (dest) {
// console.log('destination: ' + JSON.stringify(dest));
this.destination.latitude = dest.lat;
this.destination.longitude = dest.lng;
this.isShowingDirection = true;
const degreeUpdateRate = 3;
RNSimpleCompass.start(degreeUpdateRate, (degree) => {
// console.log('degree:' + degree);
try {
Geolocation.getCurrentPosition((position) => {
this.setRotate(270 - degree + Calculate.bearing(position.coords.latitude, position.coords.longitude,
this.destination.latitude, this.destination.longitude));
this.distance = Math.round(Calculate.distance(position.coords.latitude, position.coords.longitude,
this.destination.latitude, this.destination.longitude));
}, (error) => { console.warn(error); }, { maximumAge: 1000, enableHightAccuracy: true });
} catch (exception) {
console.warn(exception);
}
});
} else {
// console.log('stopped');
RNSimpleCompass.stop();
this.isShowingDirection = false;
}
}
rotate = '270deg'
setRotate(deg) {
this.rotate = deg + 'deg';
}
radius = 5000;
getRadius() {
if (this.radius > 10) {
return this.radius;
}
return undefined;
}
predefinedPlaces = [];
showListViewOnReturn = false;
location = { latitude: 57.708870, longitude: 11.974560 }
getLocationAsString() {
const locationString = this.location.latitude + ',' + this.location.longitude;
// console.log('locationString: ' + locationString);
return locationString;
}
distance = 0;
}
decorate(ArrowPageModel, {
isShowingDirection: observable, // is used by swipeNavigationPage reaction
rotate: observable,
radius: observable,
predefinedPlaces: observable,
location: observable,
distance: observable
});