2013-06-28 129 views
1

我試圖給標記分配一個彈出。 我已經創建了一個彈出框並將其綁定到一個標記。但是,它並沒有顯示出來。 我測試了一個alert()顯示,但彈出窗口沒有。標記彈出不能正常工作

有人可以幫助解決這個問題嗎?

var lonLatMarker = new OpenLayers.LonLat(78.447876 ,17.371610) 
.transform(new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984 
    map.getProjectionObject() // to Spherical Mercator Projection 
    ); 
var feature = new OpenLayers.Feature(markers, lonLatMarker); 
feature.closeBox = true; 
feature.popupClass = OpenLayers.Class(OpenLayers.Popup.AnchoredBubble, { 
    minSize: new OpenLayers.Size(300, 180) 
}); 
feature.data.popupContentHTML = 'Hello World'; 
feature.data.overflow = "hidden"; 

var marker = new OpenLayers.Marker(lonLatMarker); 
marker.feature = feature; 

var markerClick = function(evt) { 
    if (this.popup == null) { 
     this.popup = this.createPopup(this.closeBox); 
     map.addPopup(this.popup); 
     this.popup.show(); 
    } else { 
     alert("Hello"); 
     this.popup.toggle(); 
    } 
    OpenLayers.Event.stop(evt); 
}; 
marker.events.register("mousedown", feature, markerClick); 

markers.addMarker(marker); 
map.setCenter (lonLatMarker, 9); 

回答