javascript - Leaflet Omnivore KML, style imported paths - Stack Overflow

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

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

  var uni = new Array();
  for (var i = nearbyuni.length - 1; i >= 0; i--) {
    var c = nearbyuni[i].colore;
    une = omnivore.kml(nearbyuni[i].kml);
    une.setStyle({color: c});
    uni.push(une);
  };
  var uniLayer = L.layerGroup(uni);

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?

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

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

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?

Share Improve this question asked Oct 9, 2014 at 9:43 Marek MaurizioMarek Maurizio 1,0782 gold badges11 silver badges22 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

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

The setStyle code had to be called synchrounsly like this:

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

Full example on fiddle: http://jsfiddle/oxdnpzcr/3/

//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);
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745305830a4621703.html

相关推荐

  • javascript - Leaflet Omnivore KML, style imported paths - Stack Overflow

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

    1小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信