2014-08-31 82 views
1
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); 

出於某種原因,折線的顏色是默認的顏色,而不是指定的顏色。在同一時間,它給了我正確的圓圈顏色。任何想法可能是錯的?無法識別的傳單

回答

0

正如您在documentation,中看到的,指向圖層的回調函數爲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/

+0

仍然有問題。我已經發布了它作爲答案,因爲它需要很長時間才能發表評論。所有圖層(包括點)都會調用 – Bla 2014-08-31 21:22:59

+0

風格。您只能返回LineString的樣式(請參閱更新後的答案)。 – YaFred 2014-08-31 21:50:42

+0

新的貼子怎麼樣? – Bla 2014-08-31 22:16:22