question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

are clipping options from leaflet implemented in folium?

See original GitHub issue

I’m completely new to folium and leaflet as of today, so maybe this is a silly question. I am plotting a LineString (though Polygon has the same behavior) on map and I noticed that I get visual artifacts when I scroll the map such that the perimeter is off the viewable area.

From googling around, I think it sounds and looks pretty much like this issue.

Edit 10/22: fixed a wrong variable name Here’s a simple version to illustrate:

import folium

lat, lon = (44, -93)
m = folium.Map(location=(lat, lon),
               zoom_start=12)

## used to be in the variable `box`; fixed as noted above
coords = [[-93.2, 43.8], [-92.8, 43.8], [-92.8, 44.2], [-93.2, 44.2]]
line = {'type': 'Feature',
        'geometry': {'type': 'LineString',
                     'coordinates': coords }
        }

folium.GeoJson(line, name='line',
               style_function=lambda x: {'color': '#999999',
                                         'fill': '#999999',
                                         'opacity': 0.8,
                                         'fillOpacity': 0.5}).add_to(m)
m

This is what I get on Chromium 62.0.3202.62 and Firefox 56.0.1:

anim

Is this an instance of the clipping documented on the leaflet issue? If so, is there a way to get at CLIP_PADDING or padding as referenced over there?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
jwhendycommented, Nov 2, 2017

Bah. Well, as is not that surprising (as it happens to me often), in the process of clarifying my thoughts for an issue at leaflet, I had a sudden burst of insight: what if the issue is the fact that I defined a LineString and then said to give it a fill?

Reviewing some documentation I’d run into when starting to play with folium, I found this on that geometry:

Points and lines are also similar in that they have no area: there is no inside or outside.

Huh. Well that’s interesting. Only one way to find out how this plays out in folium/leaflet and that was to specify 'type': 'Polygon' instead, which I also learned requires one more level of list nesting. With the original example above, I just changed it to this:

coords = [[
    [-93.2, 43.8],
    [-92.8, 43.8],
    [-92.8, 44.2],
    [-93.2, 44.2],
    [-93.2, 43.8],
]]
line = {'type': 'Feature',
        'geometry': {'type': 'Polygon',
                     'coordinates': coords }
        }

It worked! I don’t get that triangle artifact with this method. Pretty sure it’s a fluke that you can specify a fill for a line, but perhaps that’s an abuse of the shape’s intent and it just doesn’t handle it well?

Mystery solved, programmer’s angst resolved, thorn in brain removed… I can now sleep well tonight, and thanks once again for the assistance/patience! Hopefully this trail of breadcrumbs helps someone down the road.

1reaction
jwhendycommented, Oct 22, 2017

Figured it out. 0.5.0 release is dated 2017-09-13; looks like vector_layers were created or refactored on 2017-09-17. I installed from git and now I can use this.

My real shape is a complex polygon and I still show clipping/glitching with GeoJson, but vector_layers.Polygon is working great. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Folium 0.12.1 documentation
**kwargs – These values will map directly to the Leaflet Options. More info available here: ... no_clip (Bool, default False) – Disable polyline...
Read more >
How to select a polygon and use it as a clipping mask for other ...
I want the user to select a polygon (one of the local authorities) and then turn on other layers. I want these layers...
Read more >
Inserting an URL link in marker's popup in Folium
I want to insert a live url link into my marker's popup in Python Folium but I don't know what class and code...
Read more >
TUTO: Draw nice maps with folium - Kaggle
Markers are probably the most basic way to indicate some point of interest on a folium map. We will illustrate it with a...
Read more >
Displaying a gridded dataset on a web-based map
There are many options, but Dash-Leaflet is one of the best. It's a Python implementation of the popular LeafletJS mapping library and the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found