openlayers+geoserver WMS过滤CQL_FILTER查询动态刷新图层

openlayers+geoserver WMS过滤CQL_FILTER查询动态刷新图层

初始化图层

var wmsSource = new ol.source.ImageWMS({
            crossOrigin: 'anonymous',
            params: {
                LAYERS: 'bjdz:un_feature', //图层
                'VERSION': '1.1.0',
                'FORMAT': "image/png",
                bbox: [0.0, 0.0, 3439.2839891971, 1716.1370382487],
                'CQL_FILTER': "projectid='" + projectid + "'" //过滤条件
            },
            serverType: 'geoserver',
            url: geourl + 'wms' //geoserver wms服务地址

        });
 var wmsLayer = new ol.layer.Image({
            source: wmsSource
        })

数据有变化,更新图层,实时刷新

//筛选语句就是sql语句类型
var cql = "(featurename like '%桩'  or featurename = '抗浮锚杆') and projectid='" + projectid + "'";
function updateSource(cql) {
        wmsSource = new ol.source.ImageWMS({
            crossOrigin: 'anonymous',
            params: {
                LAYERS: 'bjdz:un_feature',
                'VERSION': '1.1.0',
                'FORMAT': "image/png",
                bbox: [0.0, 0.0, 3439.2839891971, 1716.1370382487],
                'CQL_FILTER': cql
            },
            serverType: 'geoserver',
            url: geourl + 'wms'

        });
        wmsLayer.setSource(wmsSource);
        view.setResolution(view.getResolution() + Math.random() * 0.00000001);//随机数缩放实现刷新
 }
updateSource(cql);


You may also like...

1 Response

  1. Thank you for starting this up. This website is something that is needed on the internet someone with a little originality!

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

CAPTCHAis initialing...