Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

  1. Press button and create WFS layer with chosen object
  2. Add OpenLayers.Control.ModifyFeature to map controls and activate this
  3. Edit object
  4. Press button again and remove WFS layer with my object, deactivate OpenLayers.Control.ModifyFeature control.
  5. 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 map OpenLayers.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.length;i++){
                                ppp[i].activate();
                                alert("2 "+ppp[i].active);
                            }

                            counter=1;

                }

Its will nice if u help.

share|improve this question
    
Or can someone tell me how to make new filter to WFS layer? –  Kliver Max Jul 23 '12 at 7:02

1 Answer 1

up vote 1 down vote accepted

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.length;i++){
                                ppp[i].activate();
                            }
                            counter=1;

                }
                else {
                    //FS.deactivate();
                //  SS.save();
                    //myVecLayer.destroyFeatures(); 
                    map.removeLayer(myVecLayer); 
                    for(var i=0;i<ppp.length;i++){
                                ppp[i].deactivate();
                            }
                    //ppp.deactivate();
                    counter=0;
                }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.