[英]how to load geometryCollection of geojson file in d3
I successfully converted a UK map shapefile to geojson using mapshapers. 我使用mapshapers成功地将英国地图shapefile转换为geojson。 But I am unable to load this geojson in d3.js.
但是我无法在d3.js中加载此geojson。 Please help.
请帮忙。 script is as follows.
脚本如下。
<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>
The geojson file has a geometryCollection instead of featureCollection. geojson文件具有geometryCollection而不是featureCollection。 The geojson file is of the below mentioned format.
geojson文件的格式如下。
{
"type" : "GeometryCollection",
"geometries" : [{
"type" : "MultiPolygon",
"coordinates" : [[[[-2.2241804372470533, 56.88745481725907],
.... }, ... and so on. .... }, ... 等等。
The error I am getting is "d3.geo.path.projection is not a function" 我收到的错误是“ d3.geo.path.projection不是函数”
As mentionned in @vincent-beltman comment, it should be 如@ vincent-beltman评论中所述,应该
d3.geo.path().projection(projection);
You can confirm this with Mike Bostock post "Let's Make a Map" 您可以在Mike Bostock的“让我们做一张地图”中进行确认。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.