我有以下问题:当我选择此功能时,如何获取功能的名称(例如点)?我有一个函数,我在其中声明了矢量图层和特征及其名称(部分代码):
function makeLayer(){
var objPoints = {station1: '68.0226656 36.9819691',station2: '66.895908 38.67347'};
// loop through the object with the points
for (var pointStat in objPoints ){
var pointCoords = objPoints[pointStat]
// seperate the coordinates lat and lon
var PosSpace=pointCoords.indexOf(' ');
var lonStr = pointCoords.substring(0,PosSpace);
var lon = +(lonStr); //convert string to number
var latStr = pointCoords.substring(PosSpace+1);
var lat = +(latStr);
// create the geometry
var point = new OpenLayers.Geometry.Point(lon,lat);
// assign the geometry to the feature
var feature_point = new OpenLayers.Feature.Vector(
point,
{name: pointStat} // name of label
);
// add the generated feature to the vector layer
this.layer.addFeatures(feature_point);
}
}
然后,我想要第二个功能,提醒我选择的功能的名称。像这样的东西:
function onFeatureSelect(){
alert(featureName);
}
有可能做这样的事情吗?我希望我的问题足够清楚。谢谢迪米特里斯