我有一个openlayer-3 web应用程序,我需要在上面做一些图层过滤。该层恰好来自WFS源。我想选择过滤作为GetFeature CQL请求到服务器,也过滤本地的数据。
我还没有让CQL请求工作。同时,我想根据Openlayers 2中的特征属性在本地过滤矢量数据。有没有简单的方法可以做到这一点?是否有意不将Filter对象包含在ol3中?
编辑:我希望在ol3中有一个这样的过滤器:
发布于 2016-07-27 17:46:11
我已经找到了一种解决方案,通过解析CQL过滤器并在将特征添加到层之前过滤掉它们。
/* Your filter ... */
var cql = "STATE_ABBR >= 'B' AND STATE_ABBR <= 'O'";
/* Gets all the features from the current extent */
var features = new ol.format.WFS().readFeatures(response);
/**
* Find a way to parse your CQL filter, for example, replace the 'AND's into '&&'s
* It would be better to build a parser. You can use this: http://pegjs.org/
*/
/* Filters the features */
features = features.filter(function (feature) {
return feature.get('STATE_ABBR') >= 'B' && feature.get('STATE_ABBR') <= 'O';
});
/* Adds the features to the layers */
layerWFS.getSource().addFeatures(features);
尝试使用PEGjs构建解析器
您的解析器应该将此转换为
"STATE_ABBR >= 'B' AND STATE_ABBR <= 'O'"
进入到这个
feature.get('STATE_ABBR') >= 'B' && feature.get('STATE_ABBR') <= 'O'
请参阅示例here
这里的关键是PEGjs。:)我希望我能帮到..。
https://stackoverflow.com/questions/29011970
复制相似问题