openlayers之wms属性查询、空间查询
openlayers之wms属性查询、空间查询
图层新建代码:
let wmsSource = new ol.source.TileWMS({ url: config.dataSeverUrl, params: { 'FORMAT': 'image/png', 'VERSION': '1.1.1', "LAYERS": 'sxyd:' + id, "CQL_FILTER": null, }, serverType: 'geoserver', crossOrigin: 'anonymous', }); var wmsLayer = new ol.layer.Tile({ id: id, typeName: 'dataLayer', source: wmsSource, }); this.map.addLayer(wmsLayer)
1.原理
通过"CQL_FILTER"传递sql语句查询。"CQL_FILTER"传null时取消查询条件。
2.查询语句:
COUNTY = '夷陵区' and INTERSECTS(the_geom,POINT(111.35192871093749 30.927359440059533))
两条语句之间使用and连接 空间查询使用WKT格式
3.更新查询
wmsSource.updateParams({ CQL_FILTER: "INTERSECTS(the_geom, POLYGON((111.328388 30.790351,111.322711 30.77428,111.345492 30.773225,111.328388 30.790351)))" });
4.注意:
如查询语句中有中文,geoserver数据存储字符集需要改成UTF-8
钻研不易,转载请注明出处。。。。。。