metalheart
metalheart

Reputation: 3809

react-leaflet: missing touchstart event

I would like to handle touchstart and touchend events on the react-leaflet map component but seem to be unable to do so - what am I missing?

Here's what I tried - general setup:

<MapContainer>
  <MapInitializer />
  ...
</MapContainer>
  1. Handle events using a map initializer component
function MapInitializer() {
  const map = useMap();

  const handleTouchStart = (event) => {
    alert('DEBUG touchstart 1');
  }

  map.on('touchstart', handleTouchStart);
}
  1. With useMapEvent as per the docs
function MapInitializer() {
  const map2 = useMapEvent('touchstart', () => {
    alert('DEBUG touchstart 2');
  });
}
  1. Directly on the map component
<MapContainer touchStart='handleTouchStart'>
  ...
</MapContainer>

Upvotes: 0

Views: 37

Answers (0)

Related Questions