[OpenLayers-Dev] Error changes to save

Neelima Emmani neelima.emmani at iictechnologies.com
Tue Feb 14 06:31:14 EST 2012


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-dev/attachments/20120214/89af6fd1/attachment-0001.html


More information about the Dev mailing list