0

我有以下问题:当我选择此功能时,如何获取功能的名称(例如点)?我有一个函数,我在其中声明了矢量图层和特征及其名称(部分代码):

  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);
    }

有可能做这样的事情吗?我希望我的问题足够清楚。谢谢迪米特里斯

4

1 回答 1

1

您可以使用 OpenLayers.Feature.Vector 中的属性:

http://dev.openlayers.org/docs/files/OpenLayers/Feature/Vector-js.html#OpenLayers.Feature.Vector.Properties

通过这种方式,您可以指定所需功能的名称,如下例所示:

https://gis.stackexchange.com/questions/40689/how-to-show-a-toolip-over-a-feature-with-openlayers

希望这可以帮助,

于 2013-09-11T10:41:41.503 回答