bozdoz / wp-plugin-leaflet-map

Add leaflet maps to Wordpress with shortcodes
https://wordpress.org/plugins/leaflet-map/
GNU General Public License v2.0
140 stars 71 forks source link

detectRetina and maxZoom = no tiles #182

Closed hupe13 closed 1 year ago

hupe13 commented 1 year ago

I can confirm this bug. https://wordpress.org/support/topic/detectretina-and-maxzoom-no-tiles/

bozdoz commented 1 year ago

Seems familiar. I thought I already resolved this.

bozdoz commented 1 year ago

In leaflet, there was this:

https://github.com/Leaflet/Leaflet/pull/7328

bozdoz commented 1 year ago

And from the readme:

= 2.21.0 =

  • Fixes issues with tilelayers when min_zoom and max_zoom are identical and detect_retina is true
hupe13 commented 1 year ago

The bug exists. I'm using Leaflet V 1.9.2, Leaflet Map 3.0.5. MaxZoom is 19. Shortcode:

[leaflet-map height=200px width=100% detect-retina]
[zoomhomemap]

https://user-images.githubusercontent.com/73023225/201288825-96ca3e58-c81b-46e2-9d30-6510a8c37aa9.mov

hupe13 commented 1 year ago

If the shortcode is: [leaflet-map height=200px width=100% max_zoom=18 detect-retina] No tiles are displayed at zoom level 18 if retina is true.

bozdoz commented 1 year ago

That's upsetting. I'll see if it happens in leaflet; I imagine it does. Maybe there's something we can do on the plug-in to fix it.

bozdoz commented 1 year ago

Do you believe this is resolved @hupe13 ?

hupe13 commented 1 year ago

It isn't resolved. I tried it, but I did not understand the $raw_map_options. I'll have to look at it again.

bozdoz commented 1 year ago

Yeah, so it looks like when detect-retina is on, leaflet refuses to load tiles at the max_zoom (likely because they have some code to disable loading any tiles greater than max_zoom, and detectRetina requires loading the next zoom level)

bozdoz commented 1 year ago

This is related to what I worked on before, but I think it's slightly different than the bug I was trying to fix:

https://github.com/Leaflet/Leaflet/commit/990d49773a129619f2eed09712867627c8e3cf60#diff-65b47b2f5de405436bea6525bc4a7100f141796807f6efcc5cab6b8d9f543691R98-R116

Issue: https://github.com/Leaflet/Leaflet/issues/7326

So I think the new issue here is that maxZoom seems to affect the actual tile request: probably _updateLevels and _pruneTiles in L.GridLayer:

https://github.com/Leaflet/Leaflet/blob/3f5ea5a271b41ec09147ea774fea90bc960a1ab2/src/layer/tile/GridLayer.js#L361

TileLayer is altering maxZoom if detectRetina is true: https://github.com/Leaflet/Leaflet/blob/3f5ea5a271b41ec09147ea774fea90bc960a1ab2/src/layer/tile/TileLayer.js#L102

And then GridLayer (which is what TileLayer is extended from) is pruning tiles and refusing to load new tiles at the maxZoom. Need to make a demo and a new Leaflet Issue.

bozdoz commented 1 year ago

Ok, demo made: https://codepen.io/bozdoz/pen/VwBjwaW

So maybe it's not a problem with Leaflet, but a problem with configuring the tileLayer. Perhaps this can just be removed now that Leaflet has a fix for this:

https://github.com/bozdoz/wp-plugin-leaflet-map/blob/master/shortcodes/class.map-shortcode.php#L287-L294