@ -2,17 +2,13 @@ import React, { useContext, useState, useEffect, memo } from "react";
import { StyleSheet , View , Text , Image } from "react-native" ;
import { StyleSheet , View , Text , Image } from "react-native" ;
import colors from "../config/colors" ;
import colors from "../config/colors" ;
import { screen_width , screen_height } from "../config/dimensions" ;
import * as Location from "expo-location" ;
import * as Location from "expo-location" ;
import { EventLocationContext } from "../context/EventLocationContext" ;
import { EventLocationContext } from "../context/EventLocationContext" ;
import { TouchableOpacity } from "react-native-gesture-handler" ;
import { TouchableOpacity } from "react-native-gesture-handler" ;
import { CurrentLocationContext } from "../context/CurrentLocationContext" ;
import OpenStreetMap from "../components/map/OpenStreetMap" ;
import OpenStreetMap from "../components/map/OpenStreetMap" ;
import { MapRefContext } from "../context/MapRefContext" ;
// NOTE: Implementação posterior: É interessante adcionar um searchBox para que o usuário busque um endereço (google places autocomplete é uma api paga)
// NOTE: Implementação posterior: É interessante adcionar um searchBox para que o usuário busque um endereço (google places autocomplete é uma api paga)
const MapFormScreen = ( props ) => {
const MapFormScreen = ( props ) => {
const context = useContext ( EventLocationContext ) ; //local do evento
const context = useContext ( EventLocationContext ) ; //local do evento
const [ position , setPosition ] = useState ( null ) ;
const [ position , setPosition ] = useState ( null ) ;
@ -27,12 +23,14 @@ const MapFormScreen = (props) => {
} , [ location ] ) ;
} , [ location ] ) ;
const [ moveEndListener , setMoveEndListener ] = useState ( null ) ;
const [ moveEndListener , setMoveEndListener ] = useState ( null ) ;
//console.log("=====POSIÇÃO: " +position.lat);
console . log ( "=====POSIÇÃO: " + typeof location ) ;
const getAddress = async ( coordenadas ) => {
const getAddress = async ( coordenadas ) => {
Location . setGoogleApiKey ( "AIzaSyD_wuuokS3SVczc8qSASrsBq0E5qIpdyMc" ) ;
Location . setGoogleApiKey ( "AIzaSyD_wuuokS3SVczc8qSASrsBq0E5qIpdyMc" ) ;
const address = await Location . reverseGeocodeAsync ( coordenadas ) ;
const address = await Location . reverseGeocodeAsync ( coordenadas ) ;
console . log ( address ) ;
console . log ( coordenadas ) ;
if ( address [ 0 ] != undefined ) {
if ( address [ 0 ] != undefined ) {
var street = ( address [ 0 ] . street == null ? "" : address [ 0 ] . street ) ;
var street = ( address [ 0 ] . street == null ? "" : address [ 0 ] . street ) ;
var number = ( address [ 0 ] . name == null ? "" : ", " + address [ 0 ] . name ) ;
var number = ( address [ 0 ] . name == null ? "" : ", " + address [ 0 ] . name ) ;
@ -43,42 +41,23 @@ const MapFormScreen = (props) => {
context . saveNewLocation ( "Erro ao carregar endereço" , coordenadas ) ;
context . saveNewLocation ( "Erro ao carregar endereço" , coordenadas ) ;
}
}
} ;
} ;
const refContext = useContext ( MapRefContext ) ;
const setLocation = ( ) => {
const setLocation = ( ) => {
getAddress ( moveEndListener ) ;
getAddress ( moveEndListener ) ;
props . navigation . goBack ( null ) ;
props . navigation . goBack ( null ) ;
} ;
} ;
//leva o mapa pra localização escolhida pelo usuário
//leva o mapa pra localização escolhida pelo usuário
const aplyLocation = ( p ) => {
//setPosition(position);
setMoveEndListener ( p ) ;
if ( refContext . mapRef ) {
refContext . mapRef . injectJavaScript ( `
if ( moveend == true ) {
map . setView ( [ $ { p . latitude } , $ { p . longitude } ] , $ { 16.5 } ) ; moveend = false
} ` );
}
const moveLocation = ( l ) => {
setMoveEndListener ( l ) ;
setPosition ( l ) ;
} ;
} ;
//inicia o mapa na região do usuário ou no ultimo valor do marker
if ( refContext . mapRef && moveEndListener == null ) {
console . log ( "IIIIIIIIIIIIIIIIIIIIF " + location . latitude )
refContext . mapRef . injectJavaScript ( `
map . setView ( [ $ { position . lat } , $ { position . long } ] , $ { 16.5 } ) ; moveend = false
` );
}
return (
return (
< View style = { styles . container } >
< View style = { styles . container } >
< OpenStreetMap
< OpenStreetMap
style = { styles . mapStyle }
style = { styles . mapStyle }
moveEndListener = { e => moveLocation ( e ) }
animateToPosition = { position }
animateToPosition = { position }
moveEndListener = { e => aplyLocation ( e ) }
/ >
/ >
< View style = { styles . markerFixed } >
< View style = { styles . markerFixed } >
< Image
< Image
@ -131,19 +110,13 @@ const styles = StyleSheet.create({
textAlign : "center" ,
textAlign : "center" ,
} ,
} ,
markerFixed : {
markerFixed : {
//left: "50%",
// marginLeft: -19,
// marginTop: -48,
alignSelf : "center" ,
alignSelf : "center" ,
justifyContent : "center" ,
justifyContent : "center" ,
position : "absolute" ,
position : "absolute" ,
flexDirection : "row" ,
flexDirection : "row" ,
alignItems : "flex-start" ,
alignItems : "flex-start" ,
// bottom: "50%",
// top: "50%",
height : "13%" ,
height : "13%" ,
width : 38 ,
width : 38 ,
//backgroundColor: "black"
} ,
} ,
text : {
text : {
color : colors . white ,
color : colors . white ,
@ -153,7 +126,6 @@ const styles = StyleSheet.create({
} ,
} ,
marker : {
marker : {
height : "50%" ,
height : "50%" ,
// alignSelf:"flex-end",
width : 40 ,
width : 40 ,
} ,
} ,
callback : {
callback : {