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);
4

1 回答 1

0

参考 Openlayers 文档http://dev.openlayers.org/docs/files/OpenLayers/Marker-js.html#OpenLayers.Marker标记对象没有适当的调用功能

所以我认为你应该删除这条线

marker.feature = feature;

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

于 2014-03-28T00:55:35.413 回答