index.html 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <!DOCTYPE html>
  2. <meta charset="utf-8">
  3. <body>
  4. <div id='js-map-nz-center'></div>
  5. <script src='http://code.jquery.com/jquery-2.0.3.js'></script>
  6. <script src="http://d3js.org/d3.v3.min.js"></script>
  7. <script src="http://d3js.org/topojson.v0.min.js"></script>
  8. <script src="worldtopo.js"></script>
  9. <style>
  10. .background {
  11. fill: #a4bac7;
  12. }
  13. .foreground {
  14. fill: none;
  15. stroke: #333;
  16. stroke-width: 1.5px;
  17. }
  18. .graticule {
  19. fill: none;
  20. stroke: #fff;
  21. stroke-width: .5px;
  22. }
  23. .graticule :nth-child(2n) {
  24. stroke-dasharray: 2,2;
  25. }
  26. .land {
  27. fill: #d7c7ad;
  28. stroke: #766951;
  29. }
  30. .geojson {
  31. fill: none;
  32. stroke: red;
  33. stroke-width: 5;
  34. }
  35. .boundary {
  36. fill: none;
  37. stroke: #a5967e;
  38. }
  39. </style>
  40. <script>
  41. var width = $(window).width(),
  42. height = $(window).height();
  43. var sc = Math.min(width,height) * 0.5
  44. var projection = d3.geo.equirectangular()
  45. .scale(sc)
  46. .translate([width/2,height/2])
  47. .rotate([-180,0])
  48. .precision(100);
  49. var path = d3.geo.path()
  50. .projection(projection);
  51. var graticule = d3.geo.graticule();
  52. var svg = d3.select("#js-map-nz-center").append("svg")
  53. .attr("width", width)
  54. .attr("height", height);
  55. svg.append("path")
  56. .datum(graticule.outline)
  57. .attr("class", "background")
  58. .attr("d", path);
  59. svg.append("g")
  60. .attr("class", "graticule")
  61. .selectAll("path")
  62. .data(graticule.lines)
  63. .enter().append("path")
  64. .attr("d", path);
  65. svg.insert("path", ".graticule")
  66. .datum(topojson.mesh(worldtopo, worldtopo.objects.countries, function(a, b) { return a.id !== b.id; }))
  67. .attr("class", "boundary")
  68. .attr("d", path);
  69. svg.insert("path", ".graticule")
  70. .datum(topojson.object(worldtopo, worldtopo.objects.land))
  71. .attr("class", "land")
  72. .attr("d", path);
  73. </script>