jubjub
jubjub

Reputation: 107

Understanding .features method of topojson

I'm still pretty new to D3 and I'm working through a few online examples to develop a better understanding.

Looking at this example, I'm having a hard time figuring out the code on line 33 of the index file is doing:

.data(topojson.feature(us, us.objects.counties).features)

If I have this right, I believe topojson.feature() converts the topojson file into geojson and accepts arguments for the data (us) and the object of interest (counties)...?

But what does the last method, .features do?

Upvotes: 1

Views: 2656

Answers (1)

Gerardo Furtado
Gerardo Furtado

Reputation: 102218

.features is not a method, that's just a property of the GeoJSON object. It is created by topojson.feature (which, by the way, is a real method).

According to the GeoJSON specs,

2.3. Feature Collection Objects

A GeoJSON object with the type "FeatureCollection" is a feature collection object.

An object of type "FeatureCollection" must have a member with the name "features". The value corresponding to "features" is an array. Each element in the array is a feature object as defined above.

Upvotes: 2

Related Questions