【发布时间】:2018-01-25 08:07:51
【问题描述】:
我用 D3 制作地图,这是我的代码
d3.json('https://unpkg.com/world-atlas@1/world/110m.json', (error, topology) => {
if (error) throw error;
let width = map.offsetWidth,
height = map.offsetHeight;
let projection = d3.geoMercator().scale('200').translate([width / 2, height / 1.4]);
let canvas = d3.select('.map').append('canvas')
.attr('width', width)
.attr('height', height);
let context = canvas.node().getContext('2d'),
path = d3.geoPath()
.context(context)
.projection(projection);
context.fillStyle = '#d8d8d8';
context.strokeStyle = 'black';
context.beginPath();
path(topojson.mesh(topology));
context.fill();
context.stroke()
});
有一些白色但应该是灰色的。 我不知道发生了什么,如果使用 svg 效果很好,但在这种情况下,我想使用画布。 谢谢。
【问题讨论】:
标签: javascript d3.js topojson