[OpenLayers-Users] WFS-T example

Dipl. Inf. Carsten Eider eider at fh-bingen.de
Thu Jul 17 04:47:42 EDT 2008


Hi folks,
here are some code-snippets: I am working on a openlayers based 
geoEditor, just requiring a java-backend to split or join polygons:

   1. Loading data
      use a GML-Layer to get the data from your wfs-t server


      layers['schlaege']=new
      OpenLayers.Layer.GML("Schläge","/geoserver164a/wfs?request=GetFeature&typeName=ms:schlaege&outputformat=text/xml;
      subtype=gml/2.1.2",{layerName:'schlaege',typeName:'schlaege',outputFormat:'text/xml;
      subtype=gml/2.1.2',formatOptions:{xy:false},styleMap:styleMaps['schlaege']});

   2. Manipulating data
      Use modifycontrol or drawfeatuer-control to edit or add new
      elements, use event such as featuremodified to set feature.state

      this.layer.events.on({"featuremodified":this.featureModified});
      GeoEditor.prototype.featureModified=function(object)
      {           
          if(object.feature==null ||
      object.feature.state!=OpenLayers.State.INSERT)
              object.feature.state=OpenLayers.State.UPDATE;
      }

      Pay attention whether you want to delete a feature
      Remove feature from layer and store it into a seperate array
      within your layer

      GeoEditor.prototype.addDeletedFeature=function(layer,feature)
      {       
          if(feature.fid!=null)
          {
              feature.state=OpenLayers.State.DELETE;
              if(layer.deletedFeatures==null)
                  layer.deletedFeatures=[];
              this.layer.deletedFeatures.push(feature);
          }
          else
              feature.destroy();
      }

   3. Storing
      You can use a Format.WFS to create the required xml-structe, but
      it is a bit tricky to configure, look at "layername"

      //Schlaege speichern
          var _writer=new
      OpenLayers.Format.WFS({layerName:'ms:schlaege',featureNS:'http://mapserver.gis.umn.edu/mapserver',featureName:'schlaege',geometryName:'the_geom'},layers['schlaege']);
          //_writer.featureName='schlaege';
          //tmpFeature=feature;   
          var _tmpFeatures=layers['schlaege'].features;
      //Adding deleted features
          if(layers['schlaege'].deletedFeatures!=null)
          {       
              for(_i=0;_i<layers['schlaege'].deletedFeatures.length;_i++)
              {
                  _tmpFeatures.push(layers['schlaege'].deletedFeatures[_i]);
              }       
          }                   
          var _gml=_writer.write(_tmpFeatures);  
          //alert(_gml);
          //prompt("",_gml);   
          var url = "/geoserver164a/wfs/";   
          new OpenLayers.Ajax.Request(url,
          {   method: 'post',
              postBody: _gml,
              asynchronous: false,
              onComplete: this.commitSuccessSchlaege,
              onFailure: this.commitFailure
          }   
      ); 

GeoEditor.prototype.commitSuccessSchlaege=function(request)
{       
    var response = request.responseText;
    var doc = request.responseXML;       
    if (response.indexOf('SUCCESS') != -1) {
        //alert("Schlaege:"+OpenLayers.i18n("commitSuccess", 
{'response':response}));           
        var _fidCounter=0;
        var _fids=doc.getElementsByTagName("FeatureId");   
        for(var i = 0; i < layers['schlaege'].features.length; i++) {
            
if(layers['schlaege'].features[i].state==OpenLayers.State.INSERT)
            {               
                
layers['schlaege'].features[i].fid=_fids[_fidCounter].getAttribute("fid");
                _fidCounter++;
            }           
            layers['schlaege'].features[i].state = null;
            if(layers['schlaege'].deletedFeatures!=null)
            {              
                for(_i=0;_i<layers['schlaege'].deletedFeatures.length;_i++)
                {
                    layers['schlaege'].deletedFeatures[_i].destroy();
                }
                layers['schlaege'].deletedFeatures.length=0;
            }   
        }
    } else if (response.indexOf('FAILED') != -1 ||
        response.indexOf('Exception') != -1) {
        alert("Schlaege:"+OpenLayers.i18n("commitFailed", 
{'response':response}));
    }   
}

Alexandre Dubé schrieb:
> Hi Fabio,
>
>   That would be most appreciated.  Indika is also looking forward to see 
> an example to get wfs-t features working.
>
>
> Fabio D'Ovidio wrote:
>   
>> If u want,
>> I developed something like taht some times ago ...
>>
>> Alexandre Dubé ha scritto:
>>     
>>> Hi everyone,
>>>
>>>   Does anybody have a WFS-T example to share ?  I would like to see 
>>> how to use a WFS layer, modify it and post my changes to a WFS server.
>>>
>>>   Thanks,
>>>
>>>   
>>>       
>
>
>   

-- 
Mit freundlichen Grüßen / Yours faithfully
Carsten Eider

Dipl. Inf. (FH)

Kompetenzzentrum für Innovative Informationssysteme

c/o Fachhochschhule Bingen / University of applied sciences Bingen

Berlinstraße 109
55411 Bingen

Tel: +49 (0) 6721 / 409-179
Fax: +49 (0) 6721 / 409-158
email: eider at fh-bingen.de
Internet: iis.fh-bingen.de 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://openlayers.org/pipermail/users/attachments/20080717/84082284/attachment.htm 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: eider.vcf
Type: text/x-vcard
Size: 330 bytes
Desc: not available
Url : http://openlayers.org/pipermail/users/attachments/20080717/84082284/attachment.vcf 


More information about the Users mailing list