[英]Popup on marker not working properly
我正在嘗試為標記分配一個彈出窗口。 我創建了一個彈出窗口,並將其綁定到標記。 但是,它沒有出現。 我已經對顯示的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);
請參考Openlayers文檔http://dev.openlayers.org/docs/files/OpenLayers/Marker-js.html#OpenLayers.Marker ,標記對象沒有適當的功能
所以我認為您應該刪除此行
marker.feature = feature;
我遇到了同樣的問題,標記上的click事件無法正常工作,我通過這種方式解決了
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.