rrose icon indicating copy to clipboard operation
rrose copied to clipboard

feature req: Re-initialize layout on close/re-open

Open xEtherealx opened this issue 10 years ago • 7 comments

If the popup is closed, map is panned, and popup reopened, then the orientation should be recalculated.

The undesirable behavior can be seen when using the "bindPopup" method on a marker.

xEtherealx avatar Jun 02 '14 18:06 xEtherealx

I'm also having issues with this. I would like to be able to pan, click a marker, and have the position of the popup update.

RobbieTheWagner avatar Aug 27 '14 14:08 RobbieTheWagner

I accomplished this by binding the popup on marker click, then destroying it and binding a new one when you click it again, therefore the coordinates are always fresh.

RobbieTheWagner avatar Aug 27 '14 15:08 RobbieTheWagner

I think I did the same -- will try to dig up a snippet to post.

xEtherealx avatar Aug 27 '14 15:08 xEtherealx

This is applied to a leaflet marker (note that "this" here is the marker itself:

// Create a toggle popup function to re-position rrose
marker.on('click', function(e){
    if (this._custom_popup) {
        self.layer.removeLayer(this._custom_popup);
        this._custom_popup = null;
    } else {
        this._custom_popup = new L.Rrose({ name: this._popup_name, closeOnClick: false,})
                                .setContent(this._popup_content)
                                .setLatLng(this._popup_position);
        self.layer.addLayer(this._custom_popup);
    }
});

xEtherealx avatar Aug 28 '14 12:08 xEtherealx

I had a slightly different approach:

marker.on('click', function (e) {
          var clickedPopup = e.target.getPopup();
          var newPopup = new L.Rrose({ offset: new L.Point(0, -10), closeButton: false, autoPan: false, closeOnClick: true });
          var popupContent = yourPopupContentVariable;
          //If a popup has not already been bound to the marker, create one and bind it.
          if (!clickedPopup) {
            newPopup.setContent(popupContent)
              .setLatLng(e.latlng)
              .openOn(e.target._map);
            e.target.bindPopup(newPopup);
          }
          //We need to destroy and recreate the popup each time the marker is clicked to refresh its position
          else if (!clickedPopup._isOpen) {
            var content = clickedPopup.getContent();
            e.target.unbindPopup(clickedPopup);
            newPopup.setContent(content)
              .setLatLng(e.latlng)
              .openOn(e.target._map);
            e.target.bindPopup(newPopup);
          }
        });

RobbieTheWagner avatar Aug 28 '14 14:08 RobbieTheWagner

Neither of these methods help in my particular case. We bind the popup content to the marker when the page loads for all markers, this is due to our application fetching search results on load.

We then have a simple:

    this.markers.on('click', function(e) {
        e.layer.openPopup();
    });

and e.layer.closePopup() for when the user clicks out or on another marker.

Hopefully there is a way to embed this in the L.Rrose extension method to occur when the openPopup() method occurs vs having to re-bind the popup on every close and re-open.

1parkplace avatar Oct 14 '14 23:10 1parkplace

@1parkplace why can't you use the method I did? You can use e.target.getPopup() to get the popup you bound to the marker before. It should work with markers with prebound popups with no problem. Please take another look.

RobbieTheWagner avatar Oct 15 '14 14:10 RobbieTheWagner