Skip to content

Instantly share code, notes, and snippets.

@wboykinm
Created December 2, 2014 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wboykinm/e17149be752de37a85fe to your computer and use it in GitHub Desktop.
Save wboykinm/e17149be752de37a85fe to your computer and use it in GitHub Desktop.
Negative buffer with turf.js
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>turf-buffer</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://rawgit.com/Turfjs/turf/master/turf.min.js'></script>
<script src='https://api.tiles.mapbox.com/mapbox.js/v2.0.1/mapbox.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox.js/v2.0.1/mapbox.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<div id='map'></div>
<script>
L.mapbox.accessToken = 'pk.eyJ1IjoiZmFyYWRheTIiLCJhIjoiTUVHbDl5OCJ9.buFaqIdaIM3iXr1BOYKpsQ';
var polygon = turf.polygon([
[
[-121.5847,40.1002],[-121.5080,40.1002],[-121.4368,40.1495],[-121.4040,40.1495],[-121.3656,40.0838],[-121.4204,40.0181],[-121.4094,39.8702],[-121.0753,39.5963],[-121.1575,39.5197],[-121.3054,39.5197],[-121.3328,39.4265],[-121.4040,39.3389],[-121.6121,39.3170],[-121.6230,39.2951],[-121.9078,39.3061],[-121.8914,39.3827],[-121.8585,39.5361],[-121.9955,39.5361],[-121.9900,39.6401],[-121.9681,39.6511],[-121.9955,39.6675],[-121.9407,39.6949],[-121.9462,39.7333],[-122.0448,39.7990],[-122.0667,39.8428],[-122.0448,39.8811],[-121.7764,39.8866],[-121.7052,39.9852],[-121.6449,39.9852]
]
], {
"fill": "#e2e3e3",
"stroke": "#333",
"stroke-width": 5
});
var map = L.mapbox.map('map', 'faraday2.206936a8')
.setView([39.66914219401813, -121.44561767578125], 9);
var buffer = turf.buffer(polygon, -8, "miles");
buffer.features[0].properties = {
"fill": "#0000ff",
"stroke": "#0000ff",
"stroke-width": 5,
"description": "8 miles inward"
}
L.mapbox.featureLayer().setGeoJSON(polygon).addTo(map);
L.mapbox.featureLayer().setGeoJSON(buffer).addTo(map);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment