WFS-GetFeature的请求方式和ajax提交方法

前端之家收集整理的这篇文章主要介绍了WFS-GetFeature的请求方式和ajax提交方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
根据OGC标准,WFS的请求有两种方式,一种是url带参数形式,另一种是XML的请求方式。

以下是一个WFS使用KVP格式的GetFeature操作示例:

  1. http://www.someserver.com/wfs? SERVICE=WFS& VERSION=1.1.0& REQUEST=GetFeature& PROPERTYNAME=InWaterA_1M/wkbGeom,InWaterA_1M/tileId& TYPENAME=InWaterA_1M& FILTER=<Filter><Within><PropertyName>InWaterA_1M/wkbGeom<PropertyName> <gml:Envelope><gml:lowerCorner>10,10</gml:lowerCorner> <gml:upperCorner>20 20</gml:upperCorner></gml:Envelope></Within></Filter>

以下是一个WFS使用XML格式的GetFeature操作示例:

  1. <?xml version="1.0" ?>
  2. <GetFeature version="1.1.0" service="WFS" handle="Query01"
  3. xmlns="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc"
  4. xmlns:gml="http://www.opengis.net/gml" xmlns:myns="http://www.someserver.com/myns"
  5. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  6. xsi:schemaLocation="http://www.opengis.net/wfs ../wfs/1.1.0/WFS.xsd">
  7. <Query typeName="myns:Hydrography">
  8. <wfs:PropertyName>myns:geoTemp</wfs:PropertyName>
  9. <wfs:PropertyName>myns:depth</wfs:PropertyName>
  10. <ogc:Filter>
  11. <ogc:Not>
  12. <ogc:Disjoint>
  13. <ogc:PropertyName>myns:geoTemp</ogc:PropertyName>
  14. <gml:Envelope srsName="EPSG:63266405">
  15. <gml:lowerCorner> -57.9118 46.2023 <gml:lowerCorner>
  16. <gml:upperCorner>-46.6873 51.8145</gml:upperCorner>
  17. </gml:Envelope>
  18. </ogc:Disjoint>
  19. </ogc:Not>
  20. </ogc:Filter>
  21. </Query>
  22. </GetFeature>

当使用XML格式请求时,特别注意使用Ajax请求时,必须要设置数据的传输采用Request Payload方式发送数据

例:

  1. $.ajax({
  2. url: url,type: "POST",contentType: 'text/plain;charset=UTF-8',// 这里必须设置,否则会默认以form表单数据进行发送
  3. traditional: true,data: '这里是XML内容',success: function(result){
  4. // 这里获取到返回的features数据 // ...
  5. }
  6. });
另外,还可以使用更新潮的fetch方式请求:
  1. fetch(url,{
  2. method: 'POST',body: '这里是XML内容'
  3. }).then(function(response) {
  4. return response.json();
  5. }).then(function(json) {
  6. var features = new ol.format.GeoJSON().readFeatures(json); //...
  7. });

有的浏览器还没有对fetch进行支持,所以可以通过if(!self.fetch) {...}进行判断使用。

@H_403_23@

猜你在找的Ajax相关文章