Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using Leaflet.GestureHandling with React.Leaflet #73

Open
AliBayatpour opened this issue Jul 1, 2021 · 3 comments
Open

using Leaflet.GestureHandling with React.Leaflet #73

AliBayatpour opened this issue Jul 1, 2021 · 3 comments

Comments

@AliBayatpour
Copy link

Hi Everybody! First of all thanks a lot for the amazing library. I've searched to find how I can use this library for React Leaflet. I couldn't make it work on React leaflet. I'll be very thankful if someone has any solution for React. leaflet:
my react leaflet version is:
"react-leaflet": "^3.0.5",

Imagine someone is using the map like below as the react-leaflet docs:

<MapContainer center={position} zoom={13} scrollWheelZoom={false}> <TileLayer attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" /> <Marker position={position}> <Popup> A pretty CSS3 popup. <br /> Easily customizable. </Popup> </Marker> </MapContainer>

@nategurian
Copy link

@AliBayatpour : Running into the same issue. Wish there was a way to incorporate gesture handling with the MapContainer component.

@nategurian
Copy link

@AliBayatpour I just followed this example and got it working with react
#65

Hope that helps!

@kmoskwiak
Copy link

kmoskwiak commented Jan 7, 2024

Enabling this plugin dynamically with the help of useMap hook worked for me:

import { useMap } from "react-leaflet";
import { GestureHandling } from "leaflet-gesture-handling";
import "leaflet-gesture-handling/dist/leaflet-gesture-handling.css";

export const MapController = () => {
  const map = useMap();
  
  useEffect(() => {
    map.addHandler("gestureHandling", GestureHandling);
    // @ts-expect-error typescript does not see additional handler here
    map.gestureHandling.enable();
  }, [map]);

  return null;
}

Then add MapController somewhere inside <MapContainer />;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants