OpenLayers - 根据弹出文本添加到标记数组

时间:2012-09-26 20:16:27

标签: popup openlayers markers

我在OpenLayers中可能存在一个相当基本的问题,如果有人可以帮我解决这个问题,那将会非常棒。

我有一系列标记,每个标记应该有不同的弹出框文本。但是,我无法将相关文本应用于标记。我尝试通过另一个数组为弹出框的内容执行此操作。但是,我无法将正确的文本与标记相关联。这是我的代码:

var vs_locations = [
[13.045240, 47.8013271],
[13.145240, 47.8013271],
[13.245240, 47.8013271],
];

var popupContentHTML = [
"Text for marker with loc[0]",
"Text for marker with loc[1]",
"Text for marker with loc[2]"
];

function addVS(){

  for (var i = 0; i < vs_locations.length;i++){
    var loc = vs_locations[i];
    var feature = new OpenLayers.Feature(volksschulen, new OpenLayers.LonLat(loc[0],loc[1],loc[2]).transform(proj4326,proj900913));
    feature.closeBox = true;
    feature.data.icon = new OpenLayers.Icon('coffeehouse.png');
    feature.popupClass =  OpenLayers.Class(OpenLayers.Popup.FramedCloud, {
     'autoSize': true, 
    });
    marker = feature.createMarker();
    volksschulen.addMarker(marker);
    feature.data.popupContentHTML = ; //Here should be the text according to the marker
    feature.data.overflow = "auto";
    marker.events.register("mousedown", feature, markerClick);
    feature.popup = feature.createPopup(feature.closeBox);
    map.addPopup(feature.popup);
    feature.popup.hide();
  } 
}

1 个答案:

答案 0 :(得分:0)

你试过了吗?

feature.data.popupContentHTML = popupContentHTML[i];

假设您的位置数组的长度与文本数组匹配,两者的长度和位置都是