rveciana - d3-trail-layout-using-coordinates

D3 Trail Layout using coordinates

Open raw page in new tab

This an example using the D3 trail layout made by Benjamin Schmidt. The example shows how to use the coordinates as the coordType value. The track.json data represents the Hayian typhoon track, as it’s explained in this blog entry.

There is a blog entry explaining this example at GeoExamples

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

<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="pathlayout.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()

d3.json("track.json", function(error, track) {

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

    var trail = d3.layout.trail()
        .positioner(function(d) {return [d.lon,d.lat];})

    var trail_layout = trail.data(track).layout();

    paths = svg.selectAll("line").data(trail_layout);

    .attr("d", path);