mapbox / leaflet-omnivore

universal format parser for Leaflet & Mapbox.js
https://www.mapbox.com/mapbox.js/example/v1.0.0/omnivore-gpx/
Other
650 stars 126 forks source link

topojson styling? #21

Closed cappelaere closed 10 years ago

cappelaere commented 10 years ago

topojsonload does not seem to read styling options that could be passed for each feature. How could this be achieved? Thanks. Pat.

tmcw commented 10 years ago

This uses L.geoJson, a class that has no built-in data style constructs. Possibility of using L.mapbox.featureLayer is in #1, otherwise, the trick is to wait for .on('ready' and then apply your custom styles.

cappelaere commented 10 years ago

Actually, I think this could be fixed in the code leaflet-omnivore.js:36 change to: var layer = L.geoJson(null, options); This would allow the passing of options such as onEachFeature...that could then be used for styling. Thank you for your great work. Pat.

jdgodchaux commented 10 years ago

A related question for you Tom: I want to create 4 different layers with different styling from the same topojson with multiple properties. Is there a way to do this using leaflet-omnivore? Right now I'm loading each one seperately, but this seems wasteful:

var MAP1 = omnivore.topojson(topojsonURL, null, MAP1_style);
var MAP2 = omnivore.topojson(topojsonURL, null, MAP2_style);
var MAP3 = omnivore.topojson(topojsonURL, null, MAP3_style);
var MAP4 = omnivore.topojson(topojsonURL, null, MAP4_style);

Thanks for a great tool!

tmcw commented 10 years ago

Right now I'm loading each one seperately, but this seems wasteful:

If you want to just request this once, you can use jQuery for the ajax and topojson.parse. Otherwise, if your server is properly configured this should cache the first response.

jdgodchaux commented 10 years ago

I see. Makes sense. Thanks for your response!