编程语言/地图:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
第124行: 第124行:


==== 等距圆柱投影 ====
==== 等距圆柱投影 ====
图示:
[[文件:等距圆柱投影-1.png|700px|替代=等距圆柱投影-1|等距圆柱投影-1]]
实现:
<syntaxhighlight lang="html5">
<script src="https://d3js.org/d3.v7.min.js"></script>
<script src="https://lib.baomitu.com/topojson/3.0.2/topojson.min.js"></script>
<script>
  const width = 1000;
  const height = 500;
  const svg = d3.select('body')
    .append('svg')
    .attr('width', width)
    .attr('height', height);
  const path = d3.geoPath().projection(
    d3.geoEquirectangular()
      .translate([width / 2, height / 2])
    );
  d3.json('https://gist.githubusercontent.com/whatsthebeef/6361969/raw/2717d4d1635bccd141001ffb1dacccaece7f6d52/world.json').then(function(root) {
    const countries = topojson.feature(root, root.objects.countries);
    const land = topojson.feature(root, root.objects.land);
    svg.append('g').selectAll('path')
      .data(countries.features.concat(land.features))
      .enter()
      .append('path')
      .attr('class', 'country')
      .style('fill', function(d, i) {
        return d3.schemeCategory10[i % 10];
      })
      .attr('d', path);
  });
</script></syntaxhighlight>


==== 等积圆柱投影 ====
==== 等积圆柱投影 ====