I\'m working with leaflet.js and pulling data from a CSV file via omnivore. I am able to make individual layers for each of the features I am \"filtering\" on from the CSV. Asid
EDIT
If I understand correctly, you have HTML inputs (radios / checkboxes) with associated String
values, that incidentally correspond to the name of your L.geoJSON
layer groups variables.
Then you do not know how to correctly call omnivore, given only this String
value?
You have several ways to associate the actual Layer Groups to your inputs, so that you can pass them to omnivore (which, once again, needs a Leaflet GeoJSON Layer Group as 3rd parameter, not an Object
).
For example, you could use jQuery's data to associate directly the Layer Group to each input. It accepts any kind of objects, not just String
's.
Another simple solution would be to use a hash map / dictionary object that holds the bijective association between your String
input value and your Layer Group:
var strValueToLayerGroup = {
"trailheadLayer": trailheadLayer
// more as appropriate
};
selectedLayer("sbnf", strValueToLayerGroup["trailheadLayer"]);
Original answer
As for your console error, it comes from the fact that you provide a String
("trailheadLayer"
) as omnivore.csv()
3rd argument, whereas it expects a GeoJSON Layer Group.
So selectedLayer("sbnf", trailheadLayer);
(without quotes around trailheadLayer
) should not trigger that error.
BTW, you could use pointToLayer option on your L.geoJson()
constructor to directly assign the appropriate icon, popup and label, instead of having to go through eachLayer()
afterwards.