无法识别传单上的颜色

时间:2014-08-31 00:06:17

标签: javascript json leaflet

var non_tfl_lines_JubileetoIlford = L.geoJson(non_tfl_lines_JubileetoIlford, {
     pointToLayer: function(feature, latlng) {
        switch (feature.geometry.type) {
          case 'LineString': return new L.polyline(latlng, {
            color: feature.properties.color
          });
          case 'Point':   return new L.Circle(latlng, 400, {
            color: getColor(feature.properties.relief_JtI)});
        }
        onEachFeature: popup
     }
}).addTo(map);

由于某种原因,折线的颜色是默认颜色,而不是指定的颜色。同时它给了我正确的圆圈颜色。知道什么可能是错的吗?

1 个答案:

答案 0 :(得分:0)

正如您在documentation中看到的那样, pointToLayer 回调是针对GeoJSON点的;这就是为什么你的代码适用于点。

如果您想使用geojson结构中的信息设置颜色,最好是拥有颜色属性......

   {
      "type": "Feature",
      "properties": {
          "color": "#ff7800"
      },
      "geometry": {
        "type": "LineString",
        "coordinates": [

并在样式回调

中使用它
L.geoJson(non_tfl_lines_JubileetoIlford, {
    style: function(feature) {
        if(feature.geometry.type == "LineString") {
           return {
                   "color": feature.properties.color,
                   "weight": 5,
                   "opacity": 0.65
               };
        }
    }

以下是http://jsfiddle.net/FranceImage/myxd1ooy/

的示例
相关问题