This repository has been archived by the owner on Jun 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
executable file
·143 lines (130 loc) · 3.84 KB
/
App.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import React, {Component} from 'react';
import {SafeAreaView, StyleSheet, View} from 'react-native';
import Map from './app/components/Map';
import {Header, Text} from 'react-native-elements';
class App extends Component {
state = {
parkMarkers: [],
loading: true,
};
static getRandomColor() {
let letters = '0123456789ABCDEF';
let color = '#';
for (let i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
componentDidMount() {
this._allParkPos();
}
_allParkPos = () => {
let array = [];
let XMLParser = require('react-xml-parser');
fetch(
'https://data.montpellier3m.fr/sites/default/files/ressources/TAM_MMM_VELOMAG.xml',
)
.then(response => response.text())
.then(response => {
const xml = new XMLParser().parseFromString(response); // Assume xmlText contains the example XML
for (let i = 0; i < xml.getElementsByTagName('si').length; i++) {
let occupiedPlaces = xml.getElementsByTagName('si')[i].attributes.av;
let creditCardReader = xml.getElementsByTagName('si')[i].attributes
.cb;
let availablePlaces = xml.getElementsByTagName('si')[i].attributes.fr;
let latitude = xml.getElementsByTagName('si')[i].attributes.la;
let longitude = xml.getElementsByTagName('si')[i].attributes.lg;
let stationName = xml.getElementsByTagName('si')[i].attributes.na;
let totalPlaces = xml.getElementsByTagName('si')[i].attributes.to;
let output = '';
output += 'Nombre total de places:' + totalPlaces + '\n';
output += 'Nombre de places occupées:' + occupiedPlaces + '\n';
output += 'Nombre de place libres:' + availablePlaces + '\n';
if (creditCardReader === '1') {
output += 'Lecteur de CB disponible' + '\n';
} else {
output += 'Lecteur de CB non disponible' + '\n';
}
array.push({
title: stationName.substr(stationName.indexOf(' ') + 1),
occupiedPlaces: occupiedPlaces,
availablePlaces: availablePlaces,
creditCardReader: creditCardReader,
color: App.getRandomColor(),
coordinates: {
latitude: parseFloat(latitude),
longitude: parseFloat(longitude),
},
});
}
this.setState({loading: false});
})
.catch(err => {
alert('an error was occured. Try to restart the app.');
});
this.setState({parkMarkers: array});
};
render() {
const {parkMarkers, loading} = this.state;
if (loading) {
return (
<View>
<Text>Loading...</Text>
</View>
);
}
return (
<View style={styles.container}>
<Header
statusBarProps={{barStyle: 'light-content'}}
barStyle="light-content"
centerComponent={
<Text h4 style={styles.titleHeader}>
{'Velo Magg Park'}
</Text>
}
containerStyle={styles.header}
/>
<SafeAreaView style={styles.map}>
<Map region={region} places={parkMarkers} />
</SafeAreaView>
</View>
);
}
}
// A placeholder until we get our own location
const region = {
latitude: 43.610769,
longitude: 3.876716,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
};
const styles = StyleSheet.create({
container: {
flex:1,
flexDirection: 'column',
},
container2: {
flex: 1,
},
header: {
backgroundColor: '#6495ED',
justifyContent: 'space-around',
height: '10%',
position: 'absolute',
top: 0,
left: 0,
right: 0,
zIndex: 1,
},
titleHeader: {
color: 'white',
fontFamily: 'Roboto',
},
map: {
flex: 1,
marginTop: '20%',
marginBottom: '-10%',
},
});
export default App;