2015-10-07 28 views
0

我已經使用openlayers繪製了往返程。 的不同點有一個這樣的風格:更改了功能的字體並獲得了「斷言失敗:將從索引中刪除的預期功能」

new ol.style.Style({ 
     image: new ol.style.Circle({ 
      radius: 2, 

      fill: new ol.style.Fill({ 
       color: 'rgba(1,0,0,0)' 
      }) 
     }), 
     text: new ol.style.Text({ 
      font: 'normal 600 12px Calibri, sans-serif', 
      text: feature.get('TEXT'), 
      offsetX: 0, 
      offsetY: +12, 
      fill: new ol.style.Fill({ 
       color: 'rgba(1,0,0,0)' 
      }) 
     }) 
    }) 

我想修改特定事件(出口PNG)的字體,所以對於每一個特徵,我改變字體

for (var i = 0; i < vector_service_port.getSource().getFeatures().length; i++) { 
    vector_service_port.getSource().getFeatures()[i].setStyle(new ol.style.Style({ 
     text: new ol.style.Text({ 
       font: 'normal 600 14px Calibri, sans-serif' 
      }) 
    })); 

} 

但我有錯誤

Uncaught AssertionError: Assertion failed: Expected feature to be removed from index

我該如何繞過?

+0

是否有您所使用的每功能樣式的原因是什麼?在矢量圖層上設置樣式不夠嗎? – tsauerwein

+0

如果可以,讓我們來完成這個問題。 –

回答

0

我會做這樣的事情:

var features = vector_service_port.getSource().getFeatures(); 
features.forEach(function(feature){ 
    feature.getStyle().getText().setFont('your desired font'); 
}); 
+0

getStyle()似乎沒有工作(我在ol3上)我得到「未捕獲的TypeError:無法讀取null的屬性'getText'」錯誤 – So4ne

+0

然後,您需要顯示更多的代碼,你能夠把這是一個小提琴? –

+0

我在努力,我會讓你知道:) – So4ne