背景:
在GIS开发过程中,经常会遇到前端加载了geoserver的wms服务后,需要查询某个要素的属性进行弹窗显示的需求,这个时候就需要调用wfs服务查询到鼠标位置的要素属性进行操作;
关键代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| const Your_WorkSpace = 'TEST'; const Your_LayerName = 'Block'; const geometryFieldKey = 'the_geom'; axios.get(`http://192.168.0.81:8080/geoserver/${Your_WorkSpace}/wfs`, { params: { SERVICE: 'WFS', VERSION: '1.1.0', REQUEST: 'GetFeature', TYPENAME: `${Your_WorkSpace}:${Your_LayerName}`, OUTPUTFORMAT: 'application/json', CQL_FILTER: `INTERSECTS(${geometryFieldKey},SRID=4326;POINT(${lng} ${lat}))`, SRSNAME: 'EPSG:4326', PROPERTYNAME: '*' } }) .then( ({ data: { features: [feature] } }) => { if (feature) { this.featurePopup({ lnglat: lnglat, vueCom: immiBlockPop, props: { data: feature.properties } }); } } ) .catch((error) => { console.error('请求失败:', error); });
|