I was inspired by the wonderful series of D3 maps displayed here from maptimelex. I am trying to replicate it, but using a map of the country of Haiti instead of the state of Kentucky.
Please see my JSFiddle here.
I am using a JSON file with the simple borders of Haiti. It doesn't include any administrative boundaries (departments, communes, etc.). The map doesn't seem to render properly and I am not sure what the problem is.
I get errors suggesting that the JSON file is not loading or rendering properly. One error says: "XMLHttpRequest cannot load: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource." Another error says: "Uncaught TypeError: Cannot read property 'coordinates' of null".
Here is my JavaScript code:
// 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://gist.github.com/29a1f4a91c1c8d615595.git", 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);
});