Vector Openlayers 2.x:在添加另一个矢量层后不刷新WFS矢量层
这只是我的代码片段:Vector Openlayers 2.x:在添加另一个矢量层后不刷新WFS矢量层,vector,openlayers,geoserver,Vector,Openlayers,Geoserver,这只是我的代码片段: function removeFilter(a){ if (a === "100-Year Rainfall"){ bldg100yearCBR.filter = null; bldg100yearCBR.refresh({ force: true }); } ... 上面是我为WFS矢量层移除过滤器的函数。如果我不添加另一层,它就会工作。我想知道为什么?以下是我添加图层的方
function removeFilter(a){
if (a === "100-Year Rainfall"){
bldg100yearCBR.filter = null;
bldg100yearCBR.refresh({
force: true
});
}
...
上面是我为WFS矢量层移除过滤器的函数。如果我不添加另一层,它就会工作。我想知道为什么?以下是我添加图层的方式:
bldg100yearCBR = new OpenLayers.Layer.Vector("100-Year Rainfall Affected Buildings", {
strategies: [new OpenLayers.Strategy.Fixed()],
eventListeners: {
'loadend': function (evt) {
map.zoomToExtent(bldg100yearCBR.getDataExtent());
//map.getExtent().containsBounds(bldg100yearCBR, true);
$("#load_table").removeAttr("disabled", "disabled");
$("#load_table").val("Go");
$("#locateMe").hide();
},
'loadstart': function (evt) {
$("#load_table").attr("disabled", "disabled");
$("#load_table").val("Loading...");
$("#locateMe").show();
}
},
projection: new OpenLayers.Projection("EPSG:4326"),
protocol: new OpenLayers.Protocol.WFS({
version: "1.1.0",
url: a,
featureType: "bldg_100yr",
featureNS: b,
geometryName: "geom"
}),
renderers: renderer,
styleMap: new OpenLayers.StyleMap(style),
displayInLayerSwitcher: !0
});
var selFloodEvent = $('#affectedLayer').val();
var layerName = map.getLayersByName(selFloodEvent);
var len = layerName.length;
if (len < 1){
map.addLayer(bldg100yearCBR);
activateControls(c);
}else{
removeFilter("100-Year Rainfall");
layerName[0].setVisibility(true);
console.log("reset me");
}
myflag1 = true;
toggleStatic1("100-Year Rainfall Affected Buildings");
bldg100yearCBR=新OpenLayers.Layer.Vector(“受100年降雨影响的建筑物”{
策略:[新建OpenLayers.Strategy.Fixed()],
eventListeners:{
“loadend”:函数(evt){
zoomToExtent(bldg100yearCBR.getDataExtent());
//map.getExtent().containsBounds(bldg100yearCBR,true);
$(“加载表”).removeAttr(“禁用”、“禁用”);
$(“#加载表格”).val(“Go”);
$(“#locateMe”).hide();
},
“loadstart”:函数(evt){
$(“加载表”).attr(“禁用”、“禁用”);
$(“#加载表格”).val(“加载…”);
$(“#locateMe”).show();
}
},
投影:新OpenLayers.projection(“EPSG:4326”),
协议:新OpenLayers.protocol.WFS({
版本:“1.1.0”,
网址:a,
特征类型:“建筑100年”,
特点:b,,
geometryName:“geom”
}),
渲染器:渲染器,
styleMap:new OpenLayers.styleMap(样式),
displayInLayerSwitcher:!0
});
var selFloodEvent=$(“#影响层”).val();
var layerName=map.getLayersByName(selFloodEvent);
var len=layerName.length;
if(len<1){
地图添加层(bldg100yearCBR);
激活控制(c);
}否则{
移除过滤器(“100年降雨量”);
layerName[0]。设置可见性(true);
控制台日志(“重置我”);
}
myflag1=真;
toggleStatic1(“受100年降雨影响的建筑物”);
添加/加载另一个矢量层后,过滤器将无法工作。场景是,如果层已经加载,我希望显示它而不再次添加它,但如果它之前已过滤,我希望重置它。这就是问题所在,removeFilter
函数在加载另一个向量层后无法工作
所以,基本上过滤器只在我第一次加载图层时起作用。我还注意到,在我的浏览器的console log中,它不会像这样查询GeoServer:
XHR已完成加载:POST”http://127.0.0.1:8080/geoserver/wfs“
加载另一层后