2

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?

Luca Kiebel
  • 9,790
  • 7
  • 29
  • 44

1 Answers1

2

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).

IvanSanchez
  • 18,272
  • 3
  • 30
  • 45