Open martinburch opened 11 years ago
Good question. I know the documentation needs some work, and now I know of at least one area where I need to devote some time to documenting.
The basic structure is a JavaScript object key/value lookup. Each key is a code (e.g. county code), and each value is the GeoJSON representing the polygon associated with that code. This makes it efficient to find the polygon or other geometry associated with a given code. If you have GeoJSON you want to use for polygons, there's no need to create your own key/value lookup. There's built in support in L.DataLayer based classes (e.g. L.ChoroplethDataLayer) for this particular use case - where you have GeoJSON representing a set of polygons or other features that you want to map and some input data that has properties that you want to use to style those polygons/features. Check out the Netherlands Population by ZIP 2 example: http://humangeo.github.io/leaflet-dvf/examples/html/nlzip.html.
In this case, the key things to note in the DataLayer options are:
As an alternative to this approach, if you want to create your own custom lookup from a GeoJSON FeatureCollection, there's also the L.GeometryUtils.indexFeatureCollection method that takes a GeoJSON FeatureCollection and a property key as input and returns a key/value lookup of the given property mapped to its associated polygon. This lookup can then be used in a DataLayer with the L.LocationModes.CUSTOM locationMode.
Hope this helps. Does this answer your question? Let me know if you have any additional questions.
On Tuesday, December 3, 2013, Martin Burch wrote:
Is there some documentation available for the structure used by countryData.js and stateData.js?
I would like to use other GeoJSON files, such as U.S. counties or legislative districts, but I'm not sure how the GeoJSON is being transformed, exactly, so I'm having trouble making my own files.
In the docs, I see that
Polygons are indexed via a state or country code and lookups are created to map various state/country code formats to the default index format.
That use of keys seems to create invalid GeoJSON per spec, therefore, it will be difficult to create additional files without a conversion script.
— Reply to this email directly or view it on GitHubhttps://github.com/humangeo/leaflet-dvf/issues/8 .
I just pushed an update that has a US county example (still a work in progress) that might be helpful.
Is there some documentation available for the structure used by countryData.js and stateData.js?
I would like to use other GeoJSON files, such as U.S. counties or legislative districts, but I'm not sure how the GeoJSON is being transformed, exactly, so I'm having trouble making my own files.
In the docs, I see that
That use of keys seems to create invalid GeoJSON per spec, therefore, it will be difficult to create additional files without a conversion script. Is such a script available, by any chance?