pavel-corsaghin / react-native-leaflet

A LeafletView component using WebView and Leaflet map for React Native applications
MIT License
99 stars 42 forks source link

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

Open loloide opened 1 year ago

loloide commented 1 year ago

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.

cubevis commented 4 months ago

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 :)