0

I'm using WFS-T in OpenLayers-5.0.3 according to here. I have created a feature and then sent a WFS request as follows:

In below code the program is getting WFS version 1.1.0 only, but I need to get the WFS-T in the version of 2.0.

<script>
        //var formatWFS = new ol.format.WFS();

        var formatGML = new ol.format.GML({
            featureNS : 'http://localhost:8080/geoserver/ilfs',
            featureType : 'ilfs:ilfs_parceldata',
            srsName: 'EPSG:3857',
            /* srsName : 'EPSG:32643' 'http://localhost:8080/geoserver/schemas/wfs/2.0/wfs.xsd' */
            schemaLocation : 'http://www.opengis.net/wfs/2.0 http://localhost:8080/geoserver/schemas/wfs/2.0/wfs.xsd' // \ http://localhost:8080/geoserver/ilfs/wfs/DescribeFeatureType?typename=ilfs:ilfs_parceldata'
        });
        console.log(formatGML);
        /* var formatWFS = new ol.format.WFS(); */
        var formatWFS = new ol.format.WFS({
            featureNS:'http://localhost:8080/geoserver/ilfs',
            featureType:'ilfs:ilfs_parceldata',
            version: '2.0.0',
            schemaLocation:'http://www.opengis.net/wfs/2.0 http://localhost:8080/geoserver/schemas/wfs/2.0/wfs.xsd'
        });

        var xs = new XMLSerializer();
        //var filter = "kid='111' ";
        var filter = null;

        var wfsSource = ILFS.GetBoundingBox(filter)
        var sourceWFS = wfsSource.source;

        var layerWFS = new ol.layer.Vector({
            source : sourceWFS
        });     

        var interaction;

        var interactionSelectPointerMove = new ol.interaction.Select({
            condition : ol.events.condition.pointerMove
        });

        var interactionSelect = new ol.interaction.Select({
            style : new ol.style.Style({
                stroke : new ol.style.Stroke({
                    color : '#FF2828'
                })
            })
        });

        var interactionSnap = new ol.interaction.Snap({
            source : layerWFS.getSource()
        });

        var map = new ol.Map(
        {
            target : 'map',
            controls : [],
            interactions : [ interactionSelectPointerMove,
                    new ol.interaction.MouseWheelZoom(),
                    new ol.interaction.DragPan() ],
            layers : [ layerWFS ],
            view : new ol.View({                
                center : [0,0],
                zoom : 14
            })
        });

        var bounds = [673562.512010076,1873273.77078815,675067.642255779,1875701.29118918]; 
        map.getView().fit(bounds, map.getSize());

        //wfs-t
        var dirty = {};
        var transactWFS = function(mode, f) {
            var node;
            switch (mode) {
            case 'insert':
                node = formatWFS.writeTransaction([ f ], null, null, formatGML/* {gmlOptions: formatGML, version : '2.0.0'} */);
                break;
            case 'update':
                node = formatWFS.writeTransaction(null, [ f ], null, formatGML);
                break;
            case 'delete':
                node = formatWFS.writeTransaction(null, null, [ f ], formatGML);
                break;
            }
            console.log(node);          
            var payload = xs.serializeToString(node);
            console.log(payload);
            $.ajax('http://localhost:8080/geoserver/wfs', {
                type : 'POST',
                dataType : 'xml',
                processData : false,
                contentType : 'text/xml',
                data : str,
                success: function(data) {
                    var result = formatWFS.readTransactionResponse(data);
                    console.log(result);
                    bootbox.alert('Results <br><br>' + result);
                    //f.setId(result.insertIds[0]);
                },
                error: function(e) {
                    var errorMsg = e? (e.status + ' ' + e.statusText) : "";
                    bootbox.alert('Error saving this feature to GeoServer.<br><br>' + errorMsg);
                },
                context: this
            }).done(function() {
                //bootbox.alert("done");
                //sourceWFS.clear();
            });
        };

        $('button').click(function() {
            $(this).siblings().removeClass('btn-active');
            $(this).addClass('btn-active');
            map.removeInteraction(interaction);
            interactionSelect.getFeatures().clear();
            map.removeInteraction(interactionSelect);

            switch ($(this).attr('id')) {

            case 'btnPoint':
                interaction = new ol.interaction.Draw({
                    type : 'Point',
                    source : layerWFS.getSource()
                });
                map.addInteraction(interaction);
                interaction.on('drawend', function(e) {
                    transactWFS('insert', e.feature);
                });
                break;

            default:
                break;
            }
        });
    </script>

The default version that OpenLayers works is "1.1.0", In this setting, I want to work with version "2.0.0". How can I set the version?

  • I have a feeling OpenLayers only supports WFS 1.0.0 or WFS 1.1.0, with 1.1.0 as the default. – nmtoken Jul 23 '18 at 10:53

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.