本文介绍了Topojson:v0和v1之间的区别列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我合并代码,代码依赖于V1上的v0中断。



topojson.v0.min.js和topojson.v1.min.js之间的语法变化是什么?*



-



可疑语法列表:




  • V0> V1

  • .object> .feature

  • .geometries> .features(在某些情况下或总是?)

  • *。coordinates> * .geometry.coordinates

  • 其他?


解决方案

1.0.0主要版本(请参阅)用topojson.feature替换了topojson.object函数,以获得更好的GeoJSON兼容性。



在以前版本的TopoJSON中, topojson.object返回几何对象(可能是几何集合),与几何对象在TopoJSON 替换了topojson.object,返回一个Feature或一个FeatureCollection,与GeoJSON中几何最初被表示的方式一致,转换为TopoJSON。 (如GeoJSON中所示,零几何形状表示为具有零几何对象的要素。)如,这提供了与以及处理GeoJSON的库的更大兼容性。 / p>

要升级代码,可以用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);

在1.0及更高版本中,相应的代码为:



$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ b $ ).append(path)
.attr(d,path);

同样,如果您在1.0之前迭代点阵几何数组,您可能会说:

  topojson.object(topology,topology.objects.points).geometries.forEach(function(point){
console.log(x,y,point.coordinates [0],point.coordinates [1]);
});

在1.0及更高版本中,相应的代码为:

  topojson.feature(topology,topology.objects.points).features.forEach(function(point){
console.log(x,y,point .geometry.coordinates [0],point.geometry.coordinates [1]);
});


I'am merging code, the code relying on v0 breaks on v1.

What are the syntaxes changes between topojson.v0.min.js and topojson.v1.min.js?*

--

List of suspect syntaxes:

  • V0 > V1
  • .object > .feature
  • .geometries > .features (in some cases or always?)
  • *.coordinates > *.geometry.coordinates
  • others ?

解决方案

The 1.0.0 major release (see release notes) replaced the topojson.object function with topojson.feature for better GeoJSON compatibility.

In previous versions of TopoJSON, topojson.object returned a geometry object (which may be a geometry collection), consistent with how the geometry object is represented inside the TopoJSON Topology. However, unlike GeoJSON geometries, TopoJSON geometries are more like features, and could have an id and properties; likewise, null geometries were represented as a null type.

As of version 1.0.0, topojson.feature replaces topojson.object, returning a Feature or a FeatureCollection instead, consistent with how the geometry was originally represented in the GeoJSON, prior to conversion to TopoJSON. (As in GeoJSON, null geometries are represented as features with a null geometry object.) As discussed in #37, this offers greater compatibility with the GeoJSON specification and libraries that deal with GeoJSON.

To upgrade your code, you can replace topojson.object with topojson.feature. However, code that assumed that topojson.object returned a geometry must be changed to handle the feature (or feature collection) now returned by topojson.feature. For example, prior to 1.0, if you said:

svg.selectAll("path")
    .data(topojson.object(topology, topology.objects.states).geometries)
  .enter().append("path")
    .attr("d", path);

In 1.0 and later, the corresponding code is:

svg.selectAll("path")
    .data(topojson.feature(topology, topology.objects.states).features)
  .enter().append("path")
    .attr("d", path);

Likewise, if you were iterating over an array of point geometries, prior to 1.0, you might have said:

topojson.object(topology, topology.objects.points).geometries.forEach(function(point) {
  console.log("x, y", point.coordinates[0], point.coordinates[1]);
});

In 1.0 and later, the corresponding code is:

topojson.feature(topology, topology.objects.points).features.forEach(function(point) {
  console.log("x, y", point.geometry.coordinates[0], point.geometry.coordinates[1]);
});

这篇关于Topojson:v0和v1之间的区别列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 01:38