JSFiddle - React, Tailwind, and code Playground

Creating 100m rectangles with Leaflet Geodesy

by nathansnider

HTML

<script src="//cdn.leafletjs.com/leaflet/v1.0.0-rc.1/leaflet.js"></script>
<link rel="stylesheet" href="//cdn.leafletjs.com/leaflet/v1.0.0-rc.1/leaflet.css">
<script src="//api.mapbox.com/mapbox.js/plugins/leaflet-geodesy/v0.1.0/leaflet-geodesy.js"></script>
<div id="map"></div>

CSS

html,
body,
#map {
  height: 100%;
  width: 100%;
  padding: 0px;
  margin: 0px;
}

JavaScript

var map = L.map('map').setView([34.05, -118.25], 14);
ATTR = '&copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
  '<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a> | ' +
  '&copy; <a href="http://cartodb.com/attributions">CartoDB</a>';
CDB_URL = 'http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png';
L.tileLayer(CDB_URL, {
  attribution: ATTR
}).addTo(map);

map.on('click', function(e) {
  var circ = LGeo.circle(e.latlng, 100);
  var rect = L.rectangle(circ.getBounds()).addTo(map);
});