我已经创建了一个矢量层,并在网页上在其上绘制了一个多边形,现在,我想将该多边形插入到geoserver上的wms图像层中。使用以下代码:
var node;
var lName = 'myworkspace:mylayer, http://*.*.*.*:8080/geoserver';
var layerAuth = "-";
var lNameInfo = lName.split(',');
var url = lNameInfo[1];
var layer = lNameInfo[0];
//console.log(layer.split(':')[0]);
var formatWFS = new ol.format.WFS();
var formatGML = new ol.format.GML({
featureNS: url + '/' + layer.split(':')[0],
featureType: layer.split(':')[1],
srsName: 'EPSG:28191'
});
var xs = new XMLSerializer();
var featureProperties = f.getProperties();
var clone = new ol.Feature(featureProperties);
//clone.setId(layer.split(':')[1] + "." + "7");
//(Math.floor(Math.random() * 90000) + 10000)
switch (p) {
case 'insert':
node = formatWFS.writeTransaction([clone], null, null, formatGML);
break;
}
var payload = xs.serializeToString(node);
var req = payload.replace('geometry', 'Shape').replace('/geometry', '/Shape').replace('typeName="feature:', 'typeName="' + layer.split(':')[0] + ':');
//console.log(req);
alert(payload);
alert(req);
$.ajax(url + "/wfs", {
type: 'POST',
dataType: 'xml',
processData: false,
contentType: 'text/xml',
data: { url: url + "/wfs", xml: payload, auth: layerAuth },
success: function (result) {
//console.log(result);
if ($(result).find("HttpError").length > 0) {
alert('error');
toastr.error($(result).find("HttpError").text().trim());
} else {
if ($(result).find("ows\\:ExceptionReport").length > 0) {
toastr.error($(result).find("ows\\:ExceptionReport").text().trim());
alert($(result).find("ows\\:ExceptionReport").text().trim());
} else {
toastr.success("Feature Geometry Inserted Successfully");
alert('success');
}
}
}
}).done(function () {
// sourceWFS.clear();
});
此代码为我提供了以下异常:
org.xmlpull.v1.xmlpullparserexception only whitespace content allowed
有什么主意吗????
这是req变量的内容:
<Transaction xmlns="http://www.opengis.net/wfs" service="WFS" version="1.1.0" 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.xsd"><Insert><mylayer xmlns=" http://*.*.*.*:8080/geoserver/myworkspace"><Shape><Polygon xmlns="http://www.opengis.net/gml" srsName="EPSG:28191"><exterior><LinearRing srsName="EPSG:28191"><posList srsDimension="2">3905141.4998611817 3703192.482474612 3905471.1345456615 3703211.5917316834 3905361.2563175014 3702967.9487040243 3905141.4998611817 3703192.482474612</posList></LinearRing></exterior></Polygon></Shape></mylayer></Insert></Transaction>