Hi,
I solved the problem. I wrote different typename for the same WFS layer ;-(
Now, I'd like to implement also UPDATE and DELETE functions trought WFS-T on all my features. At the moment, only UPDATE works fine but only for Polygon layer.
This is my code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="/geoserver/style.css" type="text/css" />
<style type="text/css">
body {
margin: 1em;
align: center;
}
#map {
width: 800px;
height: 475px;
border: 1px solid black;
}
</style>
<script src="openlayers/OpenLayers.js"></script>
<script src='http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAQ7O6ISk_yCoR4rsoNpu2yRQWqUa-fjQtVNT-NyOCg5sW_7idSBTyTXe4Vyv_Q6e4QRJOFOIkmbRmWg’></script>
<script type="text/javascript">
OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;
var options = {
maxExtent: new OpenLayers.Bounds(12.454,36.591,15.590,38.351)
};
var map;
function init(){
map = new OpenLayers.Map('map',options);
var gsat = new OpenLayers.Layer.Google(
"Google Sattelite",
{type: G_HYBRID_MAP}
);
var punto = new OpenLayers.Layer.WFS(
"Elementi puntuali",
"/geoserver/wfs",
{typename: 'topp:poi'},
{
typename: 'poi',
featureNS: 'http://www.openplans.org/topp’,
extractAttributes: false
}
);
"Elementi lineari",
"/geoserver/wfs",
{typename: 'topp:linea'},
{
typename: 'linea',
featureNS: 'http://www.openplans.org/topp’,
extractAttributes: false
}
);
var poligono = new OpenLayers.Layer.WFS(
"Elementi poligonali",
"/geoserver/wfs",
{typename: 'topp:poligono'},
{
typename: 'poligono',
featureNS: 'http://www.openplans.org/topp’,
extractAttributes: false
}
);
if (!poligono.writer) {
poligono.writer = new
OpenLayers.Format.WFS({layerName:'topp:poligono'},poligono);
}
linea.style.strokeColor = "#ff0000";
punto.style.strokeColor = "#0000ff";
poligono.style.strokeColor = "#0000ff";
map.addLayers([gsat, linea, punto, poligono]);
var panel = new OpenLayers.Control.Panel(
{displayClass: 'olControlEditingToolbar'}
);
var drawPoint = new OpenLayers.Control.DrawFeature(
punto, OpenLayers.Handler.Point,
{displayClass: 'olControlDrawFeaturePoint'}
);
drawPoint.featureAdded = function(feature) {
feature.layer.eraseFeatures([feature]);
// cast to multipoint
feature.geometry = new OpenLayers.Geometry.MultiPoint(
feature.geometry
);
feature.style.strokeColor = "#0000ff";
feature.state = OpenLayers.State.INSERT;
feature.layer.drawFeature(feature);
}
var drawLine = new OpenLayers.Control.DrawFeature(
linea, 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);
}
var drawPolygon = new OpenLayers.Control.DrawFeature(
poligono, OpenLayers.Handler.Polygon,
{displayClass: 'olControlDrawFeaturePolygon'}
);
drawPolygon.featureAdded = function(feature) {
feature.layer.eraseFeatures([feature]);
// cast to multipoint
feature.geometry = new OpenLayers.Geometry.MultiPolygon(
feature.geometry
);
feature.style.strokeColor = "#0000ff";
feature.state = OpenLayers.State.INSERT;
feature.layer.drawFeature(feature);
}
onModificationStart: function(feature) {
OpenLayers.Console.log("start modifying", feature.id);
},
onModification: function(feature) {
OpenLayers.Console.log("modified", feature.id);
},
onModificationEnd: function(feature) {
OpenLayers.Console.log("end modifying", feature.id);
feature.state = OpenLayers.State.UPDATE;
},
onDelete: function(feature) {
OpenLayers.Console.log("delete", feature.id);
}
};
var modify = new OpenLayers.Control.ModifyFeature(
poligono, modifyOptions);
map.addControl(modify);
modify.activate();
panel.addControls(
[new OpenLayers.Control.Navigation(), drawPoint, drawLine, drawPolygon]
);
map.addControl(panel);
map.addControl(new OpenLayers.Control.LayerSwitcher());
//map.addControl(new OpenLayers.Control.OverviewMap());
map.zoomToExtent(
new OpenLayers.Bounds(12.454,36.591,15.590,38.351)
//new OpenLayers.Bounds(145.51045,-44.0,149.0,-40.5)
);
}
</script>
</head>
<body onload="init()">
<h3>GeoEdit Demo</h3>
<a href="#" onclick="map.layers[1].commit();return false">Salva Elementi Lineari</a><br />
<a href="#" onclick="map.layers[2].commit();return false">Salva Elementi Puntuali</a><br />
<a href="#" onclick="map.layers[3].commit();return false">Salva Elementi Poligonali</a><br />
<div id="map"></div><br />
</body>
</html>
I'd like to use UPDATE for each feature, but if i define for example something as:
var modifyl = new OpenLayers.Control.ModifyFeature(
linea, modifyOptions);
map.addControl(modifyl);
modifyl.activate();
It doesn't work. Why?
Any idea for DELETE in a similar way ?
Thanks!
--
Ing. Fabio D'Ovidio
INOVA Open Solutions s.r.l.
Web : http://www.inovaos.it
Tel.: 081 197 57 600
mail: fabiodovidio@anonymised.com