Using Leaflet with GeoJSON, I would like to create a map with geometries, and with alphanumerical data associated to each item of the geometry. A map very similar to the easy sample at http://leafletjs.com/examples/geojson.html, with the names/values of each one the points/lines/polygons.
However, I found that, in every example I've seen, the alphanumerical data ('properties') and the geometrical data ('geometry') are within the same GeoJSON file. I mean, for each one of the items ('Features'), there are 'properties' and 'geometry' associated with the same 'id'.
I wondered if there was any possibility to separate 'properties' and 'geometry' in two different files, joining the features through their ID.
Best Answer
Thomas B and geogeek have the right idea. Here is a fiddle that takes the Leaflet sample data (which I split up into separate objects for geometry and properties), re-joins them, and displays them on a map:
http://jsfiddle.net/nathansnider/6askexjq/
The two important functions are this one (grabbed from this stackoverflow answer), to extract objects based on a key name and value:
and this one, to join the separate objects into a functioning GeoJSON Feature Collection:
For the input geometry, it works with GeoJSON Features, Feature Collections and Geometry Collections, but adapting it for objects in other formats would not be too difficult.