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

Customise removeOutsideVisibleBounds #316

Closed
daviestar opened this issue Feb 13, 2014 · 2 comments
Closed

Customise removeOutsideVisibleBounds #316

daviestar opened this issue Feb 13, 2014 · 2 comments

Comments

@daviestar
Copy link

I'm finding an issue with the 'removeOutsideVisibleBounds' option on mobiles - Android and iOS.

I have a custom function in place to center the popup in the viewport, rather than the marker.

I have noticed just on mobiles, markers are immediately removed from the DOM when they are panned out of the viewport. The problems is, when I click my marker to open a popup, sometimes the marker is panned out of the viewport, which removes the popup and the marker. This is particularly evident in landscape mode on a small-screen mobile.

Is it possible to add some 'padding' to the calculation of 'removeOutsideVisibleBounds'? Something like an extra 100px on all sides? Or perhaps a flag to not remove a marker with an open popup?

@danzel
Copy link
Member

danzel commented Feb 13, 2014

Yep, you will need to override _getExpandedVisibleBounds

https://github.com/Leaflet/Leaflet.markercluster/blob/master/src/MarkerClusterGroup.js#L860

The current implementation will restrict to the screen size on mobile, if you change 869,870 to something like

            latDiff = Math.abs(sw.lat - ne.lat) * 0.1,
            lngDiff = Math.abs(sw.lng - ne.lng) * 0.1;

That should suit :)
You can't pad it in pixels, just in a percentage of the screen size. I'm sure there is a way if you do a bunch of projection, but this will probably suit fine.

@danzel danzel closed this as completed Feb 13, 2014
@daviestar
Copy link
Author

This works, cheers!

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

2 participants