react-native-leaflet icon indicating copy to clipboard operation
react-native-leaflet copied to clipboard

is there a way to control the map with javascript like in the web version of leaflet?

Open loloide opened this issue 2 years ago • 1 comments

i am trying to pan the camera of the map to a different location than the original one in the web version i can use map.panTo(new L.LatLng(lat, lon)); and it moves the map to the coordinates.

but in the React-Native version there is, as far as i'm concerned, no way to control it that way and have to instead use the props which i can't control dynamically.

loloide avatar Feb 17 '23 20:02 loloide

Just use useState Hook

import { LatLng, LeafletView } from 'react-native-leaflet-view';

export default function App(){

  
  const [DEFAULT_COORDINATES, setCoordinates]: LatLng = useState({
      lat: 37.78825,
      lng: -122.1324,
    });

    return(
      <>

         <LeafletView
            mapCenterPosition={DEFAULT_COORDINATES}
         />
    
        <Button onPress={() => {
          setCoordinates({ 
              lat: 40.706669,
              lng: -73.997705
          })
        }/>

      </>
)}

I hope it helps :)

cubevis avatar Feb 20 '24 23:02 cubevis