Git Product home page Git Product logo

Comments (2)

sfairgrieve avatar sfairgrieve commented on May 18, 2024 1

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.

sfairgrieve avatar sfairgrieve commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.