1.0.0主要版本(请参阅发行说明)将topojson.object函数替换为topojson.feature以获得更好的GeoJSON兼容性.
在早期版本的TopoJSON中,topojson.object返回了一个几何对象(可能是几何集合),与几何对象在TopoJSON 拓扑中的表示方式一致.但是,与GeoJSON几何体不同,TopoJSON几何体更像是特征,并且可以具有id和属性; 同样,null几何被表示为null类型.
从版本1.0.0开始,topojson.feature替换topojson.object,返回一个Feature或一个FeatureCollection,与转换为TopoJSON之前几何体最初在GeoJSON中的表示方式一致.(与在GeoJSON中一样,null几何被表示为具有null几何对象的要素.)如#37中所讨论的,这提供了与GeoJSON规范和处理GeoJSON的库的更大兼容性.
要升级代码,可以使用topojson.feature替换topojson.object.但是,必须更改假定topojson.object返回几何的代码,以处理 topojson.feature现在返回的要素(或要素集合).例如,在1.0之前,如果你说:
svg.selectAll("path")
.data(topojson.object(topology, topology.objects.states).geometries)
.enter().append("path")
.attr("d", path);
Run Code Online (Sandbox Code Playgroud)
在1.0及更高版本中,相应的代码是:
svg.selectAll("path")
.data(topojson.feature(topology, topology.objects.states).features)
.enter().append("path")
.attr("d", path);
Run Code Online (Sandbox Code Playgroud)
同样,如果你在1.0之前迭代一个点几何数组,你可能会说:
topojson.object(topology, topology.objects.points).geometries.forEach(function(point) {
console.log("x, y", point.coordinates[0], point.coordinates[1]);
});
Run Code Online (Sandbox Code Playgroud)
在1.0及更高版本中,相应的代码是:
topojson.feature(topology, topology.objects.points).features.forEach(function(point) {
console.log("x, y", point.geometry.coordinates[0], point.geometry.coordinates[1]);
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1773 次 |
最近记录: |