D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
lee00678
Full window
Github gist
US State Geo Map
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>US State projection</title> <script type="text/javascript" src="https://d3js.org/d3.v3.js"></script> <style type="text/css"> body { background-color: white; } h1 { font-family: sans-serif; font-size: 20px; padding-left: 30px; padding-top: 0px; } h2 { font-family: sans-serif; font-size: 12px; padding-left: 30px; font-weight: normal; padding-top: 10px; } svg { background-color: white; } #container { width: 800px; margin-left: auto; margin-right: auto; margin-top: 60px; padding: 50px; background-color: white; border: 1px solid #ccc; /*box-shadow: 3px 3px 5px 6px #ccc;*/ } </style> </head> <body> <div id="container"> <h1>Unite States Geo Map</h1> </div> <script type="text/javascript"> //Width and height var w = 500; var h = 300; //Define map projection var projection = d3.geo.albersUsa() .translate([ w/2, h/2 ]) .scale([ 600 ]); //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("usstate.json", function(json) { //Bind data and create one path per GeoJSON feature svg.selectAll("path") .data(json.features) .enter() .append("path") .attr("d", path) .style({fill: "steelblue", stroke: "#eee"}); }); </script> </body> </html>
Modified
http://d3js.org/d3.v3.js
to a secure url
https://d3js.org/d3.v3.js