【问题标题】:OpenLayers - Add according popup text to marker arrayOpenLayers - 将相应的弹出文本添加到标记数组
【发布时间】:2012-09-26 20:16:26
【问题描述】:

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

【问题讨论】:

    标签: popup openlayers markers


    【解决方案1】:

    你试过了吗:

    feature.data.popupContentHTML = popupContentHTML[i];
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-27
      • 2019-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多