From acad2cb182322e3ff9aa1ae54135b008d2f3b8da Mon Sep 17 00:00:00 2001 From: Ananta Pandey Date: Mon, 27 Aug 2018 19:11:11 -0400 Subject: [PATCH] switch to google maps and add a polyline (#35) --- expo_project/components/MapWithMarkers.js | 13 +++++++++---- expo_project/constants/Map.js | 15 ++++++++++++--- expo_project/screens/HomeScreen.js | 6 +++--- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/expo_project/components/MapWithMarkers.js b/expo_project/components/MapWithMarkers.js index c1d7fdf..736b20a 100644 --- a/expo_project/components/MapWithMarkers.js +++ b/expo_project/components/MapWithMarkers.js @@ -50,17 +50,23 @@ class MapWithMarkers extends React.Component { return this.state.region ? ( onMapPress()} + onLongPress={e => onMapLongPress(e.nativeEvent.coordinate)} initialRegion={this.state.region} showsUserLocation scrollEnabled zoomEnabled pitchEnabled={false} > + {markers.map(marker => { const selected = marker.id === activeMarkerId; - const key = marker.id; + const key = marker.id + (selected ? "-selected" : ""); //trigger a re render when switching states, so it recenters itself return ( ); diff --git a/expo_project/constants/Map.js b/expo_project/constants/Map.js index 006e734..1f23d4c 100644 --- a/expo_project/constants/Map.js +++ b/expo_project/constants/Map.js @@ -2,7 +2,16 @@ export default { defaultRegion: { latitude: 43.703805, longitude: -79.343568, - latitudeDelta: 0.0043, - longitudeDelta: 0.0034 - } + latitudeDelta: 0.00043, + longitudeDelta: 0.0012 + }, + polylineCoordinates: [ + { latitude: 43.703354, longitude: -79.343594 }, + { latitude: 43.703555, longitude: -79.343832 }, + { latitude: 43.70364, longitude: -79.344049 }, + { latitude: 43.703893, longitude: -79.34427 }, + { latitude: 43.704307, longitude: -79.343645 }, + { latitude: 43.703889, longitude: -79.343398 }, + { latitude: 43.703354, longitude: -79.343594 } + ] }; diff --git a/expo_project/screens/HomeScreen.js b/expo_project/screens/HomeScreen.js index cf9f0ea..3f9a452 100644 --- a/expo_project/screens/HomeScreen.js +++ b/expo_project/screens/HomeScreen.js @@ -164,7 +164,7 @@ class HomeScreen extends React.Component { } resetDrawer(y = MID_DRAWER_TRANSLATE_Y) { - if (this._drawerY !== y) { + if (this._drawerY !== y && this.state.markers.length) { Animated.timing(this.state.pan, { toValue: { x: 0, y }, duration: 200, @@ -235,14 +235,14 @@ class HomeScreen extends React.Component { } } - createNewMarker(e) { + createNewMarker(coordinate) { const markersCopy = [...this.state.markers]; const date = moment(); const dateLabel = date.format("HH:mm"); const title = "Person " + (markersCopy.length + 1); const marker = { - coordinate: e.nativeEvent.coordinate, + coordinate: coordinate, color: this.getRandomIconColor(), title, dateLabel