Advertisement
Guest User

Untitled

a guest
May 30th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. var width = 800,
  2. height = 600;
  3.  
  4. var svg = d3.select("#chart").append("svg")
  5. .attr("width", width)
  6. .attr("height", height);
  7.  
  8. var map = svg.append("g").attr("id", "map"),
  9. places = svg.append("g").attr("id", "places");
  10.  
  11. var projection = d3.geo.mercator()
  12. .center([126.9895, 37.5651])
  13. .scale(100000)
  14. .translate([width/2, height/2]);
  15.  
  16. var path = d3.geo.path().projection(projection);
  17.  
  18. d3.json("seoul_mapping.json", function(error, data) {
  19. var features = topojson.feature(data, data.objects.seoul_municipalities_geo).features;
  20. map.selectAll('path')
  21. .data(features)
  22. .enter().append('path')
  23. .attr('class', function(d) { console.log(); return 'municipality c' + d.properties.code })
  24. .attr('d', path);
  25.  
  26. map.selectAll('text')
  27. .data(features)
  28. .enter().append("text")
  29. .attr("transform", function(d) { return "translate(" + path.centroid(d) + ")"; })
  30. .attr("dy", ".35em")
  31. .attr("class", "municipality-label")
  32. .text(function(d) { return d.properties.name; })
  33. });
  34.  
  35. d3.csv("places.csv", function(data) {
  36. places.selectAll("circle")
  37. .data(data)
  38. .enter().append("circle")
  39. .attr("cx", function(d) { return projection([d.lon, d.lat])[0]; })
  40. .attr("cy", function(d) { return projection([d.lon, d.lat])[1]; })
  41. .attr("r", 10);
  42.  
  43. places.selectAll("text")
  44. .data(data)
  45. .enter().append("text")
  46. .attr("x", function(d) { return projection([d.lon, d.lat])[0]; })
  47. .attr("y", function(d) { return projection([d.lon, d.lat])[1] + 8; })
  48. .text(function(d) { return d.name });
  49. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement