1

I want to get multiple WFS features and edit

My Code

this.wfs = new OpenLayers.Layer.Vector("WFS-T" , {
        strategies: [new OpenLayers.Strategy.BBOX(), this.saveStrategy],
        projection:  new OpenLayers.Projection("EPSG:3857"),
        protocol:    new OpenLayers.Protocol.WFS({
            version:     "1.1.0",
            srsName:     "EPSG:3857",
            url:         "http://localhost:8080/geoserver/wfs",
            featureNS:   "http://localhost:8080/geoserver/mall",
            extractAttributes: true,
            featureType: ['stores' , 'store_point'],
            geometryName: 'geom'
        })

    });

But i can not edit features

Error Message :

<ows:ExceptionText>Feature type 'stores,store_point' is not available: </ows:ExceptionText>
  • what is your datastore called? – Ian Turton Dec 17 '15 at 11:59
  • It is Postgresql – Serhan Yavçin Dec 17 '15 at 12:02
  • but what is it's name in geoserver? – Ian Turton Dec 17 '15 at 12:14
  • sorry i don't get it. What do you men excatly ? – Serhan Yavçin Dec 17 '15 at 12:18
  • You are requesting features from a datastore - is it called 'stores' or 'point' or something else entirely – Ian Turton Dec 17 '15 at 12:18
2

You need to enable jsonp in your Geoserver to be able to post code

In order to edit you need the following code:

var formatWFS = new ol.format.WFS();

var formatGML = new ol.format.GML({
    featureNS: 'yourfeatureNS',
    featureType: 'stores',
    srsName: 'EPSG:3857'
});

var s = new XMLSerializer();

var sourceWFS = new ol.source.Vector({
    loader: function (extent) {
        $.ajax('http://localhost:8080/geoserver/wfs', {
            type: 'GET',
            data: {
                service: 'WFS',
                version: '1.1.0',
                request: 'GetFeature',
                typename: 'stores',
                srsname: 'EPSG:3857',
                bbox: extent.join(',') + ',EPSG:3857'
            }
        }).done(function (response) {
            sourceWFS.addFeatures(formatWFS.readFeatures(response));
        });
    },
    strategy: ol.loadingstrategy.bbox,
    projection: 'EPSG:3857'
});

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

var map = new ol.Map({
    target: 'map',
    layers: [
        new ol.layer.Tile({
            source: new ol.source.OSM({
                url: 'https://cartodb-basemaps-{a-d}.global.ssl.fastly.net/light_nolabels/{z}/{x}/{y}.png',
                opaque: false,
                attributions: []
            })
        }),
        layerWFS
    ],
    view: new ol.View({
        center: ol.proj.fromLonLat([-0.1, 51.50]),
        zoom: 13
    })
});

var interaction = new ol.interaction.Draw({
    type: 'Polygon',
    source: layerWFS.getSource()
});

map.addInteraction(interaction);

interaction.on('drawend', function (e) {
    $.ajax('http://localhost:8080/geoserver/wfs', {
        type: 'POST',
        dataType: 'xml',
        contentType: 'text/xml',
        data: s.serializeToString(formatWFS.writeTransaction([e.feature], null, null, formatGML))
    }).done();
});

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.