I make a map with D3, it's my code
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()
});
and get wrong canvas
There are some white but should be gray.
I have no idea what happened, if use svg it works perfectly, but in this case, I want to use canvas.
Thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…