【发布时间】:2016-05-18 21:47:12
【问题描述】:
尽我所能,我无法在不导致地图明显模糊的情况下渲染 d3.js 县级地图。
我正在使用通常的技巧:我的canvas 样式宽度是我的属性宽度的一半。我将绘图的上下文翻译半个像素以抵消任何不需要的效果。
但它仍然非常模糊。
有人可以分享为canvas 元素制作的清晰 d3.js 地图的模式吗?
function drawQuintiles() {
var width = 960,
height = 500;
var projection = d3.geo.albers()
.scale(666);
var canvas = d3.select("#quintiles")
.append("canvas")
.attr("class",'canvasarea');
var context = canvas.node().getContext("2d");
var ratio = (window.devicePixelRatio / context.webkitBackingStorePixelRatio) || 1;
d3.select('.canvasarea')
.attr("width", width * ratio).attr("height", height * ratio)
.style("width", width + "px").style("height", height + "px");
context.scale(ratio, ratio);
var path = d3.geo.path()
.projection(projection)
.context(context);
d3.json("/data/us-counties.json", function(error, us) {
if (error) throw error;
context.strokeStyle = '#333';
context.beginPath();
var strokeWidth = 0.5;
var iTranslate = (strokeWidth % 2) / 2;
context.translate(iTranslate, 0);
context.lineWidth = strokeWidth;
context.lineCap = "round";
path(topojson.feature(us, us.objects.counties));
context.stroke();
});
}
【问题讨论】:
标签: html dictionary canvas d3.js blurry