Geographic Information Systems Asked by Marcus Junius Brutus on March 19, 2021
When a user modifies the geometry of a feature on my map, I am using WFS to write the new modified feature to the GeoServer. I have verified that this works: the modified geometry is indeed saved in the database.
Also the server responds with an XML payload that, inside a <wfs:TransactionSummary>
supplies the correct number of updates (1), deletes (0) and insertions (0). I know that by inspecting the "Network" tab on my browser’s developer console.
My question is how to parse this response in JavaScript using the open layers library. I have found the readTransactionResponse method on the ol/format/WFS
class but I am not getting the results I expected; instead I get an empty object ({}
).
Here’s the code:
const featureRequest = wfs.writeTransaction(
[], // inserts
[feature], // updates
[], //deletes
{
srsName: 'EPSG:3857',
featureNS: 'https://geoserver.anon.com/',
featurePrefix: 'coredb',
featureType: 'eae_field_geospatial_data'
});
return fetch('https://geoserver.anon.com/geoserver/coredb/ows', {
method: 'POST',
body: new XMLSerializer().serializeToString(featureRequest)
}).then( (response) => {
const tr = wfs.readTransactionResponse(response);
console.log(tr);
return tr;
});
The above code prints {}
on the console.
Any ideas?
That was really silly of me. Response
is a ReadableStream
so you have to do a further response.text()
to get the string value (or response.json()
if you know it's JSON and you wish to parse it). The below works (I've get the original TypeScript annotations but they don't come into play):
return fetch('https://geoserver.anon.com/geoserver/coredb/ows', {
method: 'POST',
body: new XMLSerializer().serializeToString(featureRequest)
}).then( (response: Response) => {
return response.text(); // response is a Response object in this block
}).then( (response_as_string: string) => {
// response_as_string is a string in this block
}
Correct answer by Marcus Junius Brutus on March 19, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP