Reputation: 1724
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 method:
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 mouse.
saveStrategy.save();
the second method work bu the first method dosn't work.
I need first method.
how can I do?
Upvotes: 2
Views: 1715
Reputation: 1724
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).
Upvotes: 1