yafred / leaflet-responsive-popup

This plugin overrides L.Popup to remove the need to move the map to be able to see the content of the popup.
https://yafred.github.io/leaflet-responsive-popup/
BSD 2-Clause "Simplified" License
90 stars 20 forks source link

how to implement with react Leaflet ? #15

Open yjarid opened 4 years ago

yjarid commented 4 years ago

I am very intrested on your pluggin, however I am strugling to how to implement it with react leaflet

hexadeciman commented 3 years ago
  1. install with npm i --save leaflet-responsive-popup
  2. add the import on top of your file import R from "leaflet-responsive-popup";
  3. you might need to declare a file externalModules.d.ts and declare the module:
    
    declare module "leaflet-responsive-popup" {
    export = responsivePopup;
    }
4. then here's a snippet of how to use it in React:

const leaflet = useLeaflet(); R.responsivePopup({ autoPanPadding: [0, 0], hastip: false, offset: [0, 5], maxWidth: 500, closeButton: false, closeOnClick: false, autoPan: false, }) .setLatLng({ lat: 0, lng: 0 }) .setContent("Hello World") .openOn(leaflet.map);



You can wrap that in a component and decide to use it or not.