leaflet - 实施传单绘制时我做错了什么。在这个具体示例中如何使用 WFST?
问题描述
我是地理信息开发领域的新手。我遵循以下管道架构流程来实现基于 GIS 的应用程序问题。
PostGIS - 地理服务器 - 传单
我已经设置了我的传单客户端应用程序,它将图块组合到地图上。我还使用了一些传单插件(如 Draw、zoom),以便为用户提供在地图上进行标记和绘制的选项。
我能够绘制并获取所绘制多边形的 GeoJSON 特征,如下所示:
在弄清楚我需要如何发送绘制的多边形请求并以编程方式检索多边形(已保存)的这一部分之后,我陷入了困境。我知道答案是 WFS-T,但是如何在我的原始代码中使用它。这是原始代码示例:
原始代码链接:https ://pastebin.com/wCAHxVc0Follow the link
参考:
解决方案
了解 WFS-T 的最佳方式是使用 GeoServer Demo 选项(链接:http://localhost:8080/geoserver/web/wicket/bookmarkable/org.geoserver.web.demo.DemoRequestsPage?5)。我的主要问题是弄清楚如何插入和更新交易细节。Exploring GeoServer Demo给了我解决方案。
这是一个示例:
var postdata = "<wfs:Transaction service="WFS" version="1.0.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:topp="http://www.openplans.org/topp" xmlns:gml="http://www.opengis.net/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd http://www.openplans.org/topp http://localhost:8080/geoserver/wfs/DescribeFeatureType?typename=topp:tasmania_roads"> <wfs:Insert>
<topp:tasmania_roads>
<topp:the_geom>
<gml:MultiLineString srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
<gml:lineStringMember>
<gml:LineString>
<gml:coordinates decimal="." cs="," ts=" ">
494475.71056415,5433016.8189323 494982.70115662,5435041.95096618
</gml:coordinates>
</gml:LineString>
</gml:lineStringMember>
</gml:MultiLineString>
</topp:the_geom>
<topp:TYPE>alley</topp:TYPE>
</topp:tasmania_roads> </wfs:Insert> </wfs:Transaction>"
此 XML 请求稍后可用于发送到 GeoServer 以使用 AJAX 调用进行操作,如下所示:
$.ajax({
type: "POST",
url: gs.wfs,
dataType: "xml",
contentType: "text/xml",
data: postdata,
//TODO: Error handling
success: function(xml) {
//TODO: User feedback
console.log("Successfully inserted");
}
});
为了更好地理解 WFS-T 的应用场景,请尝试以下 URL:https ://georepublic.info/en/blog/2012/leaflet-example-with-wfs-t/ 。这应该可以帮助您开始使用 WFS-T。快乐的地图编辑:)