Advertisement
Guest User

Untitled

a guest
Jun 30th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1.  
  2. var width = document.getElementById('container').offsetWidth-60;
  3. var height = width/1.5;
  4.  
  5. var zoomBehaviour=d3.behavior.zoom();
  6.  
  7. var projection = d3.geo.mercator()
  8. .scale(230)
  9. .translate([width / 2, height / 2]);
  10.  
  11. var path = d3.geo.path()
  12. .projection(projection);
  13.  
  14. var svg = d3.select("#container").append("svg")
  15. .attr("width", width)
  16. .attr("height", height)
  17. .call(zoomBehaviour.on("zoom", zoom));
  18.  
  19. var g = svg.append("g");
  20.  
  21.  
  22. d3.json("world.json", function(error, map) {
  23. var w = document.getElementById('container').width;
  24. var h =document.getElementById('container').height;
  25.  
  26. function clicked(d){
  27. zoomBehaviour.translate([10,10]);
  28. zoom();
  29. }
  30.  
  31. var country = g.selectAll(".country")
  32. .data(topojson.feature(map,map.objects.subunits).features)
  33. .enter()
  34. .append("path")
  35. .style("fill", "green")
  36. .attr("d", path)
  37. .on("click", clicked);
  38. });
  39.  
  40.  
  41.  
  42. function zoom() {
  43. g.transition()
  44. .duration(500)
  45. .attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale+ ")");
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement