Initialized leaflet map with worldCopyJump as true
var map = L.map('weatherMap', {
center: [51.505, -0.09],
zoom: 13,
worldCopyJump: true
});
need to change worldCopyJump as false after that?
Initialized leaflet map with worldCopyJump as true
var map = L.map('weatherMap', {
center: [51.505, -0.09],
zoom: 13,
worldCopyJump: true
});
need to change worldCopyJump as false after that?
If you look at Leaflet's source code, you can see that the worldCopyJump
map option is evaluated only once, when the map drag handler is being enabled for the first time (notice how this._draggable
is cached and never destroyed).
You can access the map handlers as map properties, then enable and disable them. As the worldCopyJump
option is evaluated when enabling the dragging handler for the first time (when its internal _draggable
property is falsy), one is able to do something like:
map.dragging.disable();
delete map.dragging._draggable;
map.options.worldCopyJump = !map.options.worldCopyJump;
map.dragging.enable();
Remember the javascript unwritten convention that properties and methods starting with an underscore (_
) are meant to be protected/private - deleting _draggable
above is quite an ugly hack.
Ideally, the code for the draggable handler for L.Map
could be refactored in order to evaluate the worldCopyJump
option on re-enabling the dragging handler. However, the use cases for this are very niche and nobody has undertaken that (as of this writing).