首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >按要素属性在本地过滤ol.layer.Vector

按要素属性在本地过滤ol.layer.Vector
EN

Stack Overflow用户
提问于 2015-03-12 14:06:38
回答 1查看 2.9K关注 0票数 2

我有一个openlayer-3 web应用程序,我需要在上面做一些图层过滤。该层恰好来自WFS源。我想选择过滤作为GetFeature CQL请求到服务器,也过滤本地的数据。

我还没有让CQL请求工作。同时,我想根据Openlayers 2中的特征属性在本地过滤矢量数据。有没有简单的方法可以做到这一点?是否有意不将Filter对象包含在ol3中?

编辑:我希望在ol3中有一个这样的过滤器:

http://dev.openlayers.org/examples/cql-format.html

EN

回答 1

Stack Overflow用户

发布于 2016-07-27 17:46:11

我已经找到了一种解决方案,通过解析CQL过滤器并在将特征添加到层之前过滤掉它们。

代码语言:javascript
运行
AI代码解释
复制
/* 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构建解析器

您的解析器应该将此转换为

代码语言:javascript
运行
AI代码解释
复制
"STATE_ABBR >= 'B' AND STATE_ABBR <= 'O'"

进入到这个

代码语言:javascript
运行
AI代码解释
复制
feature.get('STATE_ABBR') >= 'B' && feature.get('STATE_ABBR') <= 'O'

请参阅示例here

这里的关键是PEGjs。:)我希望我能帮到..。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29011970

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档