React-leaflet v3 and leaflet-contextmenu plugin problem with map instance

Viewed 792
1 Answers

You can take the map instance using whenCreated prop on MapContainer

<MapContainer
        className="markercluster-map"
        center={currentLocation}
        zoom={zoom}
        maxZoom={18}
        contextmenu={true}
        contextmenuItems={[
          {
            text: 'Zoom in',
            callback: this.zoomIn
          },
          { text: 'Zoom out', callback: this.zoomOut }
        ]}
        whenCreated={(map) => this.setState({ map })}
      >
   ...
</MapContainer>

and then on your event listeners

zoomOut = () => {
    const { map } = this.state;
...
}
zoomIn = () => {
    const { map } = this.state;
...
}

Demo

Related