Home > Software engineering >  How to modify href property on Leaflet 1.8 Popup?
How to modify href property on Leaflet 1.8 Popup?

Time:04-28

Is there a way to modify the href property of the close button on a Leaflet 1.8 popup? I can’t find anything in the documentation for it.

CodePudding user response:

Unfortunately there is indeed no API in Leaflet for that specifically.

However you can easily customize Leaflet behaviour by modifying how its classes behave.

In your case, you would override L.Popup._initLayout method.

Something like:

L.Popup.include({
  _originalInitLayout: L.Popup.prototype._initLayout, // Keep a reference to super method

  _initLayout() {
    this._originalInitLayout();
    this._closeButton?.href = "#myCustomValue"; // Change the value as desired
  }
});

See also the Leaflet tutorial about extending its classes.

  • Related