Issue:
By default Leaflet shows data drawn onto the world map within a fixed boundary that horizontally goes from -180° to 180° and centers around 0°. Shapes that span across the meridian will be cut of on both sides and currently its not possible to zoom the map to a position where both can be shown. See example with markers:
Briefly look into options that might help improve the situation for these edge cases. For use cases see e.g. T195654 or T313615
Findings and resources:
Static maps do not exactly have that problem. They draw the map once and provide a stitched version by repeating the drawing horizontally.
See https://en.wikipedia.beta.wmflabs.org/wiki/Maptests/Anti-meridian#A_line_on_the_equator.
Static
Or from https://fr.wikipedia.org/wiki/Utilisateur:WikedKentaur/polygon ( originally from T195654 )
Static vs Dynamic
Dynamic maps on the other hand provide the option to draw across the anti-meridian by setting values >180°
See https://en.wikipedia.beta.wmflabs.org/wiki/Maptests/Anti-meridian#/map/0 ( originally from T313615 )
Dynamic
Because the static mode "just" repeats the rendered world within the 180° some info is lost there though
Ideas to move forward:
On the dynamic maps copy and repeat the data from the central base map to the maps left and right, similar to what happens on the static map.
- At least for markers there's a library supporting that https://gitlab.com/IvanSanchez/Leaflet.RepeatedMarkers and there are suggestions to do this for lines/polygons as well
- Additionally to that we could try to limit the view so that only "one" world can be seen on the dynamic map. This could be done by limiting the zoom and cutting the viewport.
- Note, that similar to what's currently happening on the static map, this is incompatible with drawing features over the >180°
Identify features that cross the anti-meridian and convert them to values >180°
- For features like in the example at the top or a split shape like in F36914705 this method could move the "split" parts together at one end and the map's focus could be set there then when in dynamic mode. The effect then could be similar to what's visible in the static mode F36914703.
- This might allow to also keep representing features defined over the >180°
- Identifying the relevant features and their boundaries is the most tricky to almost impossible part here. Bringing some shapes in "order" with this method might break other shapes on the map.
Other resources
- https://stackoverflow.com/questions/40532496/wrapping-lines-polygons-across-the-antimeridian-in-leaflet-js/40544502#40544502
- Openstreetmap.org has the same issues see https://www.openstreetmap.org/relation/151231
- https://github.com/Leaflet/Leaflet/issues/82 suggests a workaround with L.LatLng
- https://github.com/rstudio/leaflet/issues/553
- https://github.com/briannaAndCo/Leaflet.Antimeridian






