Omnivore KML Flyer, Imported Paths Style

I am trying to import multiple kml files and style them. This is my code as it is 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 displayed correctly, kmls are converted and added to the map successfully, but the fill and stroke colors are always blue by default. "C" var contains the hexadecimal color code. What am I missing?

+3


source to share


2 answers


I was kindly helped on github https://github.com/tmcw

The setStyle code had to be called synchronously like this:



comune.on('ready', function() {
        this.setStyle({color: "#FF0000"});
    });

      

Full script example: http://jsfiddle.net/oxdnpzcr/3/

+5


source


//using leaflet
function intialthree(file)
{
    var highlightStyle1 = {
      fillColor: "00FFFFFF",
      weight: 1,
      opacity: 1,
      color: "#000000",
      fillOpacity:0.0
    };

    city = new L.KML("IndiaKML/"+file, {async: true });

    city.on("loaded", function(e) {
      this.setStyle(highlightStyle1);
      map.fitBounds(e.target.getBounds());
    });

    map.addLayer(city);
}

      



0


source







All Articles