3

Below is my code which i am using for modifying features and drawing new features.

saveStrategy = new OpenLayers.Strategy.Save();
saveStrategy.events.register('success', null, ChangesSuccess);
saveStrategy.events.register('fail', null, ChangesFailed);

wfs = new OpenLayers.Layer.Vector("Edit Vagmitt Polyline", {

    styleMap: StyleMap,
    eventListeners: {
        "featuresadded": ZoomToData
    },
    strategies: [new OpenLayers.Strategy.Fixed(), saveStrategy],
    protocol: new OpenLayers.Protocol.WFS({
        url: GEOSERVER_WFS,
        featureType: "new_Vagmitt_polyline",
        featureNS: "http://www.openplans.org/workspace",
        geometryName: "the_geom",
        srsName: "EPSG:900913",
        version: "1.1.0",
        extractAttributes: true,
        isBaseLayer: false,
        visibility: true
    })

});

new OpenLayers.Control.DrawFeature(wfs, OpenLayers.Handler.Path, {displayClass: 'lineButton', title: 'Draw new line feature', handlerOptions: {style: sty}});

new OpenLayers.Control.ModifyFeature(wfs, {title: 'Edit line feature'}); The code works fine for modifyFeature control, but its gives error on save strategy when i draw a new feature.

The changes are also saved back to Geoserver when i modify the feature (triggers ChangesSuccess). but in case of DrawFeature control, saveStrategy triggers ChangesFailed function.

I could not understand, why ModifyFeature works but DrawFeature does't work. Can anybody explain, where is the problem ?

2 Answers 2

3

Probably you missed to set the feature's state to INSERT. Here is an example code:

var geom = new OpenLayers.Geometry.Point(x, y);
var feature = new OpenLayers.Feature.Vector(geom);
feature.state = OpenLayers.State.INSERT;

See this OpenGeo workshop for a complete example:

http://workshops.opengeo.org/geoext/wfs/wfst.html

0

Can you provide more information about the error when saving a new feature, please?

Also take a look at the response for the initial XHR request of your WFS layer.

Your Answer

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

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