var projection = d3.geo.mercator().scale(1).translate([0,0]).precision(0); var path = d3.geo.path().projection(projection); var Map = { svg: undefined, width: 530, height: 500, orig_geo_data: undefined, html_hook: '#country-hook', initSvg: function() { Map.svg = d3.select(Map.html_hook) .append('svg') .attr('width', Map.width) .attr('height', Map.height); }, init: function(geo_data) { Map.initSvg(); var bounds = path.bounds(Map.orig_geo_data); var scale = .95 / Math.max((bounds[1][0] - bounds[0][0]) / Map.width, (bounds[1][1] - bounds[0][1]) / Map.height); var transl = [(Map.width - scale * (bounds[1][0] + bounds[0][0])) / 2, (Map.height - scale * (bounds[1][1] + bounds[0][1])) / 2]; projection.scale(scale).translate(transl); setColorDomain(geo_data); Map.svg.selectAll('path') .data(geo_data) .enter() .append('path') .filter(function(d) { return d.properties.WATER !== 'JA'; }) .attr({ d: path, fill: function(d) { if(d.properties.bevolking2014){ return color(d.properties.bevolking2014); } else { return '#EFEFEF'; } }, stroke: function(d) { return '#FFF' }, class: function(d) { return 'gemeente ' + d.properties.GM_CODE; } }) .on('mouseover', function(d) { Barchart.mouseOver(d); Map.mouseOver(d); Tooltip.set(d); }) .on('mouseout', function(d) { Map.mouseOut(d); Barchart.mouseOut(d); Tooltip.hide(); }) }, mouseOver: function(d) { Map.svg.select('.' + d.properties.GM_CODE) .classed('hover', true); Map.svg.selectAll('.gemeente') .classed('fadeout', true); }, mouseOut: function(d) { Map.svg.select('.' + d.properties.GM_CODE) .classed('hover', false); Map.svg.selectAll('.gemeente') .classed('fadeout', false); } }