simonw / datasette-leaflet-geojson

Datasette plugin that replaces any GeoJSON column values with a Leaflet map.
17 stars 7 forks source link

fire a window resize after rendering features #4

Closed chris48s closed 4 years ago

chris48s commented 4 years ago

This plugin is really useful, but I hit a very frustrating issue with it:

As it stands, when I use it to render a polygon column, only the last row will have its polygon inside the desired viewport. All the other rows end up with the map offset from the intended centre. This screen capture shows an example of this behaviour. I get the same behaviour in firefox and chrome.

GIFrecord_2019-10-13_154418

This issue doesn't reproduce when the geometry is a Point.

I tried various ways to resolve this (changed the rendering order, moved the map.fitBounds() inside a layer.add event or a map.addlayer event handler, declared a new layer var each time through the loop, etc). None fo those were effective. The one thing I found did work was spoofing a window resize event that doesn't actually change the window size after all the maps are rendered. This has the effect of redrawing all the maps which then centers them all correctly, as shown in this screen capture:

GIFrecord_2019-10-13_154629

This is a rather unsatisfying fix as it doesn't really address the underlying issue, but it does at least offer a workaround.

simonw commented 4 years ago

I spotted this bug too, but I never got around to investigating it. This is great - thanks for figuring out what was going on.

simonw commented 4 years ago

Released in 0.3 https://github.com/simonw/datasette-leaflet-geojson/releases/tag/0.3