Skip to content

Instantly share code, notes, and snippets.

@octaviomtz
Created November 10, 2015 18:14
Show Gist options
  • Save octaviomtz/fd98fd00bd1e6ad31730 to your computer and use it in GitHub Desktop.
Save octaviomtz/fd98fd00bd1e6ad31730 to your computer and use it in GitHub Desktop.
map of México
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Howework 1 | Octavio</title>
<script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script>
<script src="script.js"></script>
<style type="text/css">
body {
margin: 0;
background-color: #bbbbbb;
font-family: Helvetica, Arial, sans-serif;
}
#container {
width: 800px;
margin-left: auto;
margin-right: auto;
margin-top: 50px;
padding: 50px;
background-color: #ffffff;
box-shadow: 3px 3px 5px 6px #000;
}
#title {
width: 800px;
margin-left: auto;
margin-right: auto;
}
#someText {
width: 800px;
margin-left: auto;
margin-right: auto;
font-family: Helvetica, Arial, sans-serif;
}
</style>
</head>
<body>
<h1 id="title">Map of México </h1>
<div id="container"></div>
<div id="someText">
<p>The .shp file was obtained from <a href="http://www.numeroslocos.com/2013/07/10/shapefile/">here</a> and converted in mapshaper.org
</p>
</div>
<script src="script.js"></script>
</body>
</html>
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
//Width and height
var w = 500;
var h = 500;
//Define map projection
var projection = d3.geo.mercator()
.center([-86, 5])
.translate([w, h])
.scale([w * 1.8]);
//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("national_estatal.json", function (json) {
//Bind data and create one path per GeoJSON feature
svg.selectAll("path")
.data(json.geometries)
.enter()
.append("path")
.attr("d", path)
.attr("fill", "#1A9112")
.attr("stroke", "#3s92114");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment