Leaflet Geodesy

Generate true geodesic circles that exhibit projection distortion using the Geodesy plugin.

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Leaflet Geodesy</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.mapbox.com/mapbox.js/v3.1.1/mapbox.js'></script>
<link href='https://api.mapbox.com/mapbox.js/v3.1.1/mapbox.css' rel='stylesheet' />
<style>
  body { margin:0; padding:0; }
  #map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<script src='https://api.mapbox.com/mapbox.js/plugins/leaflet-geodesy/v0.1.0/leaflet-geodesy.js'></script>

<style>
.ui-form {
  background:#fff;
  position:absolute;
  top:10px;right:10px;
  padding:10px;
  border-radius:3px;
  }
  .ui-form label {
    font-size:12px;
    display:block;
    margin-bottom:5px;
    }
</style>

<div id='map'></div>
<div class='ui-form'>
  <label for='radius'>Enter a radius (m)</label>
  <input id='radius' type='number' step=1000 value=2000000 min=1 max=20000000 />
</div>

<script>
L.mapbox.accessToken = '<your access token here>';
var map = L.mapbox.map('map', 'mapbox.streets')
    .setView([0, 20], 2);

var planarCircle = L.circle([0, 0], 2000000, {
    fillOpacity: 0,
    color: '#00f'
}).addTo(map);

var desyCircle = LGeo.circle([0, 0], 2000000, {
    parts: 60,
    color: '#f00',
    fillOpacity: 0
}).addTo(map);

document.getElementById('radius').onchange = function() {
    desyCircle.setRadius(+this.value);
    planarCircle.setRadius(+this.value);
};

map.on('mousemove', function(e) {
    desyCircle.setLatLng(e.latlng);
    planarCircle.setLatLng(e.latlng);
});
</script>
to create your own custom map and use it in this example.
Use this example by copying its source into your own HTML page and replacing the Map ID with one of your own from your projects. Having trouble with JavaScript? Try out Codecademy or contact our support team.
Copy example