block by bricedev 8820cc012f2b8309523c

US Road Map II

Full Screen

US Road Map (data from natural earth).

index.html

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

body {
  font: 10px sans-serif;
}

.roads {
  fill: none;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.major-highway { stroke: #525252; stroke-width: 1.5px; }
.secondary-highway { stroke: #737373; }
.road { stroke: #bdbdbd; }
.beltway { stroke: #737373; }
.ferry-route { stroke: #4393c3; stroke-width: 1.5px; }

</style>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/topojson/1.6.19/topojson.min.js"></script>
<script>

var width = 960,
    height = 600;

var projection = d3.geo.albersUsa()
    .scale(1100)
    .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);


d3.json("usroads.json", function(error, usroads) {
  if (error) throw error;

  svg.append("g")
    .selectAll("path")
      .data(topojson.feature(usroads, usroads.objects.usa).features)
    .enter().append("path")
      .attr("d", path)
      .style("fill","none")
      .style("stroke","#252525")
      .style("stroke-width",1);

  svg.append("g")
    .selectAll("path")
      .data(topojson.feature(usroads, usroads.objects.roads).features)
    .enter().append("path")
      .attr("d", path)
      .attr("class",function(d) { return "roads " + d.properties.type.toLowerCase().split(' ').join('-'); });

  var places = svg.append("g");

  places.selectAll("path")
      .data(topojson.feature(usroads, usroads.objects.places).features)
    .enter().append("path")
      .attr("d", path.pointRadius(4.5))
      .style("fill","#252525")
      .style("stroke","#fff")
      .style("stroke-width",1);

  places.selectAll("text")
      .data(topojson.feature(usroads, usroads.objects.places).features)
    .enter().append("text")
      .attr("transform", function(d) { return "translate(" + projection(d.geometry.coordinates) + ")"; })
      .attr("dy", ".35em")
      .attr("dx", ".35em")
      .style("font-size","15px")
      .style("font-weight","bold")
      .style("text-shadow", "0px 0px 2px #fff")
      .text(function(d) { return d.properties.name; });

});

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

</script>

makefile.md

ogr2ogr \
  -f GeoJSON \
  -where "ADM0_A3 IN ('USA')" \
  usa.json \
  ne_10m_admin_0_countries.shp

ogr2ogr \
  -f GeoJSON \
  -where "sov_a3 IN ('USA')" \
  roads.json \
  ne_10m_roads.shp

ogr2ogr \
  -f GeoJSON \
  -where "ADM0_A3 = 'USA' AND SCALERANK < 3" \
  places.json \
  ne_10m_populated_places.shp

topojson \
  -o usroads.json \
  --id-property sov_a3 \
  --properties type \
  --properties name \
  -- \
  usa.json \
  roads.json \
  places.json