Editing Geoserver maps with Openlayers

In the previous article, we have viewed our map which is broadcast on Geoserver. Now we’re going to do a study on how to edit geospatial data on this map or how to draw a new point, line, or polygon.

WFS-T will be used for sending the changes we made on the map to the Geoserver side, and operations will be done with the command writeTransaction on Openlayers. But unlike the previous article, we will use a different Geoserver server, but the logic will be exactly the same.

Let’s talk a little about the WFS-T part which I didn’t mention before in the basic concepts. Unlike the WFS we know, Transactional allows to make transactional arrangements on the data. The WFS-T allows geometric properties to be added, updated and erased on the aforementioned data.

The writeTransaction command we will use on the code side takes four parameters in total. The first three represent the data to be added, updated or deleted, and the fourth parameter represents the GML format feature type, projection, and namespace data.

var transactWFS = function (mode, f) { 
var node;
switch (mode) {
case 'insert': node = formatWFS.writeTransaction([f], null, null, formatGML); break;
case 'update': node = formatWFS.writeTransaction(null, [f], null, formatGML); break;
case 'delete': node = formatWFS.writeTransaction(null, null, [f], formatGML); break;
}
var payload = xs.serializeToString(node); $.ajax('https://gsx.geolytix.net/geoserver/geolytix_wfs/ows', { service: 'WFS', type: 'POST', dataType: 'xml', processData: false, contentType: 'text/xml', data: payload }).done(function() { sourceWFS.clear(); }); };

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s