これは私のコードです
var selectFeat = new ol.interaction.Select({
condition: ol.events.condition.click,
hitTolerance: 3,
});
map.addInteraction(selectFeat);
// var selectedFeat = selectFeat.getFeatures();
function deleteFeatures() {
var selectedFeat = selectFeat.getFeatures();
if (selectedFeat.getLength() > 0) {
var toDeleteFeat = selectFeat.getFeatures().getArray()[0];
// wfsSource.removeFeature(toDeleteFeat);
// selectFeat.getFeatures().remove(toDeleteFeat);
// selectFeat.getFeatures().on("change:length", function (e) {
selectFeat.on("select", function (e) {
transactWFS("delete", e.target.item(0));
});
wfsSource.removeFeature(toDeleteFeat);
selectFeat.getFeatures().remove(toDeleteFeat);
} else
window.alert("Please select a layer first :" + selectedFeat.getLength());
}
Document.getElementById("delete").addEventListener("click", function () {
deleteFeatures();
})
トランザクション機能 -
////////transact function //////////////
let transactWFS = function (p, f) {
let WFSTSerializer = new ol.format.WFS();
let formatGML = {
featureNS: "Flori",
featureType: ["floriii"],
srsName: "urn:x-ogc:def:crs:EPSG:4326", //kshtu eshte formati i xml
//outputFormat: "application/json",
//format_options='callback:loadFeatures'
};
switch (p) {
case "insert":
node = WFSTSerializer.writeTransaction([f], null, null, formatGML);
break;
case "update":
node = WFSTSerializer.writeTransaction(null, [f], null, formatGML);
break;
case "delete":
node = WFSTSerializer.writeTransaction(null, null, [f], formatGML);
break;
}
let serializer = new XMLSerializer();
let featString = serializer.serializeToString(node);
console.log(node);
console.log(featString);
let request = new XMLHttpRequest();
request.open("POST", "http://localhost:8080/geoserver/ows");
request.setRequestHeader("Content-Type", "text/xml");
//console.log(request);
request.send(featString);
};
Openlayers Wfs- 機能の削除でトランザクションの問題が発生しました。応答に削除済みと表示されているため、機能のプロパティに何かが欠けているようです。