2012-09-26 38 views
0

我在OpenLayers中有一個可能相當基本的問題,如果有人能幫我解決這個問題,那真是太好了。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(); 
    } 
} 

回答

0

做了嘗試:

feature.data.popupContentHTML = popupContentHTML[i]; 

假設你的位置數組的長度相匹配的文字排列,無論在長度ANF位置

相關問題