5

I write a Leaflet app which makes use of two plugins Leaflet.Draw and Leaflet.WFST. The first allows to create/edit/delete features, the second saves changes to my PostGIS database hosted by GeoServer.

Here is the code:

// Basemap
var map = new L.map('map').setView([57.704, 11.965], 6);
L.esri.basemapLayer('Topographic').addTo(map);

// Layer to draw in
var wfst = new L.WFST({
    url: 'http://localhost:8080/geoserver/ows',
    typeNS: 'drawing',
    typeName: 'Stockholm_points',
    crs: L.CRS.EPSG4326,
    geometryField: 'the_geom',
    showExisting: true,
}).addTo(map);


// Drawing
var drawControl = new L.Control.Draw({ 
    draw:{circle:false, circlemarker:false, rectangle:false,
          },
    edit:{featureGroup: wfst } });
map.addControl(drawControl);

map.on('draw:created', function (e) {
    var layer = e.layer;
    wfst.addLayer(layer)});

map.on('draw:edited', function (e) {
    var layers = e.layers;
    layers.eachLayer( function (layer) {
        wfst.editLayer(layer);
        });
});

// Save button
L.easyButton('fa-save', function () {
         wfst.save();
     }, 'Save changes').addTo(map);

It makes good job when I create a feature. However, when it comes to editing of existing features (for example, I want to drag a marker to another location or delete several markers), my changes don't get saved. Sometimes one of "deleted/edited" markers disappear/change location (as I would expect it to do), but never all them.

In GeoServer's log I see that my app communicates with server and sends requests to update features.. but with a little success.

What is wrong?

Here is a snippet from logfile. I tried to change location for three features and save edits. As a result only one feature appeared to be updated when I refresh my app.

2018-08-17 12:30:19,513 INFO [geoserver.wfs] - 
Request: transaction
    service = WFS
    version = 1.1.0
    baseUrl = http://localhost:8080/geoserver/
    group[0] = wfs:update=net.opengis.wfs.impl.UpdateElementTypeImpl@12d70e9 (filter: [ Stockholm_points.2 ], handle: null, inputFormat: <unset>, srsName: null, typeName: {http://geoserver.org/drawing}Stockholm_points)group[0] = wfs:update=net.opengis.wfs.impl.UpdateElementTypeImpl@12a9a36 (filter: [ Stockholm_points.3 ], handle: null, inputFormat: <unset>, srsName: null, typeName: {http://geoserver.org/drawing}Stockholm_points)group[0] = wfs:update=net.opengis.wfs.impl.UpdateElementTypeImpl@1d7334b (filter: [ Stockholm_points.4 ], handle: null, inputFormat: <unset>, srsName: null, typeName: {http://geoserver.org/drawing}Stockholm_points)
    update[0]:
        property[0]:
            name = {http://geoserver.org/drawing}the_geom
            value = POINT (10.832519531250002 59.91097597079679)
        filter = [ Stockholm_points.2 ]
        inputFormat = x-application/gml:3
        typeName = {http://geoserver.org/drawing}Stockholm_pointsupdate[0]:
        property[0]:
            name = {http://geoserver.org/drawing}the_geom
            value = POINT (11.206054687500002 59.66774058164963)
        filter = [ Stockholm_points.3 ]
        inputFormat = x-application/gml:3
        typeName = {http://geoserver.org/drawing}Stockholm_pointsupdate[0]:
        property[0]:
            name = {http://geoserver.org/drawing}the_geom
            value = POINT (10.173339843750002 59.567723306212955)
        filter = [ Stockholm_points.4 ]
        inputFormat = x-application/gml:3
        typeName = {http://geoserver.org/drawing}Stockholm_points
    releaseAction = ALL
2018-08-17 12:30:19,536 INFO [geoserver.wfs] - 
Request: getServiceInfo
2018-08-17 12:30:19,550 INFO [geoserver.wfs] - 
Request: getFeature
    service = WFS
    version = 1.1.0
    baseUrl = http://localhost:8080/geoserver/
    query[0]:
        filter = [ none ]
        srsName = EPSG:4326
        typeName[0] = {http://geoserver.org/drawing}Stockholm_points
    outputFormat = text/xml; subtype=gml/3.1.1
    resultType = results
  • I cannot help you but I want to commend you for writing such a great first question. A clear problem, a clean code snippet and you looked at logs. Welcome! – inc42 Aug 16 '18 at 21:23
  • 1
    Does the database change? if no can you add the request being sent and the response from geoserver to the question, also the actual log at debug level for a failing request would be useful. - if yes (the db does change) it is a Leaflet issue – Ian Turton Aug 17 '18 at 7:47
  • I have updated my question with log. Sometimes it applies changes in database, but only for one of edited features. Sometimes I can't see any changes. – Elena Klimenko Aug 17 '18 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.