[OpenLayers-Users] WFS-T example

Fabio D'Ovidio fabiodovidio at gmail.com
Thu Jul 17 05:43:21 EDT 2008


Here are samples using WFS-T and GeoServer.
You can draw, modify and delete features (e.g. lines).
I developed it for points, polygons, too and I have added FILTER on WFS 
requests passing a value in query string, configured also WMS 
GetFeatureInfo in order to query my WFS data on click.
Now I am developing a module to create dinamically GeoRSS (including GML 
as geometries) by querying these features in geoserver as WFS Service 
and fill them with different colours respect some attribute values..

Hope this help!

           map = new OpenLayers.Map( 'map' ,
            { controls: [] , 'numZoomLevels':19});
           
         
            ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
            "http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'}
           
          
            );

          
           
            var linea = new OpenLayers.Layer.WFS(
                "Elementi lineari",
                "/geoserver/wfs",
                {typename: 'topp:linea'},
                {
                    typename: 'linea',
                    featureNS: 'http://www.openplans.org/topp',
                    extractAttributes: false
                }
            );
           
          
           
            if (!linea.writer) {
            poligono.writer = new
            OpenLayers.Format.WFS({layerName:'topp:linea'},linea);
            }
           
         
           
            linea.style.strokeColor = "#0000ff";

            map.addLayers([ol_wms, linea]);


            var panel = new OpenLayers.Control.Panel(
                {displayClass: 'olControlEditingToolbar'}
            );
  
            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.style.strokeWidth = "5";
                feature.style.strokeOpacity = "0.75";
                feature.state = OpenLayers.State.INSERT;
                feature.layer.drawFeature(feature);
              
            }

             var modifyOptions = {
                 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);                   
                
                 },
                 onSelect: function(feature){
                 OpenLayers.Console.log("select", 
feature.id);                   
                 feature.state = OpenLayers.State.DELETE;
                
                 }
                
                 };
           
      
        controls = {
               
               
                dellin: new OpenLayers.Control.SelectFeature(linea,
                            modifyOptions),
                modifylin: new OpenLayers.Control.ModifyFeature(linea,
                                                             modifyOptions)
                                                                 
            };
           
            for(var key in controls) {
              map.addControl(controls[key]);
            
            }
           
           
            document.getElementById('noneToggle').checked = true;
           
          
            panel.addControls(
                [new OpenLayers.Control.Navigation(), drawLine]
            );
           
            map.addControl(panel);
            map.addControl(new OpenLayers.Control.LayerSwitcher());
            map.addControl(new OpenLayers.Control.MouseDefaults());
          
            map.addControl(new OpenLayers.Control.MousePosition());
            map.addControl(new OpenLayers.Control.PanZoomBar());
           
            map.zoomToExtent();
           

     
        }
       
 
        function toggleControl(element) {
            for(key in controls) {
                var control = controls[key];
                if(element.value == key && element.checked) {
                    control.activate();
                } else {
                    control.deactivate();
                }
            }
        }
       


-- 
Ing. Fabio D'Ovidio

INOVA Open Solutions s.r.l.
Web : http://www.inovaos.it
Tel.: 081 197 57 600
mail: fabiodovidio at gmail.com


Alexandre Dubé ha scritto:
> 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,
>>>
>>>   
>>
>
>




More information about the Users mailing list