index.html
<!DOCTYPE html>
<html>
<head>
<title>Pipeline test</title>
<meta charset="UTF-8">
<meta name="description" content="" />
<meta name="keywords" content="" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js" charset="utf-8"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/topojson/1.6.19/topojson.min.js"></script>
<link rel="stylesheet" href="//cdn.leafletjs.com/leaflet-0.7.5/leaflet.css" />
<script src="//cdn.leafletjs.com/leaflet-0.7.5/leaflet.js"></script>
<script type="text/javascript" src="//maps.stamen.com/js/tile.stamen.js?v1.3.0"></script>
<style>
#map {
width: 960px;
height: 500px;
}
svg {
position: relative;
}
.pipes {
stroke-width: 2;
fill: none;
stroke-linejoin: "round";
}
.hp {
stroke: #f03b20;
}
.t {
stroke: #d9b410;
}
.streets {
stroke-width: 1;
stroke: #cbcbca;
stroke-linejoin: "round";
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var undermap = new L.StamenTileLayer("toner-lite");
var map = new L.Map("map", { center: [34.05, -118.25], zoom: 10 })
.addLayer(undermap);
var svg = d3.select(map.getPanes().overlayPane).append("svg"),
g = svg.append("g").attr("class", "leaflet-zoom-hide");
d3.json("pipeline_hp.json", function(error, collection) {
if (error) throw error;
var transform = d3.geo.transform({point: projectPoint}),
path = d3.geo.path().projection(transform);
var feature = g.selectAll("path")
.data(collection.features)
.enter().append("path")
.attr("class", "pipes hp")
map.on("viewreset", reset);
reset();
function reset() {
var bounds = path.bounds(collection),
topLeft = bounds[0],
bottomRight = bounds[1];
svg.attr("width", bottomRight[0] - topLeft[0])
.attr("height", bottomRight[1] - topLeft[0])
.style("left", topLeft[0] + "px")
.style("top", topLeft[1] + "px");
g.attr("transform", "translate(" + -topLeft[0] + "," + -topLeft[1] + ")");
feature.attr("d", path);
}
function projectPoint(x, y){
var point = map.latLngToLayerPoint(new L.LatLng(y, x));
this.stream.point(point.x, point.y);
}
})
</script>
</body>
</html>