Measuring extents of turf.buffer in Leaflet
When 'kilometers' is specified as the distance option, turf.buffer appears to first calculate a distance in degrees and then create a buffer in degrees rather than km. Thus, the real E-W dimension of a buffer will get narrower as latitude increases.
HTML
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css">
<script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script>
<script src="//api.tiles.mapbox.com/mapbox.js/plugins/turf/v2.0.0/turf.min.js"></script>
<div id="map"></div>
CSS
#map {
height: 500px;
}
JavaScript
var map = L.map("map").setView([61.441767, 5.470247], 3);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
var pt = {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [5.470247, 51.441767]
}
};
var buffered = turf.buffer(pt, 500, 'kilometers');
L.geoJson(pt).addTo(map);
bufferLayer = L.geoJson(buffered).addTo(map);
var point1=
testScales(pt, bufferLayer);
var pt2 = {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [5.470247, 71.441767]
}
};
var buffered2 = turf.buffer(pt2, 500, 'kilometers');
L.geoJson(pt2).addTo(map);
var bufferLayer2 = L.geoJson(buffered2).addTo(map);
testScales(pt2, bufferLayer2);
////////////////////////////////////////////////////////////////////////////////////////////
//functions to measure extent of buffer polygons//
//
//When 'kilometers' is specified as the distance option, turf.buffer appears to first
//calculate a distance in degrees and then just create a buffer in degrees rather than km.
//Thus, the real E-W dimension of a buffer will get narrower as latitude increases.
////////////////////////////////////////////////////////////////////////////////////////////
//input: GeoJson point and Leaflet layer for corresponding buffer
//creates line segments on axes, with popups for distance
function testScales(cenPt, bufLayer) {
var coords = [];
coords.north = [cenPt.geometry.coordinates[0], bufLayer.getBounds()._northEast.lat],
coords.east = [bufLayer.getBounds()._northEast.lng, cenPt.geometry.coordinates[1]],
coords.south = [cenPt.geometry.coordinates[0], bufLayer.getBounds()._southWest.lat],
coords.west = [bufLayer.getBounds()._southWest.lng, cenPt.geometry.coordinates[1]];
var scaleLines = {
type: "FeatureCollection",
...