function a() {
var XML = addFeature();
var xmlPara = XML; //返回结果无法解析为gml??-已解决(增加返回结果样式标签)
var request = OpenLayers.Request.POST({
url: "http://localhost:8080/geoserver/wfs?",
data: xmlPara,
callback: onComplete
});
}
var wfsstr;
function addFeature(){
wfsstr = '<wfs:Transaction '
+'service="WFS" '
+'version="1.1.0" '
+'xmlns:TJDG="TJDG" '
+'xmlns:wfs="http://www.opengis.net/wfs" '
+'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.1.0/WFS-transaction.xsd '
+'http://localhost:8080/geoserver/wfs/DescribeFeatureType?typename=TJDG:postxq"> '
+'<wfs:Insert>'
+ '<TJDG:postxq gml:id="postxq.2">'
+ '<TJDG:id>111</TJDG:id>'
+ '<TJDG:xqmc>908</TJDG:xqmc>'
+ '<TJDG:geom>'
+ '<gml:MultiSurface srsDimension="2" srsName="urn:x-ogc:def:crs:EPSG:3857">'
+ '<gml:surfaceMember>'
+ '<gml:Polygon>'
+ '<gml:exterior>'
+ '<gml:LinearRing>'
+ '<gml:posList>13064909.03381044 4675414.18053034 13065180.809911 4675492.50863014 13065337.08116884 4675579.54055719 13065337.08116884 4675527.3213119 13064909.03381044 4675414.18053034</gml:posList>'
+ '</gml:LinearRing>'
+ '</gml:exterior>'
+ '</gml:Polygon>'
+ '</gml:surfaceMember>'
+ '</gml:MultiSurface>'
+ '</TJDG:geom>'
+ '</TJDG:postxq>'
+'</wfs:Insert>'
+'</wfs:Transaction>';
return wfsstr;
}
function onComplete(response) {
// body...
var gmlStr = response.responseText;
console.log(gmlStr);
var gmlParse = new OpenLayers.Format.GML();//如果使用wfs1.1.0,则需要增加如下参数:{xy:false }//更改x,y坐标的读取顺序
var features = gmlParse.read(response.responseText);
console.log(features);
}
openlayers中通过拼接xml向postgis插入数据
最新推荐文章于 2023-05-20 10:23:32 发布