/
index.js
75 lines (70 loc) · 1.79 KB
/
index.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
'use strict';
var React = require('react');
var ReactNative = require('react-native');
var {
AppRegistry,
StyleSheet,
View,
Text,
} = ReactNative;
var Btn = require('Btn');
var Geo = new(require('Geo'));
var Mapa = new(require('Mapa'));
var GLOBAL = require('Globals');
var Moov = React.createClass({
render: function() {
return (
<View style={styles.container}>
<View style={styles.mapContainer}>
{Mapa.render()}
</View>
<Btn/>
</View>
);
},
});
Geo.setCallback(function(track) {
var lastPoint = track.slice(-1)[0];
if (!lastPoint) {
return;
}
fetch('http://localhost:8001/location', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
lat: lastPoint.coords.latitude,
lng: lastPoint.coords.longitude,
})
}).then((resp) => {
if (resp.status === 200 && resp.ok) {
return resp.json();
}
}).then((obj) => {
if (obj) {
Geo.storeObj(obj);
GLOBAL.EMITTER.emit('change', {
line: [
{latitude: 39.70825, longitude: -124.4424},
{latitude: 39.70825, longitude: -124.4524},
{latitude: 39.70825, longitude: -124.4724},
]
})
}
});
Mapa.onTrackIncrease(track)
// Liner.points.push(track[-1])
});
var styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'column',
},
mapContainer: {
flex: 1,
flexDirection: 'column',
},
});
AppRegistry.registerComponent('Moov', () => Moov);