【问题标题】:How to render only a part of topojson in d3如何在d3中只渲染topojson的一部分
【发布时间】:2017-04-28 09:57:07
【问题描述】:

我有一个topojsonfile,其中包含印度的所有地区。我只想渲染特定州的地区。我不知道该怎么做。

这是我的初始代码(它呈现所有区域):

    var district_geo_obj = topojson.feature(district, district.objects.india_district);
    var district_projection = d3.geoMercator()
        .fitSize([width/2, width/2], district_geo_obj);
    var district_path = d3.geoPath().projection(district_projection);

    map_svg.selectAll("path")
        .data(district_geo_obj.features)
        .enter().append("path")
        .attr("d", district_path)
        .attr('class', 'map-margin-const')
        .style('fill', function(d) {
            return 'red';
        })

这是topojson文件的截图

【问题讨论】:

    标签: dictionary d3.js topojson


    【解决方案1】:
      var districts = ["aaa", "bbb", "ccc", "ddd"];
    
      map_svg.selectAll("path")
        .data(district_geo_obj.features)
        .enter().append("path")
        .attr("d", district_path)
        .attr('class', 'map-margin-const')
        .style('fill', function(d) {
            return 'red';
        }).style("stroke-width", function (d, i) {
                        if (districts.indexOf(d["properties"]["NAME_1"]) > -1 ) return "1px";   // Not sure about the syntax. But this should do
                        else return "0px";
                    })
    

    【讨论】:

    • 至少要提一下反对人们投票的原因
    猜你喜欢
    • 1970-01-01
    • 2013-09-21
    • 2021-06-11
    • 1970-01-01
    • 1970-01-01
    • 2013-02-12
    • 1970-01-01
    • 2015-05-14
    • 1970-01-01
    相关资源
    最近更新 更多