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

Stop the web page from scrolling to the top when the Reset View Control is clicked. #1

Open
itamair opened this issue Nov 12, 2022 · 2 comments

Comments

@itamair
Copy link

itamair commented Nov 12, 2022

If the Leaflet Map is not at the top scroll of the web page, the click of the Reset View Control makes the page scrolling all to the top, eventually even making the map itself to disappear ...

Hence we need to stop the web page from scrolling to the top when the Reset View Control is clicked,
and this post highlights the proper solution:
https://stackoverflow.com/questions/1601933/how-do-i-stop-a-web-page-from-scrolling-to-the-top-when-a-link-is-clicked-that-

Adding

e.preventDefault();

before the following:

this._map.setView(this.options.latlng, this.options.zoom);

solves this issue to me.

@itamair itamair changed the title Stop the web page from scrolling to the top when the Reset View Control is clicked? Stop the web page from scrolling to the top when the Reset View Control is clicked. Nov 12, 2022
@itamair
Copy link
Author

itamair commented Nov 12, 2022

further tested the above change request, and it wouldn't work in case the ResetView.__resetView() is called/triggered programmatically (that could always be) because the "e" event won't be defined.
The following solution solves that and make it work also when called/triggered programmatically:

if (e) { L.DomEvent.preventDefault(e) }

emilymerwin added a commit to emilymerwin/Leaflet.ResetView that referenced this issue Apr 27, 2023
emilymerwin added a commit to emilymerwin/Leaflet.ResetView that referenced this issue Apr 27, 2023
emilymerwin added a commit to emilymerwin/Leaflet.ResetView that referenced this issue Apr 27, 2023
@emilymerwin
Copy link

This is an issue for me as well, more so because my map is in an iFrame so clicking the reset view button actually means the parent page is replaced by the iframe'd child page (I have <base target="_parent"/> in my <head> already but that doesn't help in this case). I made a pull request

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