如何根据属性设置geojson的样式

时间:2020-08-03 17:05:41

标签: python leaflet geojson

我有一个geojson文件,我试图根据那里的属性为数据着色。我的数据类型是MultiPolygon。

但是,我在第2行得到了一个无效的语法,该语法为“ style:function(feature){”

  L.geoJSON(gjson,{
  style: function(feature){
    switch (feature.properties.Traveltime) {
        case '10800': return {color: "#ff0000"};
        case '1800': return {color: "#0000ff"};
        case '3600': return {color: "#0000ff"};
        case '5400': return {color: "#ff0000"};
        case '7200': return {color: "#ff0000"};
    }
}   

}).addTo(map_Baseline);

有什么想法吗?谢谢

1 个答案:

答案 0 :(得分:0)

我会尝试以下方法:

  1. 以标准样式加载geoJSON

  2. 创建一个要在之后调用的函数,看起来像这样

     function propertyDependentStyle(feature){
         switch (feature.properties.Traveltime) {
             case '10800': gjson.setStyle({color: "#ff0000"});
             case '1800': gjson.setStyle({color: "#0000ff"});
             case '3600': gjson.setStyle({color: "#0000ff"});
             case '5400': gjson.setStyle({color: "#ff0000"});
             case '7200': gjson.setStyle({color: "#ff0000"});
         }
    

    }

这只是我的脑袋,没有经过真正的测试,因此您可能仍需要进行一些修补或调试。

相关问题