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.
controlPoint = function (feature) {
                        alert(feature);
                        pointNumber = 1;
                        draw.deactivate();
                        noktasil(feature);

                    };
                     draw = new OpenLayers.Control.DrawFeature(
                        wfs_layer, OpenLayers.Handler.Point, 
                        {
                            title: "Draw Feature",
                            displayClass: "olControlDrawFeaturePolygon",

                            multi: true,

                        }
                        );
                     draw.events.register("featureadded", ' ', controlPoint);

That's my codes for creating new feature, it works. But i want to delete feature without click. And as you can see, i store feature which i create and send it for deleting.

function noktasil(feature) {
                    // if feature doesn't have a fid, destroy it
                    var sil = new DeleteFeature(wfs_layer, { title: "Delete Feature" });
                    sil.noktasil(feature);

                }

                //set up the modification tools
                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 }
                        );
                    },
                    noktasil: 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);
                        }
                    },
                    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"
                }

);

Everythings is same with clickFeature. i wrote new function and i call it and i give this function feature which i stored. but i gave this error :Uncaught TypeError: Object # has no method 'destroy' How can i do that ?

share|improve this question
add comment

1 Answer 1

 draw.events.register("featureadded", this, function (e) {
                     alert(e.feature);
                     pointNumber = 1;
                     draw.deactivate();
                     noktasil(e.feature);
                 });

i wrote this codes and it's fine, works

share|improve this answer
add comment

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.