|
<!DOCTYPE html> |
|
<meta charset="utf-8"> |
|
<style> |
|
|
|
body { |
|
margin: 0; |
|
} |
|
|
|
svg { |
|
background-color: #fff; |
|
} |
|
|
|
path { |
|
fill: none; |
|
stroke: #072e31; |
|
stroke-opacity: 0.4; |
|
stroke-width: 2; |
|
stroke-linejoin: round; |
|
stroke-linecap: round; |
|
|
|
} |
|
|
|
.major_road { |
|
/*stroke: #4fa242; fill: #7aea90; */ |
|
stroke-width: 2; |
|
} |
|
.minor_road { |
|
/*stroke: #4fa242; fill: #7aea90; */ |
|
stroke-width: 2; |
|
} |
|
/* |
|
.highway { stroke: #f39; stroke-width: 1.5px; } |
|
|
|
.rail { stroke: #7de; } |
|
*/ |
|
</style> |
|
<body> |
|
<script src="https://d3js.org/d3.v3.min.js"></script> |
|
<script src="d3.geo.tile.min.js"></script> |
|
<script> |
|
|
|
var width = Math.max(960, window.innerWidth), |
|
height = Math.max(500, window.innerHeight); |
|
|
|
var tiler = d3.geo.tile() |
|
.size([width, height]); |
|
|
|
var projection = d3.geo.mercator() |
|
//.center([-84.2500477,30.437805]) |
|
//.center([-122.2183, 37.830]) |
|
.center([-118.3614976, 34.0937458]) |
|
//.scale((1 << 21) / 2 / Math.PI) |
|
.scale((1 << 20) / 2 / Math.PI + 15000) |
|
.translate([width / 2, height / 2]); |
|
|
|
var path = d3.geo.path() |
|
.projection(projection); |
|
|
|
var svg = d3.select("body").append("svg") |
|
.attr("width", width) |
|
.attr("height", height) |
|
.append("g") |
|
.style("filter", "url(#gooey)") //Set the filter on the container svg |
|
|
|
//SVG filter for the gooey effect |
|
//Code taken from http://tympanus.net/codrops/2015/03/10/creative-gooey-effects/ |
|
var defs = svg.append('defs'); |
|
var filter = defs.append('filter').attr('id','gooey'); |
|
filter.append('feGaussianBlur') |
|
.attr('in','SourceGraphic') |
|
.attr('stdDeviation','1') |
|
.attr('result','blur'); |
|
filter.append('feColorMatrix') |
|
.attr('in','blur') |
|
.attr('mode','matrix') |
|
.attr('values','1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 17 -4'); |
|
|
|
svg.selectAll("g.tile") |
|
.data(tiler |
|
.scale(projection.scale() * 2 * Math.PI) |
|
.translate(projection([0, 0]))) |
|
.enter().append("g").classed("tile", true) |
|
.each(function(d) { |
|
var g = d3.select(this); |
|
d3.json("https://tile.mapzen.com/mapzen/vector/v1/all/" + d[2] + "/" + d[0] + "/" + d[1] + ".json?api_key=vector-tiles-LM25tq4", function(error, json) { |
|
if (error) throw error; |
|
//console.log("data", json) |
|
|
|
g.selectAll("path") |
|
.data(json.roads.features.sort(function(a, b) { return a.properties.sort_key - b.properties.sort_key; })) |
|
.enter().append("path") |
|
.attr("class", function(d) { return d.properties.kind; }) |
|
.attr("d", path); |
|
}); |
|
}); |
|
|
|
</script> |