In my database table there are four fields(lat,lon,sensid,value).i am displaying a vector layer(point feature) by retrieving the lat, lon values from database. Now i want to display the value, whenever i click on the feature based on id. So how to get the feature id(database sensid) on click.I am getting lat lon values on click, but i need to get sensid.
my code is
var str_array =["8541652,3397019,TATM1", "8786758,3536158,TATM2"]
str_array = jsstr.split(';');
var a,b,c;
for (i = 0; i < str_array.length; i++) {
var text = str_array[i] ;
var str_coord = text.split(',');
a = parseFloat(str_coord[0]);
b = parseFloat(str_coord[1]);
c = parseFloat(str_coord[2]);
var feature=new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(a,b));
vectorLayer.addFeatures(feature);
mapPanel.map.addLayer(vectorLayer);
var selectCtrl = new OpenLayers.Control.SelectFeature(vectorLayer);
function createPopup(feature) {
popup1 = new GeoExt.Popup({
title: 'My Popup',
location: feature,
width:200,
html: '<div class="markerContent">'+feature.geometry.x +','+feature.geometry.y+'</div>',
maximizable: true,
collapsible: true,
anchorPosition: "auto"
});
// unselect feature when the popup
// is closed
popup1.on({
close: function() {
if(OpenLayers.Util.indexOf(vectorLayer.selectedFeatures,
this.feature) > -1) {
selectCtrl.unselect(this.feature);
}
}
});
popup1.show();
}
//create popup on "featureselected"
mapPanel.map.addControl(selectCtrl);
selectCtrl.activate();
}
vectorLayer.events.on({
featureselected: function(e) {
createPopup(e.feature);
}
});