我在d3地图上使用了模糊效果,如下所示:http://geoexamples.blogspot.in/2014/01/d3-map-styling-tutorial-ii-giving-style.html?d3地图 - 使用模糊滤镜后,变焦无法正常工作
但使用此方法后(由于数据如何加载..使用数据)我的缩放功能行为随机。无论我点击它放大到相同的点。另外,使用过滤器后,动画变得非常慢。
有没有其他的方法来实现模糊?或者解决这个问题?
任何帮助?
谢谢。 这是用于在需要过滤的情况下创建世界的代码(根据上述网站上的代码使用数据)。
d3.json("world-110m2.json", function(error, world) {
g.insert("path")
.datum(topojson.feature(world, world.objects.land))
.attr("d", path);
g.insert("path")
.datum(topojson.mesh(world, world.objects.countries, function(a, b) { return a !== b; }))
.attr("d", path)
.append("path");
g.selectAll("path")
.on("click", click);})
这是万一过滤中使用的代码是不需要(不使用数据的 - 也许是数据导致了问题)
d3.json("world-110m2.json", function(error,topology) {
g.selectAll("path")
.data(topojson.object(topology, topology.objects.countries)
.geometries)
.enter()
.append("path")
.attr("d",path)
.on("click", click);)}
这是变焦功能:从这里得到的代码:http://bl.ocks.org/mbostock/2206590
function click(d) {
var x, y, k;
var centered;
if (d && centered !== d) {
var centroid = path.centroid(d);
x = centroid[0];
y = centroid[1];
k = 4;
centered = d;
} else {
x = width/2;
y = height/2;
k = 1;
centered = null;
}
if (active === d) return reset();
g.selectAll(".active").classed("active", false);
d3.select(this).classed("active", active = d);
var b = path.bounds(d);
g.selectAll("path")
.classed("active", centered && function(d) { return d === centered; });
g.transition()
.duration(750)
.attr("transform", "translate(" + width/2 + "," + height/2 + ")scale(" + k + ")translate(" + -x + "," + -y + ")")
.style("stroke-width", 1.5/k + "px");
}
你能发布你的完整代码吗?没有理由放大行为应该与过滤器行为不同。 –
我更新了代码。当需要过滤时,需要使用基准面。即使当我不应用过滤器,缩放不能正常工作。它以某种方式与我如何使用数据相关。 – user2426035
你已经发布了两件做同样事情的代码,但没有告诉我们它们在哪个环境下使用。查看缩放功能也很有帮助。 –