Mercator distortion with lines
by Stefano
HTML
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css">
<script src="https://cdn.jsdelivr.net/npm/@turf/turf@5/turf.min.js"></script>
<div id="map"></div>
CSS
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
}
#map {
width: 100%;
height: 100%;
}
JavaScript
const center = turf.point(getLeafletCoords([43.12831626497193, 1.259286403656006]));
var map = L.map('map', {
center: getLeafletCoords(center),
zoom: 17,
layers: [ L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png') ],
});
const distance = .1;
L.circle(getLeafletCoords(center), {
color: 'purple',
fillColor: 'purple',
fillOpacity: 0.5,
radius: 20
}).addTo(map);
const ne = turf.rhumbDestination(center, distance, 45);
const sw = turf.rhumbDestination(center, distance, -135);
const nw = turf.rhumbDestination(center, distance, 135);
const se = turf.rhumbDestination(center, distance, -45);
L.polyline([getLeafletCoords(ne), getLeafletCoords(sw)]).setStyle({color: 'green', weight: 5}).addTo(map);
L.polyline([getLeafletCoords(nw), getLeafletCoords(se)]).setStyle({color: 'red', weight: 5}).addTo(map);
function getLeafletCoords(point) {
return turf.getCoords(point).slice().reverse();
}