Guest User

Untitled

a guest
Nov 17th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. var svg = d3.select("body").append("svg")
  2. .attr("width",width)
  3. .attr("height",height)
  4.  
  5. function createMap(countries, cities) {
  6. var projection = d3.geoMercator()
  7. .scale(scale)
  8. .translate([width/2,height/2])
  9.  
  10. var mapZoom = d3.zoom()
  11. .on("zoom", zoomed)
  12.  
  13. var zoomSettings = d3.zoomIdentity
  14. .translate(width/2, height/2)
  15. .scale(scale)
  16.  
  17. svg.call(mapZoom).call(mapZoom.transform, zoomSettings) // ?!!!
  18.  
  19. function zoomed() {
  20. var e = d3.event
  21. .translate([e.transform.x, e.transform.y])
  22. .scale(e.transform.k)
  23.  
  24. // I didn't include the drawing of the paths, but
  25. they are appended to the SVG, and this updates their data.
  26.  
  27. d3.selectAll("path.graticule").attr("d", geoPath)
  28. d3.selectAll("path.countries").attr("d", geoPath)
  29. d3.selectAll("circle.cities")
  30. .attr("cx", d => projection([d.x,d.y])[0])
  31. .attr("cy", d => projection([d.x,d.y])[1])
  32. }
  33.  
  34. var zoom = d3.zoom()
  35. .scaleExtent([1,3])
  36. .on("zoom", zoomed)
  37.  
  38. function zoomed(){
  39. g.attr("transform", d3.event.transform)
  40. }
  41.  
  42. var svg = d3.select("body").append("svg")
  43. .attr("width",width)
  44. .attr("height",height)
  45. .call(zoom)
  46.  
  47. var g = d3.select("svg").append("g")
  48.  
  49. // All elements are bound to group^
Add Comment
Please, Sign In to add comment