Comments (2)
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:
- locationLookup: zipData, (A GeoJSON FeatureCollection representing
polygons/features to be styled - in your case, this could be a
FeatureCollection of county boundaries with FIPS county code property) - locationMode: L.LocationModes.LOOKUP (this tells the DataLayer class
that it needs to lookup the geometry from the object identified in
locationLookup - the codeField property (below) will be used as the index
in the key/value lookup. NOTE: this requires that each GeoJSON feature in
the FeatureCollection has the property with the same name identified in
codeField (e.g. county FIPS code)) - codeField: 'GEOZIP2NL' (this tells the DataLayer class that the input
dataset has a property called GEOZIP2NL that will be used to lookup
associated polygons/features - in your case, this might be a FIPS county
code property) - locationTextField: 'GEOZIP2NL' (this tells the DataLayer that the
value of this property in the locationLookup GeoJSON will be used for
display purposes - in your case, this might be the county name)
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//issues/8
.
from leaflet-dvf.
I just pushed an update that has a US county example (still a work in progress) that might be helpful.
from leaflet-dvf.
Related Issues (20)
- Div not visible inside popup HOT 1
- Change color line HOT 3
- Compatibilty with leaflet1.2.0 HOT 4
- create PieChartDataLayer use Geojson data HOT 3
- Question about React integration with Leaflet 1.2.0 and Leaflet-dvf 0.3.1 HOT 7
- On click on a slice of the pie table should show only the value of that slice, not the values for all the slices HOT 2
- Create 3D pie chart markers HOT 2
- Leaflet 1.2.0 and L.Mixin.Events HOT 4
- PieCharts don't show when using the examples HOT 7
- Flowline using arrays HOT 2
- Create RegularPolygonMarker in featureGroup
- a little mistake about the "_createText" method in the source code HOT 3
- Styling attributes for markers and charts HOT 3
- GeohashLayer leaks layers when being removed
- leaflet version? HOT 2
- flight data arrow becomes a square in ie11 HOT 1
- Compatibility with Leaflet 1.7.0 HOT 1
- how can i add offline map or tile server to it HOT 1
- Demo not working anymore (?) HOT 1
- git protocol dependency - geohash
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from leaflet-dvf.