我必须加载某些功能在矢量层,并有风格的函数。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'。 –