最近碰到一个需求,将屏幕显示区域的featrues今天查询显示,思考了一下,需要先拿到视图的四至范围,将这个范围绘制成矩形即可。再去拿到geometry进行wfs条件查询。注释不写了,不明白查官方
const [ x1, y1, x2, y2 ] = map.getView().calculateExtent();
const feature = new ol.Feature({ geometry: new ol.geom.Polygon.fromExtent([ x1, y1, x2, y2 ]) });
feature.setStyle( new ol.style.Style({
fill: new ol.style.Fill({ color: 'rgba(255, 255, 255, 0.3)', }),
stroke: new ol.style.Stroke({ color: 'blue', width: 2, }),
image: new ol.style.Circle({ radius: 7, fill: new ol.style.Fill({ color: '#ffcc33', }),
})
}) );
const source = this._checkVectorSource("source");
const layer = this._checkLayerVector("layer", "source");
source.addFeature(feature);
``