<script src="https://gist.github.com/29a1f4a91c1c8d615595.git"></script>
<!-- this map is inspired by https://github.com/maptimelex/d3-mapping -->
<title>A very simple D3 map of Haiti</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<link href="http://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet" type="text/css">
<body>
<h1>Republic of Haiti</h1>
</body>
// set height and width of viz
var width = window.innerWidth,
height = window.innerHeight;
// create svg for viz
var svg = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", height);
// define JSON map data
d3.json("https://rawgit.com/mattbowlby/29a1f4a91c1c8d615595/raw/9aac80c757f6af814ad425c45e130bec25e68354/haiti.json", function (json) {
// create a first guess for the projection
var center = d3.geo.centroid(json);
var scale = 150;
var offset = [width / 2, height / 2];
var projection = d3.geo.mercator()
.center(center)
.rotate([85.8, 0])
.scale(scale)
.translate(offset);
var geoPath = d3.geo.path()
.projection(projection);
svg.append("g")
.selectAll("path")
.data(json.coordinates)
.enter()
.append("path")
.attr("d", geoPath);
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.