2

I want to add a point and then with WFS-T, save this to db.

I work with Openlayers and GeoServer.

saveStrategy = new OpenLayers.Strategy.Save();

wfs = new OpenLayers.Layer.Vector(
"WFS Vectore",
{
    strategies: [new OpenLayers.Strategy.BBOX(), saveStrategy],
    projection: new OpenLayers.Projection("EPSG:4326"),
    protocol: new OpenLayers.Protocol.WFS({
        version: "1.1.0",
        srsName: "EPSG:4326",
        url: "http://localhost:8080/geoserver/iran/wms?service=WFS",
        featureType: "population_utf-8",
        featureNS: "http://iran.kadaster.org",
        geometryName: "geom"
    })
});

I add point with two methods:

1.

wfs.addFeatures([new OpenLayers.Feature.Vector(
    new OpenLayers.Geometry.Point(
        (Math.floor(Math.random() * 360) - 180),
        (Math.floor(Math.random() * 180) - 90)
    )
)]);
saveStrategy.save();

2.

var drawFeatureController = new OpenLayers.Control.DrawFeature(wfs, OpenLayers.Handler.Point);

And then add a point with the mouse:

saveStrategy.save();

The second method works but the first method doesn't.

I need the first method.

How can I do this?

update: enter image description here

2
  • 1
    Inspect the http traffic with Fiddler or something similar and add the actual WFS-T request into your question. It may also reveal the difference and solve your problem.
    – user30184
    Aug 20, 2014 at 6:27
  • 1
    The payload does not show any content to insert with WFS-T transaction request. You have some demo requests available from GeoServer UI, see example from WFS_transactionInsert.xml. It has wrong coordinates for EPSG:4326 but don't care about it. And use WFS 1.0.0 for getting less troubles.
    – user30184
    Aug 20, 2014 at 7:05

1 Answer 1

2

when you add a point with new OpenLayers.Control.DrawFeature(wfs, OpenLayers.Handler.Point), by default feature state set to "Insert" but when you add a point with vectorLayer.addFeatures() command, the feature state is null.

when OpenLayers wants to save change, it see to the state of the feature, and you have to set the added feature state to "Insert"(case-sensitive).

Ok sir?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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