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

MeasureControl plugin scrolls map unwantedly #1737

Closed
fcenzato opened this issue Mar 14, 2023 · 6 comments · Fixed by #1748
Closed

MeasureControl plugin scrolls map unwantedly #1737

fcenzato opened this issue Mar 14, 2023 · 6 comments · Fixed by #1748
Labels
bug An issue describing unexpected or malicious behaviour plugin This issue/PR is about an existing or new plugin

Comments

@fcenzato
Copy link

Describe the bug
When trying to measure a distance with MeasureControl plugin, every time I select a point on the map, the map automatically scrolls, resulting in the point being not in the location I want it to be. This way, the plugin can't be used. See attached video for an example.

To Reproduce
Create a map with the following code, and open the saved file in a browser (Chrome or Edge):

import folium
from folium.plugins import MeasureControl

base_map = folium.Map()
MeasureControl().add_to(base_map)
base_map.save(outfile="test_map.html")

Expected behavior
Whenever you click to add a mark on the map, that mark should be at the point you clicked, not at a random location from an unwanted scrolling of the map

Environment:

  • Browser: Edge and Chrome (same behaviour)
  • Jupyter Notebook or html files: same behaviour in both
  • Python version: 3.10.9
  • folium version: 0.14.0
  • branca version: 0.6.0

Possible solutions
As a workaround, I have downgraded folium to version 0.12.1, in which the plugin works correctly

test_map.html.-.Work.-.Microsoft.Edge.2023-03-14.09-33-34.mp4
@iacisme
Copy link

iacisme commented Mar 23, 2023

I'm having the same issue in the latest folium.

This issue also exists in leafmap: jupyter-widgets/ipyleaflet#1076 so might it be something upstream?

I've also noticed marker clusters are acting funny as well, same as in ipyleaflet.

@Conengmo
Copy link
Member

Conengmo commented Apr 8, 2023

Unfortunately this is an issue in the upstream JS plugin we use: ljagis/leaflet-measure#171. This package is currently abandoned, so there's no fix.

A temporary work around is to use an older Leaflet version:
m = folium.Map()
m.default_js.append(('leaflet', 'https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.js'))
m.default_css.append(('leaflet_css', 'https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.css'))

I'd like to think about how we should solve this going forward:

  • Wait and hope for the original repo to get a new maintainer and the plugin to get updated.
  • Adopt a different plugin inside the MeasureControl class.
  • Remove the MeasureControl class.

If any of you involved in this issue know of an alternative JS plugin that we could adopt, I'd love to hear it!

Update: that issue on the upstream repo has a work around that we can include in the template. I'll open a PR.

@Conengmo Conengmo added bug An issue describing unexpected or malicious behaviour plugin This issue/PR is about an existing or new plugin in discussion This PR or issue is being discussed and removed in discussion This PR or issue is being discussed labels Apr 8, 2023
@Conengmo
Copy link
Member

Conengmo commented Apr 8, 2023

@iacisme, @fcenzato, could either of you confirm the PR I opened does fix the problem for you as well? If so, I'll merge it and it'll be included in the next Folium release.

@Conengmo Conengmo added the work in progress Work is in progress on a PR, check the PR to see its status label Apr 8, 2023
@fcenzato
Copy link
Author

fcenzato commented Apr 8, 2023

@Conengmo I tried installing that PR and the issue is not there anymore.

@Conengmo
Copy link
Member

Conengmo commented Apr 9, 2023

Great! I'll merge that PR, so the fix will be available to anyone who install Folium from the main git branch. It will also be included in the next release, v0.15.0.

@Conengmo Conengmo removed the work in progress Work is in progress on a PR, check the PR to see its status label Apr 9, 2023
@iacisme
Copy link

iacisme commented Apr 23, 2023

Sorry for being late to the party, thank you for resolving this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue describing unexpected or malicious behaviour plugin This issue/PR is about an existing or new plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants