Openlayers 3 如何在js中动态添加ol.format.filter?

Openlayers 3 如何在js中动态添加ol.format.filter?,openlayers-3,geoserver,openlayers-5,Openlayers 3,Geoserver,Openlayers 5,我正在做一个使用Openlayers和geoserver的项目,我的目标是缩放到我分配给用户的国家。目前,我通过添加一个类似ol.format.filter.equalTo(“国家”、“印度”)的过滤器来实现这一点,但问题是如果我分配了多个国家,我必须更改代码,以便有多个ol.format.filter.equalTo,我想动态添加这些国家 我搜索了以前的答案,但没有一个能解决这个问题。这是我的示例代码。请看一看 var conditions=new Array();

我正在做一个使用Openlayers和geoserver的项目,我的目标是缩放到我分配给用户的国家。目前,我通过添加一个类似ol.format.filter.equalTo(“国家”、“印度”)的过滤器来实现这一点,但问题是如果我分配了多个国家,我必须更改代码,以便有多个ol.format.filter.equalTo,我想动态添加这些国家


我搜索了以前的答案,但没有一个能解决这个问题。

这是我的示例代码。请看一看

             var conditions=new Array();

            for(var i=0;i<this.selectedAttribute.length;i++) {
                if(this.selectedAttribute[i]=="") {
                    alert("Please selected all attributes");
                    return;
                }

                if(this.selectedValue[i]=="") {
                    alert("Please input value");
                    return;
                }
                if(this.selectedOperator[i]=="") {
                    alert("Please select operators");
                    return;
                }
                var condition;

                var operator=this.selectedOperator[i];

                if(operator=="=") {
                    condition=ol.format.filter.equalTo(this.selectedAttribute[i],this.selectedValue[i]);
                }
                else if(operator=="!=") {
                    condition=ol.format.filter.equalTo(this.selectedAttribute[i],this.selectedValue[i]);
                }
                else if(operator=="<"){
                    condition=ol.format.filter.greaterThan(this.selectedAttribute[i],this.selectedValue[i]);
                }

                else if(operator=="<="){
                    condition=ol.format.filter.greaterThanOrEqualTo(this.selectedAttribute[i],this.selectedValue[i]);
                }

                else if(operator==">"){
                    condition=ol.format.filter.lessThan(this.selectedAttribute[i],this.selectedValue[i]);
                }

                else if(operator==">="){
                    condition=ol.format.filter.lessThanOrEqualTo(this.selectedAttribute[i],this.selectedValue[i]);
                }
                else if(operator=="LIKE"){
                    condition=ol.format.filter.like(this.selectedAttribute[i],this.selectedValue[i]);
                }
                else if(operator=="ISNULL"){
                    condition=ol.format.filter.isNull(this.selectedAttribute[i]);
                }
                conditions.push(condition);
            }

            if(this.selectedAttribute.length==1) {
                filter=conditions[0];
            }
            else {
                if(this.selectedCondition=="AND") {
                    filter=ol.format.filter.and.apply(null,conditions);

                }
                else if(this.selectedCondition=="OR"){
                    filter=ol.format.filter.or.apply(null,conditions);
                }
            }
var条件=新数组();

对于(var i=0;我有代码示例吗?