【发布时间】:2014-11-24 15:39:48
【问题描述】:
有人知道如何计算 OL3 矢量图层中存在的特征数量吗?
我的矢量图层定义如下,我想知道它有多少个元素,理想情况下当前正在渲染多少个:
var styleCache = {};
var WFS_layer_Traffic_Lights = new ol.layer.Vector({
source : new ol.source.GeoJSON({
projection : 'EPSG:3857',
url : "Vector_Data/Traffic_Lights_Bordeaux.geojson"
}),
style : function(feature, resolution) {
var path;
var x_anchor;
var y_anchor;
if(resolution < 4){
path = 'Icons/Traffic_Lights_Sign_Icon_Small.png';
x_anchor = 23;
y_anchor = 90;
}
if(resolution >= 4 && resolution < 10){
path = 'Icons/Traffic_Lights_Sign_Small.png';
x_anchor = 16;
y_anchor = 16;
}
if(resolution >= 10){
path = 'Icons/Traffic_Lights_Sign_Tiny.png';
x_anchor = 10;
y_anchor = 10;
}
if (!styleCache[path]) {
styleCache[path] = [new ol.style.Style({
fill : new ol.style.Fill({
color : 'rgba(255, 255, 255, 0.1)'
}),
stroke : new ol.style.Stroke({
color : '#319FD3',
width : 1
}),
image: new ol.style.Icon(({
anchor: [x_anchor, y_anchor],
anchorXUnits: 'pixels',
anchorYUnits: 'pixels',
src: path
})),
text : new ol.style.Text({
font : '12px Calibri,sans-serif',
text : "",
fill : new ol.style.Fill({
color : '#000'
}),
stroke : new ol.style.Stroke({
color : '#fff',
width : 4
})
}),
zIndex : 1
})];
}
return styleCache[path];
}
});
【问题讨论】: