Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
xEtherealx opened this issue Jun 2, 2014 · 7 comments
Open

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

xEtherealx opened this issue Jun 2, 2014 · 7 comments

Comments

@xEtherealx
Copy link

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.

@RobbieTheWagner
Copy link

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
Copy link

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.

@xEtherealx
Copy link
Author

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

@xEtherealx
Copy link
Author

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);
    }
});

@RobbieTheWagner
Copy link

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);
          }
        });

@1parkplace
Copy link

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.

@RobbieTheWagner
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants