2017-07-01 4 views
0

私は解決策を探していますが、答えが見つかりませんでした。私はDropdown listからlayerを取得し、cql-filterの値を変更し、それが動作するようにupdate()機能を使用して、私のレイヤーを表示するためのWFS要求で働いていた最初の時点で:Openlayersを使用してcqlフィルタにupdate()関数を追加する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要求で作業することを決定したとき、このようなスクリプト:私はdropdown listから私のlayerを選択したとき

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'            
      })}) 

は、私が何を取得します。私は追加する何かがあるか、私が作ったエラーがあるかどうかわからないのですか?ありがとうございます

答えて

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

関連する問題