Mateusz Gnys
Mateusz Gnys

Reputation: 19

Leaflet map: marker click change popup of different marker

I'm very basic at programming and require that option just for one specific project. I'd love to change content of one master popup by clicking on different markers. Thing is, I have 0 clue how to get .setContent() of popup on different marker, using .on('dblclick') my marker.

I was thinking about giving value to a variable depending on marker number, and then filling one specific popup with info regarding variable number.

I intentionally skipped code block as it wouldn't bring anyone closer to the problem I have. I added my 'project' on jsfiddle.

Thanks!!!

My project on jsfiddle

var map = L.map('map').setView(center, 11);
var popupMaster = L.popup({
    closeOnClick: false,
    autoClose: false,
    closeButton: false
  })
  .setLatLng([54.451194, 18.744001])
  .setContent('Show text here')
  .openOn(map);


var marker1 = L.marker([54.351194, 18.644001], {
    title: "F-25",
    opacity: 0.5
  })
  .addTo(map)
  .bindPopup(popup1)
  .on('mouseover', function(e) {
    this.openPopup();
    this.setOpacity(1.0);
  })
  .on('mouseout', function(e) {
    this.closePopup();
    this.setOpacity(0.5)
  });

Upvotes: 0

Views: 1145

Answers (1)

peeebeee
peeebeee

Reputation: 2618

You already have the master popup in a variable, so you can update the content from a dblclick event on another marker like this

marker.on("dblclick", function(e) {
    popupMaster.setContent("New content here");
});

Upvotes: 3

Related Questions