| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title></title> | |
| <style> | |
| .county { | |
| fill: rgb(97, 183, 58); | |
| stroke: #fff; | |
| stroke-width: 2px; | |
| } | |
| .county.buffered { | |
| fill: rgba(255, 255, 255, 0.3); | |
| stroke: none; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <script src="//api.tiles.mapbox.com/mapbox.js/plugins/turf/v2.0.0/turf.min.js"></script> | |
| <script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/topojson/1.6.20/topojson.min.js"></script> | |
| <script> | |
| var width = 960, | |
| height = 500; | |
| var projection = d3.geo.conicConformal() | |
| .rotate([90, 0]) | |
| .center([0.1995, 44.75]) | |
| .parallels([29.5, 45.5]) | |
| .scale(6000) | |
| .translate([width/2, height/2]) | |
| .precision(0.1); | |
| var path = d3.geo.path() | |
| .projection(projection); | |
| var svg = d3.select("body").append("svg") | |
| .attr("width", width) | |
| .attr("height", height); | |
| d3.json("wi.json", function(error, wi) { | |
| if (error) throw error; | |
| wi = topojson.feature(wi, wi.objects.wi); | |
| var wiBuffered = buffer(wi, -5, "miles"); | |
| svg.selectAll(".county").data(wi.features) | |
| .enter().append("path") | |
| .attr("class", "county") | |
| .attr("d", path); | |
| svg.selectAll(".county.buffered").data(wiBuffered.features) | |
| .enter().append("path") | |
| .attr("class", "county buffered") | |
| .attr("d", path); | |
| }); | |
| function buffer(featureCollection, distance, unit) { | |
| var features = featureCollection.features | |
| .map(function(feature) { | |
| var buffered = null; | |
| try { buffered = turf.buffer(feature, distance, unit); } | |
| catch(e) { /* console.error(e); */ } | |
| return buffered; | |
| }) | |
| .filter(function(feature) { return feature !== null; }); | |
| return { | |
| type: "FeatureCollection", | |
| features: features, | |
| properties: null | |
| }; | |
| } | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment