2016-09-08 45 views

回答

2

這是一個向通用屬性添加通用屬性的示例,您可以在其他位置使用該通用屬性。這個例子並沒有讓它變得非常明顯。在該示例中,您可以添加另一個名爲'numberOfDonkeys'的屬性,值爲20,然後可以在觸發彈出窗口的點擊事件中使用該屬性。敵我的例子,我可以改變功能是這個。

var iconFeature = new ol.Feature({ 
    geometry: new ol.geom.Point([0, 0]), 
    name: 'Null Island', 
    population: 4000, 
    rainfall: 500, 
    numberOfDonkeys: 20 
}); 

並將地圖點擊事件更改爲此。

// display popup on click 
map.on('click', function(evt) { 
    var feature = map.forEachFeatureAtPixel(evt.pixel, 
     function(feature) { 
     return feature; 
     }); 
    if (feature) { 
    var coordinates = feature.getGeometry().getCoordinates(); 
    popup.setPosition(coordinates); 
    $(element).popover({ 
     'placement': 'top', 
     'html': true, 
     'content': feature.get('name') + ' Pop: ' + feature.get('population') + ' Donkeys: ' + feature.get('numberOfDonkeys') 
    }); 
    $(element).popover('show'); 
    } else { 
    $(element).popover('destroy'); 
    } 
}); 

而且您會在彈出窗口中看到Population和numberOfDonkeys屬性。

的jsfiddle示例 - https://jsfiddle.net/z7adr7q0/1/

最終你不需要這些屬性在所有的,你可以擺脫他們,他們是你想在這個重用,在那裏你能屬性只是一個例子辦法。

1

這並不意味着什麼。空島是定義了一些屬性的虛構特徵,就是這樣。

+0

你確定嗎?你從哪裏得到這些信息? – panoet

+2

@panoet我住在那裏,我可以確認我們不是4000 –

相關問題