rveciana - drop-shadow-filter-for-the-haiyan-typhoon-track

Drop shadow filter for the Haiyan typhoon track

Open raw page in new tab

This example illustrates this GeoExamples blog entry. The map uses the base from the first example, but adding “drop shadow” filter as explained in this gist by Charl P. Botha.

<!DOCTYPE html>
<meta charset="utf-8">

.graticule {
  fill: none;
  stroke: #777;
  stroke-opacity: .5;
  stroke-width: .5px;

.land {
  fill: #999;

.boundary {
  fill: none;
  stroke: #fff;
  stroke-width: .5px;

<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script src="http://d3js.org/colorbrewer.v1.min.js"></script>

var width = 600,
    height = 500;

var projection = d3.geo.mercator()
    .scale(5*(width + 1) / 2 / Math.PI)
    .translate([width / 2, height / 2])
    .rotate([-125, -15, 0])

var path = d3.geo.path()

var graticule = d3.geo.graticule();

var svg = d3.select("body").append("svg")
    .attr("width", width)
    .attr("height", height);

var filter = svg.append("defs")
  .attr("id", "drop-shadow")
  .attr("height", "130%");
.attr("in", "SourceAlpha")
.attr("stdDeviation", 5)
.attr("result", "blur");

    .attr("in", "blur")
    .attr("dx", 5)
    .attr("dy", 5)
    .attr("result", "offsetBlur");

var feMerge = filter.append("feMerge");

    .attr("in", "offsetBlur")
    .attr("in", "SourceGraphic");

    .attr("class", "graticule")
    .attr("d", path);
d3.json("/mbostock/raw/4090846/world-50m.json", function(error, world) {
    svg.insert("path", ".graticule")
      .datum(topojson.feature(world, world.objects.land))
      .attr("class", "land")
      .attr("d", path)
      .style("filter", "url(#drop-shadow)");

    svg.insert("path", ".graticule")
      .datum(topojson.mesh(world, world.objects.countries, function(a, b) { return a !== b; }))
      .attr("class", "boundary")
      .attr("d", path);

d3.select(self.frameElement).style("height", height + "px");