Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The 1.0.0 major release (see <a href="https://github.com/mbostock/topojson/releases/v1.0.0" rel="noreferrer">release notes</a>) replaced the topojson.object function with topojson.feature for better GeoJSON compatibility.</p> <p>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 <a href="https://github.com/mbostock/topojson/wiki/Specification" rel="noreferrer">Topology</a>. 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.</p> <p>As of version 1.0.0, <a href="https://github.com/mbostock/topojson/wiki/API-Reference#wiki-feature" rel="noreferrer">topojson.feature</a> 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 <a href="https://github.com/mbostock/topojson/issues/37" rel="noreferrer">#37</a>, this offers greater compatibility with the <a href="http://geojson.org/geojson-spec.html" rel="noreferrer">GeoJSON specification</a> and libraries that deal with GeoJSON.</p> <p>To upgrade your code, you can replace topojson.object with topojson.feature. However, <strong>code that assumed that topojson.object returned a geometry must be changed to handle the feature (or feature collection)</strong> now returned by topojson.feature. For example, prior to 1.0, if you said:</p> <pre><code>svg.selectAll("path") .data(topojson.object(topology, topology.objects.states).geometries) .enter().append("path") .attr("d", path); </code></pre> <p>In 1.0 and later, the corresponding code is:</p> <pre><code>svg.selectAll("path") .data(topojson.feature(topology, topology.objects.states).features) .enter().append("path") .attr("d", path); </code></pre> <p>Likewise, if you were iterating over an array of point geometries, prior to 1.0, you might have said:</p> <pre><code>topojson.object(topology, topology.objects.points).geometries.forEach(function(point) { console.log("x, y", point.coordinates[0], point.coordinates[1]); }); </code></pre> <p>In 1.0 and later, the corresponding code is:</p> <pre><code>topojson.feature(topology, topology.objects.points).features.forEach(function(point) { console.log("x, y", point.geometry.coordinates[0], point.geometry.coordinates[1]); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload