使用openlayers3自带的功能,使用WFS对geoserver服务器进行空间查询


 使用openlayers3自带的功能,使用WFS对geoserver服务器进行空间查询。网络上很多都没有代码,这里贴点代码出来,供大家分享。
 `function QuerySpatial(geometry){
    var featureRequest = new ol.format.WFS().writeGetFeature({
        srsName: 'EPSG:4326',
        featureNS: 'http://localhost:8080/geoserver',
        featurePrefix: 'quzhou',
        featureTypes: ['20CC96E96AF7BE2780287906F67F5369'],
        outputFormat: 'application/json',
        //filter: ol.format.ogc.filter.like('NAME', '姜家山乡沃华农庄(2A)')
        filter:ol.format.ogc.filter.within("the_geom",geometry,"")
    });
    var body=new XMLSerializer().serializeToString(featureRequest);
    console.log(body);
    var axisOrientation=ol.proj.get("EPSG:4326").getAxisOrientation();
    console.log(axisOrientation);
    /*$.ajax({
            url: "./proxy.ashx?url=http://192.168.9.26:8080/geoserver/quzhou/wfs?"
            ,processData: false
            , type: "POST"
            , data: body
            , timeout: 3000
        }).done(function(response) {
            var format = new ol.format.GeoJSON();
            var features = format.readFeatures(response);
            vectorSource.addFeatures(features);
        });*/
    fetch('./proxy.ashx?url=http://192.168.9.26:8080/geoserver/quzhou/wfs', {
        method: 'POST',
        body: new XMLSerializer().serializeToString(featureRequest)
      }).then(function(response) {
        return response.json();
      }).then(function(json) {
          console.log(json);
      });`

主要的点是,额,好像代码大家都能看明白,就不啰嗦了。

转载自:https://blog.csdn.net/A741841403/article/details/52613426

You may also like...