[Geoserver-users] WFS-T

Hi all,
Can someone please tell me whats missing from my code to get WFS-t to commit changes.
The demo works fine and my example works fine up to saving changes to file when an extra line is added.The data is added from postgreSQl database with PostGIS.

var roads = new OpenLayers.Layer.WFS(
“Track”,
“/geoserver/wfs”,
{typename: ‘topp:ttlines’},
{
typename: ‘topp:ttlines’,
featureNS: ‘http://www.openplans.org/topp’,
extractAttributes: false
}
);
roads.style = OpenLayers.Util.applyDefaults({strokeColor: “#ff0000”},
OpenLayers.Feature.Vector.style[“default”]);

map.addLayers([tiled, untiled, roads]);

var panel = new OpenLayers.Control.Panel(
{displayClass: ‘olControlEditingToolbar’}
);

var drawLine = new OpenLayers.Control.DrawFeature(
roads, OpenLayers.Handler.Path,
{displayClass: ‘olControlDrawFeaturePath’}
);
drawLine.featureAdded = function(feature) {
feature.layer.eraseFeatures([feature]);
// cast to multilinestring
feature.geometry = new OpenLayers.Geometry.MultiLineString(
feature.geometry
);
feature.style.strokeColor = “#ff0000”;
feature.state = OpenLayers.State.INSERT;
feature.layer.drawFeature(feature);
}

panel.addControls(
[new OpenLayers.Control.Navigation(), drawLine]
);
map.addControl(panel);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.zoomToExtent(
new OpenLayers.Bounds(2629421.7940751617, 6192776.755018141,
2633541.55790017, 6195366.924973875)
);
}

OpenLayers WFS-T demo: Tasmania cities and roads

Save Roads

Many Thanks
Chris

Hi Chris,

On Wednesday 29 April 2009 22:18:38 chris Wild wrote:

Hi all,
Can someone please tell me whats missing from my code to get WFS-t to
commit changes.
The demo works fine and my example works fine up to saving changes to file
when an extra line is added.The data is added from postgreSQl database with
PostGIS.

Do you really want to write changes to a file? Don't you want to save it back
into PostGIS database?

For writing changes back to the database, I added a new
OpenLayers.Control.Button. When this is pushed all changes to the layer will
be written via WFS-T to the database. Maybe this could help you:

wfs = new OpenLayers.Layer.WFS(
        "Rohr-Graben-Damm",
        "http://beige.rgb:8080/geoserver/wfs",
        { typename: 'topp:rohre_graben_damm' },
        {
            typename: 'rohre_graben_damm',
            featureNS: 'http://www.openplays.org/topp’,
            extractAttributes: false,
            commitReport: function(str) {
                storage.removeFeatures(storage.features);
            }
        }
    );

var save = new OpenLayers.Control.Button({
        trigger: OpenLayers.Function.bind(wfs.commit, wfs),
        displayClass: "olControlSaveFeatures"
    });

            var roads = new OpenLayers.Layer.WFS(
                "Track",
                "/geoserver/wfs",
                {typename: 'topp:ttlines'},
                {
                    typename: 'topp:ttlines',
                    featureNS: 'http://www.openplans.org/topp’,
                    extractAttributes: false
                }
            );
            roads.style = OpenLayers.Util.applyDefaults({strokeColor:
"#ff0000"},
                    OpenLayers.Feature.Vector.style["default"]);

            map.addLayers([tiled, untiled, roads]);

            var panel = new OpenLayers.Control.Panel(
                {displayClass: 'olControlEditingToolbar'}
            );

            var drawLine = new OpenLayers.Control.DrawFeature(
                roads, OpenLayers.Handler.Path,
                {displayClass: 'olControlDrawFeaturePath'}
            );
                drawLine.featureAdded = function(feature) {
                feature.layer.eraseFeatures([feature]);
                // cast to multilinestring
                feature.geometry = new OpenLayers.Geometry.MultiLineString(
                    feature.geometry
                );
                feature.style.strokeColor = "#ff0000";
                feature.state = OpenLayers.State.INSERT;
                feature.layer.drawFeature(feature);
            }

            panel.addControls(
                [new OpenLayers.Control.Navigation(), drawLine]
            );
            map.addControl(panel);
            map.addControl(new OpenLayers.Control.LayerSwitcher());
            map.zoomToExtent(
                new OpenLayers.Bounds(2629421.7940751617,
6192776.755018141, 2633541.55790017, 6195366.924973875)
            );
        }
    </script>
  </head>
  <body onload="init()">
    <h3>OpenLayers WFS-T demo: Tasmania cities and roads</h3>
    <a href="#" onclick="map.layers[2].commit();return false">Save
Roads</a> <div id="map"></div>
  </body>
</html>

Many Thanks
Chris

Best regards,
Ingo

--
Ingo Weinzierl OpenPGP key: 0x2D2E2573
http://www.intevation.de/
Intevation GmbH, Neuer Graben 17, 49074 Osnabrück; AG Osnabrück, HR B 18998
Geschäftsführer: Frank Koormann, Bernhard Reiter, Dr. Jan-Oliver Wagner