Saving with WFS-T

Using a WFS-Transaction service usually requires less server-side configuration, but more considerations on the client side. OpenLayers 3 can write WFS-T requests; however, it is hard coded to support only Version 1.1.0. We can create a minimalistic WFS-T request with the following code:

var WFSTSerializer = new ol.format.WFS(); var featObject = WFSTSerializer.writeTransaction(this.getFeatures(), null, null, { featureType: 'ne:countries', featureNS: 'http://naturalearthdata.com', srsName: 'EPSG:3857' }); var serializer = new XMLSerializer(); var featString = serializer.serializeToString(featObject); var request = new XMLHttpRequest(); request.open('POST', 'myowsserver?SERVICE=WFS'); request.setRequestHeader('Content-Type', 'text/xml'); ...

Get Mastering OpenLayers 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.