import React, {useState, useEffect} from "react"; import { View, Text, StyleSheet, Alert, TouchableOpacity, Image, StatusBar, Pressable } from "react-native"; import MapLibreGL from '@maplibre/maplibre-react-native'; import { MapView,ShapeSource,Camera,UserLocation,PointAnnotation,FillLayer,LineLayer,VectorSource } from "@maplibre/maplibre-react-native"; import Geolocation from "@react-native-community/geolocation"; import Modal from "react-native-modal"; type MapCollectLineProps = {route: any,navigation: any} function MapCollectLineScreen({route,navigation}:MapCollectLineProps):React.JSX.Element{ const apiKey = "JoJs2pcDv5o0yQlQLMfI"; const [basemap, setBasemap] = useState("streets-v2"); const styleURL = `https://api.maptiler.com/maps/${basemap}/style.json?key=${apiKey}`; const [currentPosition, setCurrentPosition] = useState<[number,number] | []>([]); const [currentPositionCamera, setCurrentPositionCamera] = useState<[number,number] | []>([0,0]); const [coordinates,setCoordinates] = useState([ ]); const [startPoint, setStartPoint] = useState([]); const [manyPick, setManyPick] = useState(0); const morePoint = () => { setManyPick(manyPick+1); setStartPoint([...startPoint,`point${manyPick+1}`]) setCoordinates([...coordinates,currentPosition]) } const checkArrayCoord = (()=> { console.log("for Geojeson",coordinates[0]) }) const [reqCount, setReqCount] = useState(0); const [long,setLong] = useState(0); const [lat,setLat] = useState(0); const [accuracy,setAccuracy] = useState(0); const [timeStamp,setTimeStamp] = useState(0); const [modalBasemap,setmodalBasemap] = useState(false); const [modalLayerList,setmodalLayerList] = useState(false); useEffect(() => { const intervalID = setInterval(() => { Geolocation.getCurrentPosition( position => { setReqCount((reqCount) => reqCount + 1) setLong(position.coords.longitude); setLat(position.coords.latitude); setAccuracy(position.coords.accuracy); setTimeStamp(position.timestamp); setReqCount((reqCount) => reqCount++ ); setCurrentPosition([position.coords.longitude,position.coords.latitude]) setCurrentPositionCamera([position.coords.longitude,position.coords.latitude]) console.log("Long",position.coords.longitude); console.log("Lat",position.coords.latitude); console.log("current",[position.coords.longitude,position.coords.latitude]); }, error => { console.log('Error Getting current position', error); }, {timeout:20000,enableHighAccuracy:false,maximumAge:0} ); // setReqCount((reqCount) => (reqCount > 0 ? reqCount+1 : 10)); }, 5000); return () => { clearInterval(intervalID); }; }, []); const replacingCoordinate = (index:number,coor:any) => { const nextCoordinate = coordinates.map((c:any,i:number) => { if (i === index){ return c = coor } else { return c } }); setCoordinates(nextCoordinate); } const [zoom, setZoom] = useState(15); const MAX_ZOOM_LEVEL = 20; const MIN_ZOOM_LEVEL = 5; const handleZoom = (isZoomIn = false) => { let currentZoomLevel = zoom; if (!isZoomIn && currentZoomLevel === MAX_ZOOM_LEVEL) { currentZoomLevel -= 1; } else if (isZoomIn && currentZoomLevel === MIN_ZOOM_LEVEL) { currentZoomLevel += 1; } if ( currentZoomLevel >= MAX_ZOOM_LEVEL || currentZoomLevel <= MIN_ZOOM_LEVEL ) { return; } currentZoomLevel = isZoomIn ? currentZoomLevel + 1 : currentZoomLevel - 1; setZoom(currentZoomLevel); } return( setZoom(region.properties.zoomLevel) } compassEnabled={false} > {coordinates.length > 1 ? : null } { startPoint.map((item:any,index:number)=>( } key={index} id={item} coordinate={coordinates[index]} draggable={true} onDrag={(e)=> { replacingCoordinate(index,e.geometry.coordinates) }} /> )) } setmodalLayerList(true)} style={{position:'absolute',backgroundColor:'#FFFFFF',width:50,height:50,borderRadius:25,alignItems:'center',justifyContent:'center',top:'7%',left:'4%'}}> setmodalBasemap(true)} style={{position:'absolute',backgroundColor:'#FFFFFF',width:50,height:50,borderRadius:25,alignItems:'center',justifyContent:'center',top:'15%',left:'4%'}}> {/* */} setmodalBasemap(false)} style={{top:'18%',alignSelf:'center'}}> Basemap Gallery setmodalBasemap(false)} style={{alignSelf:'flex-end',padding:10}}> setmodalLayerList(false)} style={{top:'18%',alignSelf:'center'}}> Layer List setmodalLayerList(false)} style={{alignSelf:'flex-end',padding:10}}> {/* handleZoom(true)}> handleZoom()}> */} { startPoint.length === 0 ? currentPosition.length > 0 ? Pick Start Point : Pick Start Point : { startPoint.length > 1 ? { navigation.navigate('PDAM Collecting', { screen: 'PDAM Collecting',coordinates: coordinates}) }}> : null } } ) } const styles = StyleSheet.create({ buttonImageIconStyle: { padding: 10, margin: 5, height: 25, width: 25, resizeMode: 'stretch', }, gotoLocate: { opacity: 0.6, position: 'absolute', top:120, right: 5, borderRadius:8, paddingHorizontal:7, width: 50, // height: 50, backgroundColor: "white", flexDirection: 'column', gap: 10 } }); export default MapCollectLineScreen;