mapbox / leaflet-omnivore

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

Style imported paths. #46

Closed pixelmultiplo closed 10 years ago

pixelmultiplo commented 10 years ago

I'm trying to import multiple kml files and style them. That is my code as now:

  var comuni = new Array();
  for (var i = nearby.comuni.length - 1; i >= 0; i--) {
    var c = nearby.comuni[i].colore;
    comune = omnivore.kml(nearby.comuni[i].kml);
    comune.setStyle({color: c});
    comuni.push(comune);
  };
  var comuniLayer = L.layerGroup(comuni);

All variables are instanced correctly, the kmls are converted and successfully added to the map, but the fill and stroke colors are always the default blue. The "c" var contains an hex color code. What am I missing?

tmcw commented 10 years ago

Would need a working example in jsFiddle or similar complete with the data to be able to debug this.

pixelmultiplo commented 10 years ago

Thank you for the help.

http://jsfiddle.net/oxdnpzcr/

tmcw commented 10 years ago

See http://jsfiddle.net/oxdnpzcr/3/ - setStyle is a sync function, loading data is async.

pixelmultiplo commented 10 years ago

Oh, I see! Thank you!