You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.9 KiB

  1. import React, { useContext, useState } from "react";
  2. import MapView from "react-native-maps";
  3. import { StyleSheet, View, Text } from "react-native";
  4. import colors from "../config/colors";
  5. import { screen_width, screen_height } from "../config/dimensions";
  6. import attachFocusToQuery from "../hooks/useFocus";
  7. import { CurrentLocationContext } from "../context/CurrentLocationContext";
  8. import { MapMarkerList } from "../components/MapMarkerList";
  9. function DataScreen(props) {
  10. const location = useContext(CurrentLocationContext).currentCoordinates;
  11. const focusChanged = attachFocusToQuery();
  12. const default_location = {
  13. latitude: -12.901799,
  14. longitude: -51.692116,
  15. latitudeDelta: 70,
  16. longitudeDelta: 70 * (screen_width / screen_height),
  17. };
  18. const map_scale = 0.003;
  19. const lat_long_delta = {
  20. latitudeDelta: map_scale,
  21. longitudeDelta: map_scale * (screen_width / screen_height),
  22. };
  23. const [renderRain, setRenderRain] = useState(true);
  24. const [renderFlood, setRenderFlood] = useState(true);
  25. const [renderRiver, setRenderRiver] = useState(true);
  26. const [renderPluviometer, setRenderPluviometer] = useState(true);
  27. return (
  28. <View style={styles.container}>
  29. <MapView
  30. style={styles.mapStyle}
  31. showsUserLocation={true}
  32. initialRegion={{ ...default_location }}
  33. region={{
  34. latitude: location["latitude"],
  35. longitude: location["longitude"],
  36. ...lat_long_delta,
  37. }}
  38. >
  39. <MapMarkerList
  40. reload={focusChanged}
  41. renderRain={renderRain}
  42. renderFlood={renderFlood}
  43. renderRiver={renderRiver}
  44. renderPluviometer={renderPluviometer}
  45. />
  46. </MapView>
  47. </View>
  48. );
  49. }
  50. const styles = StyleSheet.create({
  51. container: {
  52. backgroundColor: colors.black,
  53. flex: 1,
  54. },
  55. mapStyle: {
  56. position: "absolute",
  57. top: 0,
  58. left: 0,
  59. right: 0,
  60. bottom: 0,
  61. },
  62. });
  63. export default DataScreen;