D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
uafrazier
Full window
Github gist
D3: Map of Texas
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>D3: Map of Texas</title> <script type="text/javascript" src="https://d3js.org/d3.v3.min.js"></script> <style type="text/css"> @import url(https://fonts.googleapis.com/css?family=Oswald:700,400); body { font-family: oswald, arial, sans-serif; color: #d3d3d3; } #container { width: 900px; margin-left: auto; margin-right: auto; margin-top: 50px; margin-bottom: 50px; padding: 20px 50px; background: #333; box-shadow: 0 0 5px #999999; } #container h1 { text-align: center; } svg { background: #333; } </style> </head> <body> <div id="container"> <h1>The State of Texas</h1> </div> <script type="text/javascript"> //Width and height var w = 900, h = 500; //Define projection var projection = d3.geo.mercator() .center([ -99.43,31.47 ]) .translate([ w/2, h/2 ]) .scale([ 2000 ]); //Define path generator var path = d3.geo.path() .projection(projection); //Create SVG var svg = d3.select("#container") .append("svg") .attr("width", w) .attr("height", h); //Load in GeoJSON data d3.json("texas.json", function(json) { //Bind data and create one path per GeoJSON feature svg.selectAll("path") .data(json.features) .enter() .append("path") .attr("d", path) .attr("fill","#d3d3d3"); }); </script> </body> </html>
Modified
http://d3js.org/d3.v3.min.js
to a secure url
https://d3js.org/d3.v3.min.js