1
我使用mapshapers成功地将英国地图shapefile转换为geojson。但是我无法在d3.js中加载这个geojson。请帮忙。脚本如下。如何在d3中加载geojson文件的geometryCollection
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var canvas = d3.select("body").append("svg")
.attr("width", 760)
.attr("height", 700)
d3.json("Areas_uk_geo.json", function (data) {
var group = canvas.selectAll("g")
.data(data.geometries)
.enter()
.append("g");
var projection = d3.geo.mercator();
var path = d3.geo.path.projection(projection);
var areas = group.append("path")
.attr("d", path)
.attr("class", "area");
});
</script>
geojson文件具有geometryCollection而不是featureCollection。 geojson文件的格式如下。
{
"type" : "GeometryCollection",
"geometries" : [{
"type" : "MultiPolygon",
"coordinates" : [[[[-2.2241804372470533, 56.88745481725907],
....},...等等。
我正的错误是“d3.geo.path.projection不是一个函数”
我认为应该是d3.geo.path()。projection(projection); – 2014-12-19 10:44:24
@VincentBeltman感谢您的纠正。 – CoffeeSipper 2015-04-24 09:48:51