2017-07-01 66 views
0

已經過了3天我正在尋找解決方案,但是我沒有找到答案。在我第一次與WFS要求工作來顯示使用update()功能得到Dropdown listlayer和改變cql-filter值我的層和它的工作:使用Openlayers將update()函數添加到cql篩選器3

<select name="pam" class='pam' id="pam" onchange='update()'> 
    <option value="Arbuuned">Moyen</option> 
    <option value="Bended">Fort</option> 
</select> 
<script> 
var vector = new ol.layer.Vector({ source: new ol.source.Vector() }) 

var geojsonFormat = new ol.format.GeoJSON(); 

var vectorSource = new ol.source.Vector({ 
    loader: function(extent, resolution, projection) { 
    var url = "http://localhost:8080/geoserver/opengeo/ows?service=WFS&" + 
     "version=2.0.0&request=GetFeature&typename=opengeo:arbousiers0&CQL_FILTER=code_espec="+"'"+pam.value+"'"+ 
     "&outputFormat=text/javascript&format_options=callback:loadFeatures"+ 
     "&srsname=EPSG:3857"; 
    $.ajax({url: url, dataType: 'jsonp', jsonp: false}); 
    }, 
    strategy: ol.loadingstrategy.tile(ol.tilegrid.createXYZ({ 
    maxZoom: 19 

    })) 

}); 
window.loadFeatures = function(response) { 
    vectorSource.addFeatures(geojsonFormat.readFeatures(response)); 
}; 
window.update = function() { 
vectorSource.clear(true); 
}; 

</script> 

但是當我決定與WMS要求我改變工作像這樣的腳本:

var wmsSource= "code_espec="+"'"+pam.value+"'"+""; 
window.update = function() { 
    wmsSource.clear(true); 
}; 
new ol.layer.Image({ 
      source: new ol.source.ImageWMS({ 
      url: 'http://localhost:8080/geoserver/opengeo/wms', 
      params: {'LAYERS': 'opengeo:arbousiers0','cql_filter':wmsSource}, 
      serverType: 'geoserver'            
      })}) 

我什麼也沒得到,當我選擇我的layerdropdown list。我不知道是否有添加或我犯的錯誤?謝謝你

回答

2

我覺得在函數中有一個問題來更新值。 我建議這樣:

window.update = function(){ad.getSource().updateParams({'cql_filter':"code_espec"+"="+"'"+pam.value+"'"+"});}; 

     var ad =new ol.layer.Image({ 
        name: 'Espece(Répartition)', 
       source: new ol.source.ImageWMS({ 
       url: 'http://localhost:8080/geoserver/opengeo/wms', 
       params: {'LAYERS': 'opengeo:arbousiers0'}, 
       serverType: 'geoserver'            
       })}); 
+0

是的,它的工作兄弟,非常感謝你 – Issam

相關問題