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.

Leaflet polygons cut off on map viewport while dragging

See original GitHub issue

Current behavior: When dragging the map so that polygons or circles are only partly in the viewport, then dragging back to reveal them again, the part of the polygons or circles that were out of the viewport are cut off only to be properly redrawn after dragend.

Desired behavior: Either the polygons and circles should not be cut off, or seamlessly redrawn/reappear in the viewport.

The problem is present in http://leafletjs.com/examples/quick-start.html, see the attached gif for an impression of what happens.

Browser: Chrome 36.0.1985.125 m OS: Windows 8.1 Pro

Only part of the issue is present in IE 11.0.9600.17207. Leaflet does work as desired for circles only in this version of IE.

polygon_cutoff

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:3
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

16reactions
luveticommented, Oct 6, 2016

Apparently the L.Map constructor accepts a renderer option, so you can do something like this:

var map = new L.Map('map', { renderer: L.svg({ padding: 100 }) });

Of course you wouldn’t want to do this with a map that has a lot of things to render. But for my use case, this worked really well!

Side note: The current version of Leaflet (1.0.1) will actually (from what I can tell) create the renderer the first time map.getRenderer() is called, which you can see here https://git.io/vPn2v. So you could also do this:

var map = new L.Map('map');
map.getRenderer(map).options.padding = 100;

NOTE: I know this issue has been closed for a while now, but I was having this issue today, and figured I’d share my solution, in case anyone else comes across the same issue!

2reactions
colinmegillcommented, Feb 14, 2017

Brief update in case anyone else from the d3-verse ends up on this thread… at this point I believe the problem was that I was not manually fitting the d3 svg to the leaflet pane using getBounds, which is demo’d here: http://bl.ocks.org/d3noob/9211665.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Leaflet polygons cut off on map viewport while dragging
Desired behavior: When dragging the polygon or circle it should come center of the map and it should load properly(Don't cut off). The...
Read more >
How to keep leaflet tooltips within visible map view
The issue is when the user mouses over features on the outer edges of the visible map area, the tooltips are outside of...
Read more >
Plugins - Leaflet - a JavaScript library for interactive maps
Displays national maps of Switzerland using map tiles from Swisstopo. ... that is kept fixed to the center of the map when the...
Read more >
Chapter 6 Leaflet | Introduction to Web Mapping
Open example-06-01.html in the browser. Try changing map perspective by dragging the mouse while pressing the Ctrl key. Compare this type of interaction...
Read more >
geoman-leaflet-extend - npm Package Health Analysis - Snyk
The npm package geoman-leaflet-extend receives a total of 0 downloads a week. ... make polygon not snappable during draw map.pm.
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