如何使用HTML发送WPS请求

问题描述 投票:2回答:1

enter image description here我已经在GeoServer上安装了WPS扩展。我已经使用GeoServer的WPS请求生成器生成了WPS请求。为此,我选择了process = gs:Bounds,过程输入= VECTOR_LAYER,并选择了我上载的任何一个矢量层,然后从WPS Request Builder选择了选项“从过程输入/输出生成XML”。生成一个XML文件后,并且我用.xml扩展名保存了我。我已经使用HTML,CSS和Java脚本创建了一个网站。现在,我想从网站访问此XML文件。我如何定义该代码?

javascript html xml openlayers geoserver
1个回答
0
投票

获得XML之后,您只需要对其执行POST请求。例如:

var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/xml");
var raw = `<?xml version="1.0" encoding="UTF-8"?>
<wps:Execute version="1.0.0" service="WPS"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.opengis.net/wps/1.0.0" xmlns:wfs="http://www.opengis.net/wfs"
xmlns:wps="http://www.opengis.net/wps/1.0.0"
xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:gml="http://www.opengis.net/gml"
xmlns:ogc="http://www.opengis.net/ogc" xmlns:wcs="http://www.opengis.net/wcs/1.1.1"
xmlns:xlink="http://www.w3.org/1999/xlink"
xsi:schemaLocation="http://www.opengis.net/wps/1.0.0
http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd">
<ows:Identifier>gs:Bounds</ows:Identifier>
<wps:DataInputs>
    <wps:Input>
        <ows:Identifier>features</ows:Identifier>
        <wps:Data>
        <wps:ComplexData mimeType="application/json">
            <![CDATA[${FEATURES_COLLECTION}]]>
        </wps:ComplexData>
        </wps:Data>
    </wps:Input>
</wps:DataInputs>
<wps:ResponseForm>
<wps:RawDataOutput>
<ows:Identifier>bounds</ows:Identifier>
</wps:RawDataOutput>
</wps:ResponseForm>
</wps:Execute>`;
var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: raw,
  redirect: 'follow'
};
fetch("http://GEOSERVER_URL/wps", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

位置:

  • 变量raw是您的带参数FEATURES_COLLECTION的字符串格式的XML,在此示例中,我选择了GeoJSON作为要素格式(在生成XML时,使用OpenLayers您可以使用writeFeatures来获取值
  • FEATURES_COLLECTION是您的功能集合(例如{“ type”:“多边形”,“坐标”:[[[100.0,0.0],[101.0,0.0],[101.0,1.0],[100.0,1.0],[100.0,0.0]]]})
  • GEOSERVER_URL是您的地图服务器网址(例如http://localhost:8080/geoserver
© www.soinside.com 2019 - 2024. All rights reserved.