[OpenLayers-Dev] Error changes to save

David Middlecamp dmiddlecamp at azavea.com
Tue Feb 14 11:52:46 EST 2012


Hi Neelima,

  I'm not sure if anyone got back to you yet, but I'm guessing the issue
here might be that you need to configure your MapServer for WFS-T, and not
just WFS.  I'm not sure if you've done that step already, but I think
MapServer does not support transactional WFS (saving) out of the box.
 Instead you want to configure something like TinyOWS alongside MapServer
to do the saving to PostGIS for you.

You can see more on configuring MapServer to do this here:
http://mapserver.org/trunk/tinyows/openlayershowtotransactional.html

and there is a WFS-T example of OpenLayers here:
http://openlayers.org/dev/examples/wfs-protocol-transactions.html

I suspect your question might be better directed at one of the MapServer or
TinyOWS mailing lists, or at the OpenLayers Users mailing list.

Thanks,
David


On Tue, Feb 14, 2012 at 6:31 AM, Neelima Emmani <
neelima.emmani at iictechnologies.com> wrote:

>  Hi All,
>
> In openlayers,  I have a map with google layer and over that I am
> overlaying POSTGIS data as a WFS overlay. For this I am also using
> OpenLayers Editing tools, all the editing tools are working fine
> (drawpoint, line, modify, delete) except SAVE Button. When i say, SAVE it
> is showing me save failure alert message. Can any one suggest me how to mak
> eit success.
> My piece of code is as follows in .js file -
>
> var map;
>
>         function init() {
>             map = new OpenLayers.Map("map");
>
>         //GOOGLE MAP
>             var base = new OpenLayers.Layer.Google("Google Hybrid",
> {'type': G_HYBRID_MAP});
>             map.addLayer(base);
>
>         //VECTOR LAYER FOR PANEL
>             var vlayer = new OpenLayers.Layer.Vector("vlayer");
>             map.addLayer(vlayer);
>
>         // CREATE WFSLAYERS
>
>             //SAVE  STRATEGY
>             var saveStrategy = new OpenLayers.Strategy.Save();
>                 saveStrategy.events.register('start', null, saveStart);
>                 saveStrategy.events.register('success', null, saveSuccess);
>                 saveStrategy.events.register('fail', null, saveFail);
>
>         //style map for points
>             var styleMap = new
> OpenLayers.StyleMap(OpenLayers.Util.applyDefaults({fillColor: "CYAN",
> fillOpacity: 1, strokeColor: "black"},
>              OpenLayers.Feature.Vector.style["default"]));
>
>         // mock up a protocol for synchronous and successful commits
>             var wfs_protocol = new OpenLayers.Protocol.WFS({url:"
> http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w/apps/openlayers-2.10/examples/addline.map&SERVICE=WFS&VERSION=1.0.0&REQUEST=getfeature&TYPENAME=xxx",
>
>
>                                 featureType: "us1gc09m",
>                                 srsName: "EPSG:900913"});
>
>             var wfslayer = new OpenLayers.Layer.Vector("WFS", {styleMap:
> styleMap, strategies: [new OpenLayers.Strategy.Fixed(), saveStrategy],
> protocol: wfs_protocol});
>
>             map.addLayer(wfslayer);
>
>         //PANEL DEFINITION
>             var panel = new OpenLayers.Control.Panel(
>                             {'displayClass': 'customEditingToolbar'}
>                             );
>
>             var navigate = new OpenLayers.Control.Navigation({
>                              title: "Pan Map"
>                              });
>
>             var drawpath = new OpenLayers.Control.DrawFeature(
>                                 wfslayer, OpenLayers.Handler.Path,
>                                  {
>                                  title: "Draw Path",
>                                  displayClass: "olControlDrawFeaturePath",
>                                  multi: true
>                                  }
>                                 );
>
>             var drawpoint = new OpenLayers.Control.DrawFeature(
>                                 wfslayer, OpenLayers.Handler.Point,
>                                 {
>                                 title: "Add Point",
>                                 displayClass: "olControlDrawFeaturePoint",
>                                 multi: true
>                                 }
>                                 );
>
>                 //ADD POINT TO LAYER
>                 drawpoint.featureAdded = function(feature) {
>                     alert("draw point: " + feature.geometry);
>                 // cast to multipoint
>                 feature.geometry = new OpenLayers.Geometry.MultiPoint(
>                     feature.geometry
>                 );
>
>                 feature.state == OpenLayers.State.INSERT;
>                 this.layer.drawFeature(feature);
>                 saveStrategy.save(feature);
>             };
>             var edit = new OpenLayers.Control.ModifyFeature(wfslayer, {
>                                 title: "Modify Feature",
>                                 displayClass: "olControlModifyFeature"
>                                 });
>
>             //delete feature definition
>             var DeleteFeature = OpenLayers.Class(OpenLayers.Control, {
>             initialize: function(layer, options) {
>             OpenLayers.Control.prototype.initialize.apply(this, [options]);
>             this.layer = layer;
>             this.handler = new OpenLayers.Handler.Feature(
>             this, layer, {click: this.clickFeature}
>             );
>             },
>             clickFeature: function(feature) {
>              // if feature doesn't have a fid, destroy it
>             if(feature.fid == undefined) {
>             this.layer.destroyFeatures([feature]);
>             } else {
>             feature.state = OpenLayers.State.DELETE;
>             this.layer.events.triggerEvent("afterfeaturemodified",
> {feature: feature});
>             feature.renderIntent = "select";
>             this.layer.drawFeature(feature);
>             }
>             },
>             setMap: function(map) {
>             this.handler.setMap(map);
>             OpenLayers.Control.prototype.setMap.apply(this, arguments);
>             },
>             CLASS_NAME: "OpenLayers.Control.DeleteFeature"
>             });
>
>             var del = new DeleteFeature(wfslayer, {title: "Delete
> Feature"});
>
>             var save = new OpenLayers.Control.Button({
>                          title: "Save Changes",
>                          trigger: function() {
>                             if(edit.feature) {
>                                  edit.selectControl.unselectAll();
>                             }
>                             saveStrategy.save();
>                         },
>                         displayClass: "olControlSaveFeatures"
>                         });
>
>
>             panel.addControls([navigate, save, del, edit, drawpoint,
> drawpath]);
>             panel.defaultControl = navigate;
>
>             map.addControl(panel);
>             map.addControl(new OpenLayers.Control.MousePosition());
>             map.addControl(new OpenLayers.Control.LayerSwitcher());
>             map.zoomToMaxExtent();
>             map.setCenter(new OpenLayers.LonLat(-82, 28),5);
>         }
>
> //SAVESTART EVENT
>     function saveStart(event) {
>         alert('save layer start');
>     }
>
> //SAVESUCCESS EVENT
>     function saveSuccess(event) {
>         alert('Changes saved');
>     }
>
> //SAVEFAIL EVENT
>     function saveFail(event) {
>         alert('Error! Changes not saved');
>     }
>
>
>
>
>
> Eagerly waiting for reply and suggestions.
>
> With Regards,
> Neelima Emmani
>
> _______________________________________________
> Dev mailing list
> Dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-dev
>
>


-- 
David Middlecamp, Software Developer

Azavea  |  340 N 12th St, Ste 402, Philadelphia, PA
dmiddlecamp at azavea.com  | T 215.701.7688  | F 215.925.2663
Web azavea.com  |  Blog azavea.com/blogs  |  @dmiddlecamp
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-dev/attachments/20120214/51d9c697/attachment.html


More information about the Dev mailing list