Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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 ?

share|improve this question

2 Answers 2

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

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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