[OpenLayers-Users] WFS-T not saving
Björn Höfling
bjoern.hoefling at gmail.com
Mon Feb 21 11:16:46 EST 2011
Dear list,
I'm trying to set up a simple WFS-Transactional example with GeoServer
as my WFS server for a Point Layer from a Shapefile.
WFS works: I can see the right points within my data's boundingbox.
But when I press the save button, the saveSuccess callback is fired,
but nothing gets saved.
The Problem seams to be that OpenLayer is sending no changes to the
server, GeoServer log says:
Request: transaction
handle = null
service = WFS
version = 1.1.0
baseUrl = http://localhost:8080/geoserver/
providedVersion = null
lockId = null
group = []
insert = []
update = []
delete = []
native = []
releaseAction = ALL
What's wrong here? Do I have to create or save my points in a
different way? Any idea?
Many thanks for your help,
Björn
Here is the html:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Using a Layer.Text to display markers</title>
<link rel="stylesheet" href="../ol/style/default/style.css" type="text/css" />
<link rel="stylesheet" href="../style.css" type="text/css" />
<script src="../ol/OpenLayers.js"></script>
<script src="../proj4js/proj4js.js"></script>
<script src="map.js"></script>
</head>
<body onload="init()">
<h1 id="title">OpenLayers example</h1>
<p id="shortdesc">Zoomed to Munich,WFS-T testing.</p>
<div id="map" class="smallmap"></div>
<div id="save"><button name="Save" onClick="doSave()"></button></div>
<div id="rnd" onClick="addRndPoint();" ><p>add Point</p></div>
</body>
</html>
And the JavaScript map.js:
var map, layer;
var saveStrategy;
var wgs84 = new OpenLayers.Projection('EPSG:4326');
var gk3 = new OpenLayers.Projection('EPSG:31467');
var wfs2;
var l = 11;
var r = 12;
var b = 48;
var t = 49;
var bounds = new OpenLayers.Bounds(l, b, r, t);
function init() {
//proxy, proj4
OpenLayers.ProxyHost = "/servletproxy-1.0-SNAPSHOT/?url=";
Proj4js.defs["EPSG:31467"] = "+proj=tmerc +lat_0=0 +lon_0=9 +k=1
+x_0=3500000 +y_0=0 +ellps=bessel +datum=potsdam +units=m +no_defs";
Proj4js.defs["EPSG:31468"] = "+proj=tmerc +lat_0=0 +lon_0=12 +k=1
+x_0=4500000 +y_0=0 +ellps=bessel +datum=potsdam +units=m +no_defs";
//create the map object
map = new OpenLayers.Map("map", {
controls : [ new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PanZoomBar(),
new OpenLayers.Control.LayerSwitcher(),
new OpenLayers.Control.Permalink(),
new OpenLayers.Control.ScaleLine(),
new OpenLayers.Control.MousePosition(), ]
});
// base layer
var base = new OpenLayers.Layer.WMS("OpenLayers WMS",
"http://tilecache.osgeo.org/wms-c/Basic.py", {
layers : "basic"
});
map.addLayer(base);
//visualize the extent
var boxes = new OpenLayers.Layer.Boxes("Boxes");
var box = new OpenLayers.Marker.Box(bounds);
boxes.addMarker(box);
map.addLayer(boxes);
//saveStrategy for the WFS-T layer
saveStrategy = new OpenLayers.Strategy.Save();
saveStrategy.events.register('start', null, saveStart);
saveStrategy.events.register('success', null, saveSuccess);
saveStrategy.events.register('fail', null, saveFail);
wfs2 = new OpenLayers.Layer.Vector("Punkte", {
projection : "EPSG:31467",
strategies : [ new OpenLayers.Strategy.BBOX(), saveStrategy ],
protocol : new OpenLayers.Protocol.WFS( {
version: "1.1.0",
srsName: "EPSG:31467",
url : "http://localhost:8080/geoserver/wfs",
featureType : "points",
featureNS : "http://sdi.mycompany.com/",
schema: "http://localhost:8080/geoserver/wfs/DescribeFeatureType?version=1.1.0&typename=mycompany:points"
})
});
map.addLayer(wfs2);
map.zoomToExtent(bounds);
};
function doSave() {
alert("Will starting to save after the click.");
saveStrategy.save();
}
function saveStart(event) {
alert('SaveStrategy: Starting to save.');
}
function saveSuccess(event) {
alert('SaveStrategy: Changes saved.');
}
function saveFail(event) {
alert('SaveStrategy: Error, changes not saved.');
}
function getRndPt() {
var x = l + Math.random() * (r - l);
var y = b + Math.random() * (t - b);
var geom = new OpenLayers.Geometry.Point(x, y);
var feature = new OpenLayers.Feature.Vector(geom);
feature.attributes.state = OpenLayers.State.INSERT;
return feature;
};
function addRndPoint() {
wfs2.addFeatures([getRndPt()]);
}
More information about the Users
mailing list