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("-");

