【发布时间】:2017-11-15 20:08:17
【问题描述】:
我正在使用Bostock's Quantile Choropleth 的变体。
我已经成功地缩放了投影并整合了我自己的数据。我目前也在过滤 json 县数据以仅包含以州 id 48 开头的县 id。
这一切都很完美,但是,我仍然需要应用 .mesh 函数来组合边界县之间的弧线。否则,当我添加悬停效果时,我会得到奇怪的不均匀边框。
我尝试用 datum(mesh) 调用替换数据调用(请参阅下面注释掉的行),但它不起作用。
这是我的工作代码:
function ready(error, us) {
if (error) throw error;
//define the feature of the states from the topojson file, then filter so only state 48 (texas) shows
var states = topojson.feature(us, us.objects.states),
state = states.features.filter(function(d) { return d.id === 48; })[0];
//define the features for the counties and filter based on number (starting with 48)
var counties = topojson.feature(us, us.objects.counties),
mycounties = counties.features.filter(function(d) { if(d.id >= 48000 && d.id <=49000) return d.id; });
//initiate the class for the state, and add an outline path
svg.append("path")
.datum(state)
.attr("class", "outline")
.attr("d", path);
//initiate the g object for the counties
svg.append("g")
.attr("class", "counties")
.selectAll("path")
//.datum(topojson.mesh(us, us.objects.counties, function(a, b) { return a !== b; }))
// ^I tried adding this to replace the following line, but it does not work
.data(mycounties)
.enter().append("path")
.attr("fill", function(d) { return color(d.establishments = centralTexas.get(d.id)); })
.attr("d", path)
.append("title")
.text(function(d) { var obj2 = jsonCounties[d.id]; if (typeof obj2 != "undefined") {return obj2.countyName + ": " + d.establishments + " Active Establishments";} });
}
我该怎么办?是否可以在 .mesh 函数中进行更复杂的过滤器查询并完全消除对我的
的需要var counties = topojson.feature(us, us.objects.counties), mycounties =counties.features.filter(function(d) { if(d.id >= 48000 && d.id
代码?
或者我是否需要使用不同的语法对该变量运行网格函数?
【问题讨论】:
标签: javascript d3.js geojson