弹出标记不能正常工作

时间:2013-06-28 10:29:44

标签: javascript popup openlayers openstreetmap

我正在尝试将弹出窗口分配给标记。 我创建了一个弹出窗口并将其绑定到标记。但是,它没有显示出来。 我已经测试了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);

1 个答案:

答案 0 :(得分:0)

参考Openlayers文档http://dev.openlayers.org/docs/files/OpenLayers/Marker-js.html#OpenLayers.Marker,没有针对标记对象的proprienty被称为功能

所以我认为你应该删除这一行

marker.feature = feature;

我遇到同样的问题,标记上的点击事件无效,我通过这种方式解决了