forked from michaelwoon/R2S2-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMapView.js
104 lines (93 loc) · 2.66 KB
/
MapView.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
'use strict';
import React, {Component} from 'react';
import {View, Image} from 'react-native';
import MapboxGL from '@mapbox/react-native-mapbox-gl';
import base64 from "react-native-base64";
MapboxGL.setAccessToken("pk.eyJ1IjoidXZhaHlkcm9pbmZvcm1hdGljc2xhYiIsImEiOiJjamI5bXRqanowbTM4MnFwczN3emNjYW9oIn0.mejJdMMfKWw7xn0i5K6c2Q");
const baseCoordinates = [
-77.2786997, 36.906495
];
export default class MapView extends Component<Props> {
constructor(props){
super(props);
this.state = {
isLoading: true,
bridges: [],
};
};
static navigationOptions = {
title: 'Map',
};
loadBridges(){
let headers = new Headers();
headers.append(
"Authorization",
"Basic " + base64.encode(global.token + ":x")
);
const { params } = this.props.navigation.state;
console.log("date: " + params.date);
fetch("http://35.194.88.251/api/bridges/" + params.date, {
method: "GET",
headers: headers
})
.then(function(response) {
return response.json();
})
.then(json => {
console.log("data received");
this.setState({
isLoading: false,
bridges: json,
});
})
.catch(function(ex) {
console.log("parsing failed or no token", ex);
});
};
componentDidMount(){
this.loadBridges();
};
makePoint(id, title, coordinates) {
return (
<MapboxGL.PointAnnotation
key={id}
id={id}
title={title}
coordinate={coordinates}>
</MapboxGL.PointAnnotation>
);
};
showPoints() {
let items = [];
for (let i = 0; i < this.state.bridges.length; i++) {
let id = this.state.bridges[i].fedid;
let title = "Road: " + this.state.bridges[i].roadname + " Stream: " + this.state.bridges[i].stream;
let coordinates = [parseFloat(this.state.bridges[i].xcord),parseFloat(this.state.bridges[i].ycord)];
items.push(this.makePoint(id,title,coordinates));
}
return items;
};
render () {
console.log(this.state.bridges.length);
if(this.state.bridges.length == 0) {
return <View></View>
}
return (
<View style={{flex: 1}}>
<MapboxGL.MapView
ref={(c) => this._map = c}
style={{flex: 1}}
zoomLevel={9}
centerCoordinate={baseCoordinates}>
<MapboxGL.PointAnnotation
key="key1"
id="id1"
title="Test"
coordinate={baseCoordinates}>
</MapboxGL.PointAnnotation>
{this.showPoints()}
</MapboxGL.MapView>
</View>
);
}
}