# topojson.feature(topology, object)
Returns the GeoJSON Feature or FeatureCollection for the specified object in the given topology. If the specified object is a GeometryCollection, a FeatureCollection is returned, and each geometry in the collection is mapped to a Feature. Otherwise, a Feature is returned.
Some examples:
A point is mapped to a feature with a geometry object of type “Point”.
Likewise for line strings, polygons, and other simple geometries.
A null geometry object (of type null in TopoJSON) is mapped to a feature with a null geometry object.
A geometry collection of points is mapped to a feature collection of features, each with a point geometry.
A geometry collection of geometry collections is mapped to a feature collection of features, each with a geometry collection.
This means no more duck-typing for GeometryCollection conversion. This also fixes a 'bug' such that GeometryCollections will retain their ids (the real reason I'm here right now). I've been a bit unsatisfied with the ambiguity of GeometryCollection conversion -- so I figure that, while the conversion still seems a bit ambiguous, at least its consistent with that of Topojson.
There's another minor functional difference -- properties are no longer copied, meaning they are modified with the layer property. I figure this isn't such a huge deal; this is an internal function and we know (?) that no one has seen the object since the time JSON.parse was invoked.
By the way, I've tested this with the developer console, which is now using this version (we're using feature ids for interactivity, so it's good to have them on GeometryCollections.)
EDIT: The first commit can be considered a false start before defaulting more to Topojson's functionality.
This aligns our converter more with the
topojson.feature()
method.From the topojson docs
This means no more duck-typing for
GeometryCollection
conversion. This also fixes a 'bug' such thatGeometryCollection
s will retain their ids (the real reason I'm here right now). I've been a bit unsatisfied with the ambiguity ofGeometryCollection
conversion -- so I figure that, while the conversion still seems a bit ambiguous, at least its consistent with that ofTopojson
.There's another minor functional difference -- properties are no longer copied, meaning they are modified with the
layer
property. I figure this isn't such a huge deal; this is an internal function and we know (?) that no one has seen the object since the timeJSON.parse
was invoked.By the way, I've tested this with the developer console, which is now using this version (we're using feature ids for interactivity, so it's good to have them on
GeometryCollection
s.)EDIT: The first commit can be considered a false start before defaulting more to
Topojson
's functionality.