smeijer / leaflet-geosearch

A geocoding/address-lookup library supporting various api providers.
https://smeijer.github.io/leaflet-geosearch/
MIT License
1.03k stars 273 forks source link

Popup options #220

Open constantbourgois opened 4 years ago

constantbourgois commented 4 years ago

Hi Thanks for your work. May I suggest to add a feature for enabling popup options like this

addMarker(result, query) {
const { marker: options, showPopup, popupFormat , popupOptions } = this.options;
const marker = new L.Marker([result.y, result.x], options);
let popupLabel = result.label;

if (typeof popupFormat === 'function') {
  popupLabel = popupFormat({ query, result });
}

marker.bindPopup(popupLabel, popupOptions);

and then you provide the options you need like this for instance

 const searchControl = new GeoSearchControl({
    provider: new OpenStreetMapProvider(),
    style: "bar",
    showMarker: true, // optional: true|false  - default true
    showPopup: true,
    keepResult: true,
    marker: {
      icon: new Icon.Default(),
      draggable: false,
    },
    popupFormat: function ({result}){ return result.label},
    popupOptions:  { 
      closeOnClick: false,
      className : "classname"
    }
  });