Leaflet geoJson layers hidden outside viewport

2020-05-07 08:27发布

问题:

I have a leaflet map with a few layers on it. Whenever layers are not in the viewport, they are hidden untill panning has completed:

Regular view with layers:

Panning right, to show layers outside viewport:

Panning stopped:

As illustrated above, the layers will first become visible once panning has stopped and mouse(finger) released.

I have tried the following, which didn't work

var map = L.map('map',{ bounceAtZoomLimits: false, removeOutsideVisibleBounds: false}).setView([40, 0], 2);
L.geoJson(mapData).addTo(map);

回答1:

Seems the solution was right in front of me

Adding the following will render the entire map:

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

Solution found here