首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >D3.js显示器

D3.js显示器
EN

Stack Overflow用户
提问于 2014-12-23 17:21:49
回答 1查看 1.1K关注 0票数 1

我在使用topojson绘制委内瑞拉时遇到了问题。我从: GeoJson获得委内瑞拉的http://code.highcharts.com/mapdata/countries/ve/ve-all.geo.json数据

之后,我尝试使用topojson控制台实用程序并将其导入到这个站点:http://www.mapshaper.org/并将其导出为topojson。我还没能把地图渲染出来。这是我的密码:

代码语言:javascript
复制
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>

<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script>
    var width = 960,
        height = 1160;

    var svg = d3.select("body").append("svg")
            .attr("width", width)
            .attr("height", height);

    d3.json("venezuela.json", function(error, ve) {
        var path = d3.geo.path();
        svg.append("path")
                .datum(topojson.feature(ve, ve.objects['ve-all.geo']))
                .attr("d", d3.geo.path().projection(d3.geo.mercator()));
    });

</script>

</body>
</html>

和拓扑结构:https://gist.githubusercontent.com/rickitan/665af7cc271baf652a90/raw/ed7341aa5431524083c6a1783eb9d32501357a91/mapShaperOutput

我不确定问题是从geojson转换到topojson还是其他什么的。

非常感谢,

里卡多

EN

回答 1

Stack Overflow用户

发布于 2015-07-16 06:18:41

首先,您应该在添加以下层之前声明一个路径、投影

代码语言:javascript
复制
var projection = d3.geo.mercator().translate([0, 0]).scale(8400000);
var path = d3.geo.path().projection(projection);

这使得它在导入层时更加干净。在那之后,你只需要这样称呼:

代码语言:javascript
复制
var featureCollection = topojson.feature(currentMap, currentMap.objects.poly_bg);
            g.append("g")
                .selectAll("path")
                .data(featureCollection.features)
                .enter().append("path")
                .attr("d", path);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27625122

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档