我必須加載某些功能在矢量層,並有風格的函數。OL3:聚類矢量功能時無法確定功能型
var features = new ol.format.GeoJSON().readFeatures(geojsonStr, {
featureProjection: 'EPSG:3857'
});
var vectorSource = new ol.source.Vector({
features: features,
});
/*
var clusterSource = new ol.source.Cluster({
distance: 15,
source: vectorSource
});
*/
var customStyleFunction = function(feature, resolution) {
....
}
var vectorLayer = new ol.layer.Vector({
//source: clusterSource,
source: vectorSource,
style : customStyleFunction
});
map.addLayer(vectorLayer);
我不知道我會得到geojsonStr
什麼樣的幾何形狀。問題是:當我收集的類型是「點」我可以羣集,但與其他任何類型的,我不能看到圖層...我怎麼能聚點,而忽略多邊形和線條?還是讓OL3足夠聰明來決定?
編輯:我讀過https://github.com/openlayers/openlayers/pull/4917
所以,你想獲得所有的功能,並單獨檢查它們以將它們添加到矢量源中,以防它們是點,並且如果它們是別的東西就完全忽略它們,對嗎?或者你想用其他功能做其他事情嗎? – Icarus
不,我有一個帶FeatureCollection的GeoJSON字符串。現在我們可以假定所有幾何都是相同的類型。問題是我必須設置源之前,我知道我有什麼樣的幾何形狀的集合中並不能確定,如果我可以在我的'vectorLayer'使用'clusterSource'或'vectorSource'。但是......(不是主要問題),將是巨大的,如果我能得到的混合和的FeatureCollection只聚集點留下其他幾何形狀不變。 –
閱讀https://github.com/openlayers/openlayers/pull/4917後我幾乎沒有,但仍然不能有條件地選擇'vectorSource'或'clusterSource'附加到'vectorLayer'。 –