(function() {
function loadMap() {
var projection = d3.geo.mercator();
var path = d3.geo.path().projection(projection);
var tooltip = document.getElementById('tooltip');
var initialScale = 3.5;
var initialPosition = [-100, -175];
var zoom = d3.behavior.zoom()
.scaleExtent([1, 20])
.scale(initialScale).translate(initialPosition)
.on("zoom", function() {
setZoom(d3.event.translate, d3.event.scale);
});
function setZoom(translate, scale) {
container.attr("transform", "translate(" + translate + ") scale(" + scale + ")").attr('data-scale', scale);
}
var container = d3.select('#map').call(zoom).insert('g', ':first-child').attr('class', 'map');
setZoom(initialPosition, initialScale);
container.append("path")
.datum(d3.geo.graticule())
.attr("class", "graticule")
.attr("d", path);
d3.selection.prototype.moveToFront = function() {
return this.each(function(){
this.parentNode.appendChild(this);
});
};
d3.json(document.getElementById('map').getAttribute('data-src'), function(error, world) {
if (error) {
throw error;
}
container.selectAll('path')
.data(topojson.feature(world, world.objects.countries).features)
.enter()
.append('path')
.attr('d', path)
.attr('class', 'country');
var year = (new Date()).getFullYear();
var conferences = document.querySelectorAll('#conferences .conference');
var conference_path = []
for (var i = 0; i < conferences.length; i++) {
var d = conferences[i];
if (d.getAttribute('data-t') === 'annual') {
var coords = projection([d.getAttribute('data-o'), d.getAttribute('data-a')]);
if (conference_path.length) {
conference_path[conference_path.length - 1].x2 = coords[0];
conference_path[conference_path.length - 1].y2 = coords[1];
}
conference_path.push({
x1: coords[0],
y1: coords[1]
});
}
}
container.append('defs').html('