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

Prevent default zoom if map is set to fitbounds #236

Open bozdoz opened 9 months ago

bozdoz commented 9 months ago

RE: https://wordpress.org/support/topic/prevent-default-map-tiles/#post-17065108

if a map is set via [leaflet-map] it defaults to whatever the default lat/lng is. That same map may be instantiated with [leaflet-map fitbounds], and it doesn't need to start at the default lat/lng.

Investigate whether we can wait to create the map, after the shapes have been created.

webd-uk commented 5 months ago

Hi,

Just want to remind you about this because I've recently found that it actually highlights a bug (in my opinion).

If you use this shortcode to initiate the map ...

[leaflet-map fitbounds]

... then the default lat/lng from settings is used before the markers are added and tiles are requested. Then the markers are added, fitbounds is run and the correct tiles are then loaded. This is fine so long as the default lat/lng is the same as the one computed by fitbounds but if it isn't then un-necessary tiles are loaded.

If you instead use this to initiate the map in order to override the default lat/lng ...

[leaflet-map lat=50.9497 lng=0.7373 fitbounds]

... then we find that fitbounds no longer works so we suspect that adding lat and lng parameters disables fitbounds.

Ideally, no map tiles would be loaded if fitbounds parameter is present until fitbounds has run.

Oliver