I want to edit object on WFS layer but have one problem. I use OpenLayers.Control.ModifyFeature(myVecLayer)
to editing.By the logic i do this.
- Press button and create WFS layer with chosen object
- Add
OpenLayers.Control.ModifyFeature
to map controls and activate this - Edit object
- Press button again and remove WFS layer with my object, deactivate
OpenLayers.Control.ModifyFeature
control. Select next object (or same object) and do "1", "2"
And object not editing.
But if I do not remove layer after editing, but just add new WFS layer to mapOpenLayers.Control.ModifyFeature
control works
My code:
function ff(){
if(counter==0){
//WFS
var myStyle = OpenLayers.Util.extend({},
OpenLayers.Feature.Vector.style['default']);
myStyle.strokeWidth = 1.5;
myStyle.strokeColor = "#ff0000";
myStyle.fillOpacity = 0.1;
OpenLayers.ProxyHost = "proxy.cgi?url=";
var renderer = OpenLayers.Util.getParameters(window.location.href).renderer;
renderer = (renderer) ? [renderer] : OpenLayers.Layer.Vector.prototype.renderers;
myVecLayer = new OpenLayers.Layer.Vector("Редактируемый участок", {
strategies: [new OpenLayers.Strategy.BBOX(), new OpenLayers.Strategy.Save()],
style: myStyle,
protocol: new OpenLayers.Protocol.WFS({
version: "1.0.0",
srsName:"EPSG:900913",
url: "http://localhost:8080/geoserver/wfs",
featureType: "filedata",
featureNS: "http://www.opengeospatial.net/cite",
defaultFilter : new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.EQUAL_TO,
property: 'id',
value: "162",
})
}),
renderers: renderer
})
map.addLayers([myVecLayer]);
if(ppp==null){
if (edit==null){
edit = new OpenLayers.Control.ModifyFeature(myVecLayer);
map.addControl(edit);
ppp=map.getControlsByClass("OpenLayers.Control.ModifyFeature");
}
alert(ppp);
}
// ppp.autoActivate=true;
for(var i=0;i ppp[i].activate();
alert("2 "+ppp[i].active);
}
counter=1;
}
Its will nice if u help.
Answer
OK. I find answer to my question. Just need to use filters.
//WFS
var myStyle = OpenLayers.Util.extend({},
OpenLayers.Feature.Vector.style['default']);
myStyle.strokeWidth = 1.5;
myStyle.strokeColor = "#ff0000";
myStyle.fillOpacity = 0.1;
OpenLayers.ProxyHost = "proxy.cgi?url=";
var renderer = OpenLayers.Util.getParameters(window.location.href).renderer;
renderer = (renderer) ? [renderer] : OpenLayers.Layer.Vector.prototype.renderers;
myVecLayer = new OpenLayers.Layer.Vector("Редактируемый участок", {
strategies: [new OpenLayers.Strategy.BBOX(), SS],
style: myStyle,
protocol: new OpenLayers.Protocol.WFS({
version: "1.0.0",
srsName:"EPSG:900913",
url: "http://localhost:8080/geoserver/wfs",
featureType: "filedata",
featureNS: "http://www.opengeospatial.net/cite",
defaultFilter : filter
}),
renderers: renderer
})
Filters+Editing
if(counter==0){
if(ppp==null){
if (edit==null){
edit = new OpenLayers.Control.ModifyFeature(myVecLayer);
map.addControl(edit);
ppp=map.getControlsByClass("OpenLayers.Control.ModifyFeature");
}
}
map.addLayers([myVecLayer]);
Ffilter = new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.EQUAL_TO,
property: 'id',
value: '170',
})
myVecLayer.filter=Ffilter;
myVecLayer.refresh({force: true});
for(var i=0;i ppp[i].activate();
}
counter=1;
}
else {
//FS.deactivate();
// SS.save();
//myVecLayer.destroyFeatures();
map.removeLayer(myVecLayer);
for(var i=0;i ppp[i].deactivate();
}
//ppp.deactivate();
counter=0;
}
No comments:
Post a Comment