|
| 1 | +var React = require('react'); |
| 2 | +var ReactNative = require('react-native'); |
| 3 | +var { |
| 4 | + StyleSheet, |
| 5 | + PropTypes, |
| 6 | + View, |
| 7 | + Text, |
| 8 | + Dimensions, |
| 9 | + TouchableOpacity, |
| 10 | + Image, |
| 11 | +} = ReactNative; |
| 12 | + |
| 13 | +var MapView = require('react-native-maps'); |
| 14 | +var PriceMarker = require('./PriceMarker'); |
| 15 | + |
| 16 | +var { width, height } = Dimensions.get('window'); |
| 17 | + |
| 18 | +const ASPECT_RATIO = width / height; |
| 19 | +const LATITUDE = 37.78825; |
| 20 | +const LONGITUDE = -122.4324; |
| 21 | +const LATITUDE_DELTA = 0.0922; |
| 22 | +const LONGITUDE_DELTA = LATITUDE_DELTA * ASPECT_RATIO; |
| 23 | +const SPACE = 0.01; |
| 24 | + |
| 25 | +var markerIDs = ['Marker1', 'Marker2', 'Marker3', 'Marker4', 'Marker5']; |
| 26 | +var timeout = 4000; |
| 27 | +var animationTimeout; |
| 28 | + |
| 29 | +var FocusOnMarkers = React.createClass({ |
| 30 | + getInitialState() { |
| 31 | + return { |
| 32 | + a: { |
| 33 | + latitude: LATITUDE + SPACE, |
| 34 | + longitude: LONGITUDE + SPACE, |
| 35 | + }, |
| 36 | + b: { |
| 37 | + latitude: LATITUDE - SPACE, |
| 38 | + longitude: LONGITUDE - SPACE, |
| 39 | + }, |
| 40 | + c: { |
| 41 | + latitude: LATITUDE - (SPACE * 2), |
| 42 | + longitude: LONGITUDE - (SPACE * 2), |
| 43 | + }, |
| 44 | + d: { |
| 45 | + latitude: LATITUDE - (SPACE * 3), |
| 46 | + longitude: LONGITUDE - (SPACE * 3), |
| 47 | + }, |
| 48 | + e: { |
| 49 | + latitude: LATITUDE - (SPACE * 4), |
| 50 | + longitude: LONGITUDE - (SPACE * 4), |
| 51 | + }, |
| 52 | + } |
| 53 | + }, |
| 54 | + focusMap(markers, animated) { |
| 55 | + console.log("Markers received to populate map: " + markers); |
| 56 | + this.refs.map.fitToSuppliedMarkers(markers, animated); |
| 57 | + }, |
| 58 | + focus1() { |
| 59 | + animationTimeout = setTimeout(() => { |
| 60 | + this.focusMap([ |
| 61 | + markerIDs[1], |
| 62 | + markerIDs[4] |
| 63 | + ], true); |
| 64 | + |
| 65 | + this.focus2(); |
| 66 | + }, timeout); |
| 67 | + }, |
| 68 | + focus2() { |
| 69 | + animationTimeout = setTimeout(() => { |
| 70 | + this.focusMap([ |
| 71 | + markerIDs[2], |
| 72 | + markerIDs[3] |
| 73 | + ], false); |
| 74 | + |
| 75 | + this.focus3() |
| 76 | + }, timeout); |
| 77 | + }, |
| 78 | + focus3() { |
| 79 | + animationTimeout = setTimeout(() => { |
| 80 | + this.focusMap([ |
| 81 | + markerIDs[1], |
| 82 | + markerIDs[2] |
| 83 | + ], false); |
| 84 | + |
| 85 | + this.focus4(); |
| 86 | + }, timeout); |
| 87 | + }, |
| 88 | + focus4() { |
| 89 | + animationTimeout = setTimeout(() => { |
| 90 | + this.focusMap([ |
| 91 | + markerIDs[0], |
| 92 | + markerIDs[3] |
| 93 | + ], true); |
| 94 | + |
| 95 | + this.focus1(); |
| 96 | + }, timeout) |
| 97 | + }, |
| 98 | + componentDidMount() { |
| 99 | + animationTimeout = setTimeout(() => { |
| 100 | + this.focus1(); |
| 101 | + }, timeout) |
| 102 | + }, |
| 103 | + componentWillUnmount() { |
| 104 | + if (animationTimeout) { |
| 105 | + clearTimeout(animationTimeout); |
| 106 | + } |
| 107 | + }, |
| 108 | + render() { |
| 109 | + return ( |
| 110 | + <View style={styles.container}> |
| 111 | + <MapView |
| 112 | + ref="map" |
| 113 | + style={styles.map} |
| 114 | + initialRegion={{ |
| 115 | + latitude: LATITUDE, |
| 116 | + longitude: LONGITUDE, |
| 117 | + latitudeDelta: LATITUDE_DELTA, |
| 118 | + longitudeDelta: LONGITUDE_DELTA, |
| 119 | + }} |
| 120 | + > |
| 121 | + <MapView.Marker |
| 122 | + identifier={'Marker1'} |
| 123 | + coordinate={this.state.a} |
| 124 | + /> |
| 125 | + <MapView.Marker |
| 126 | + identifier={'Marker2'} |
| 127 | + coordinate={this.state.b} |
| 128 | + /> |
| 129 | + <MapView.Marker |
| 130 | + identifier={'Marker3'} |
| 131 | + coordinate={this.state.c} |
| 132 | + /> |
| 133 | + <MapView.Marker |
| 134 | + identifier={'Marker4'} |
| 135 | + coordinate={this.state.d} |
| 136 | + /> |
| 137 | + <MapView.Marker |
| 138 | + identifier={'Marker5'} |
| 139 | + coordinate={this.state.e} |
| 140 | + /> |
| 141 | + </MapView> |
| 142 | + </View> |
| 143 | + ); |
| 144 | + }, |
| 145 | +}); |
| 146 | + |
| 147 | +var styles = StyleSheet.create({ |
| 148 | + container: { |
| 149 | + position: 'absolute', |
| 150 | + top: 0, |
| 151 | + left: 0, |
| 152 | + right: 0, |
| 153 | + bottom: 0, |
| 154 | + justifyContent: 'flex-end', |
| 155 | + alignItems: 'center', |
| 156 | + }, |
| 157 | + map: { |
| 158 | + position: 'absolute', |
| 159 | + top: 0, |
| 160 | + left: 0, |
| 161 | + right: 0, |
| 162 | + bottom: 0, |
| 163 | + }, |
| 164 | +}); |
| 165 | + |
| 166 | +module.exports = FocusOnMarkers; |
0 commit comments