-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
121 lines (105 loc) · 2.98 KB
/
App.js
File metadata and controls
121 lines (105 loc) · 2.98 KB
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
// @flow
'use-strict'
import React, { Component } from 'react'
import {
Text,
View,
Image,
Platform,
StyleSheet,
TouchableOpacity,
} from 'react-native'
import { Marker } from 'react-native-maps'
import ClusteredMapView from 'react-native-maps-super-cluster'
import { generateRandomPoints, generateRandomPoint } from './generator'
const italyCenterLatitude = 41.8962667,
italyCenterLongitude = 11.3340056,
radius = 600000
export default class App extends Component {
constructor(props) {
super(props)
this.state = {
pins: []
}
this.reload = this.reload.bind(this)
this.loadMore = this.loadMore.bind(this)
this.renderMarker = this.renderMarker.bind(this)
}
componentDidMount() {
this.reload()
}
reload = () => {
const pins = generateRandomPoints({latitude: italyCenterLatitude, longitude: italyCenterLongitude}, radius, 50, this.state.pins.length)
this.setState({ pins })
}
loadMore = () => {
const pins = generateRandomPoints({latitude: italyCenterLatitude, longitude: italyCenterLongitude}, radius, 50, this.state.pins.length)
this.setState({ pins: this.state.pins.concat(pins) })
}
renderMarker = (pin) => {
return (
<Marker key={pin.id} coordinate={pin.location} />
)
}
render() {
return (
<View style={styles.container} style={{flex: 1}}>
{/* Cluster Map Example */}
<ClusteredMapView
style={{flex: 1}}
data={this.state.pins}
textStyle={{ color: '#65bc46' }}
initialRegion={{latitude: italyCenterLatitude, longitude: italyCenterLongitude, latitudeDelta: 12, longitudeDelta: 12 }}
containerStyle={{backgroundColor: 'white', borderColor: '#65bc46'}}
renderMarker={this.renderMarker} >
</ClusteredMapView>
{/* Header - Control Test Bar */}
<View style={styles.controlBar}>
<TouchableOpacity
style={styles.button}
onPress={this.reload}>
<Text style={styles.text}>Reload</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={this.loadMore}>
<Text style={styles.text}>Load more</Text>
</TouchableOpacity>
</View>
<Image
source={require('./simbol.png')}
style={{position: 'absolute', bottom: 8, right: 8, width: 64, height: 64}}
resizeMode='contain' />
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#F5FCFF',
},
controlBar: {
top: 24,
left: 25,
right: 25,
height: 40,
borderRadius: 4,
position: 'absolute',
flexDirection: 'row',
alignItems: 'center',
paddingHorizontal: 20,
backgroundColor: 'white',
justifyContent: 'space-between',
},
button: {
paddingVertical: 8,
paddingHorizontal: 20,
},
text: {
fontSize: 16,
fontWeight: 'bold'
},
})