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.

I want to delete a feature attribute for example say grid completely from the map that is it has to be deleted from database. I am using OpenLayers 2.12, postgis 2.0 and postgresql 9.0. Please guide how to remove grid from database.

Below is my code

function loadMap() 
{




map = new OpenLayers.Map('map', {
          controls: [
               new OpenLayers.Control.PanZoom(),

               new OpenLayers.Control.Navigation()
           ]
       });

DeleteFeature = OpenLayers.Class(OpenLayers.Control, {
initialize: function( layr, sm) {
    OpenLayers.Control.prototype.initialize.apply(this, [sm]);
    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"
}) 

layer = new OpenLayers.Layer.WMS(
                    "Road", "http://localhost:8089/geoserver/IIRS1/wms",
                    {
                        height: '512',
                        width: '502',
                        LAYERS: 'IIRS1:india_road',
                        transparent: "true",
                        srs: 'EPSG:4326',
                        tiled: 'true',

                        format: 'image/png',
                        format_options: 'antialias:none'

                      //  tilesOrigin : map.maxExtent.left + ',' + map.maxExtent.bottom
                    },
                    {transitionEffect: 'resize',

                        buffer: 0,
                        displayOutsideMaxExtent: false,
                        visibility: false
                    }
                );                      
//Similarly I added OMS layer and other functions of zoom n navigate
//here is the delete function
 action = new GeoExt.Action({
        text: "Identify",
        control: new OpenLayers.Control.Button(),
        map: map,
        allowDepress: true, 
        iconCls: "icon-feature-identifyIcon",
        tooltip: "Identify",
        map: map,
        listeners: {
        click: function(){


      control = new OpenLayers.Control.GetFeature({
           protocol: OpenLayers.Protocol.WFS.fromWMSLayer(layer),
           box: true,
           hover: true,
           multipleKey: "shiftKey",
           toggleKey: "ctrlKey"
       });
       control.events.register("featureselected", this, function(e) {
           select.addFeatures([e.feature]);
  road_id = e.feature.attributes.road_name; // road_id contains the id of the road 
       //alert(road_id);

           del= new DeleteFeature(layer,road_id);
            alert("remoned");



 });
       control.events.register("featureunselected", this, function(e) {
       select.removeFeatures([e.feature]);
       });
       control.events.register("hoverfeature", this, function(e) {
       hover.addFeatures([e.feature]);
       });
       control.events.register("outfeature", this, function(e) {
       hover.removeFeatures([e.feature]);
       });

       map.addControl(control,del);
       control.activate(); 

    }                       

     }
    });
    actions["getfeatureinfo"] = action;
    toolbarItems.push(action);
    toolbarItems.push("-");
share|improve this question

closed as not a real question by iant, djq, Devdatta Tengshe, R.K., whuber Nov 23 '12 at 21:10

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

    
I'm not sure I understand the "grid" bit. Are you trying to remove one feature (e.g. a point or a line), an attribute on that feature (e.g. the name of the feature, or a description), or something else? –  BradHards Oct 22 '12 at 7:05
    
Also, does stackoverflow.com/questions/4091594/… address your need? If not, can you tell us more? –  BradHards Oct 22 '12 at 7:05
    
Say there is a shapefile of road. I imported it using postgis. it has road name road id and geom column in database postgresql. I want to delete a road with road_name name say '25' completely that is it should be deleted from map as well as from database, so how can I do it? –  aaliya Oct 22 '12 at 7:40
2  
So you want WFS-T (openlayers.org/dev/examples/wfs-protocol-transactions.html)? –  BradHards Oct 22 '12 at 7:41
2  
The link I provided shows the code running. I'm not able to write the solution for you - you will have to do the work here! If you have specific problems, please update the question - we can't see your screen, so "no result" isn't very informative. Please look at the link, decide if that does what you want, look at the source code (at the bottom of the page) and then come back and describe what doesn't work as you need it to. –  BradHards Oct 22 '12 at 8:55
show 8 more comments

1 Answer 1

An editor is not something you would want to implement from scratch given your current skill level. I suggest you use something like OpenLayers editor. Or the OpenGeo Suite's GeoExplorer. Or study the docs as @BradHards has said.

You can also try using GeoExt. OpenGeo has a great tutorial on making a WFS editor with GeoExt.

share|improve this answer
    
Thanks for ur answer but I have already tried what @BradHards has said. I am able to delete whatever feature i draw like polygons, line and point because they are temporary stored but I am not able to delete any feature from database (postgresql) which is my major problem. –  aaliya Oct 22 '12 at 11:54
    
On another note, have you been able to add features to your database using OpenLayers? –  R.K. Oct 22 '12 at 12:26
    
Not in database....transaction with database is the main issue. –  aaliya Oct 22 '12 at 14:39
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.