我在使用topojson绘制委内瑞拉时遇到了问题。我从: GeoJson获得委内瑞拉的http://code.highcharts.com/mapdata/countries/ve/ve-all.geo.json数据
之后,我尝试使用topojson控制台实用程序并将其导入到这个站点:http://www.mapshaper.org/并将其导出为topojson。我还没能把地图渲染出来。这是我的密码:
<!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>我不确定问题是从geojson转换到topojson还是其他什么的。
非常感谢,
里卡多
发布于 2015-07-16 06:18:41
首先,您应该在添加以下层之前声明一个路径、和投影:
var projection = d3.geo.mercator().translate([0, 0]).scale(8400000);
var path = d3.geo.path().projection(projection);这使得它在导入层时更加干净。在那之后,你只需要这样称呼:
var featureCollection = topojson.feature(currentMap, currentMap.objects.poly_bg);
g.append("g")
.selectAll("path")
.data(featureCollection.features)
.enter().append("path")
.attr("d", path);https://stackoverflow.com/questions/27625122
复制相似问题