0

我在 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();
  } 
}
4

1 回答 1

0

你试过了吗:

feature.data.popupContentHTML = popupContentHTML[i];

假设您的位置数组的长度与您的文本数组匹配,无论是长度还是位置

于 2012-09-27T19:59:06.313 回答