Google maps api 3 为什么MarkerClustererPlus.js的mouseover和mouseout事件没有为我的集群触发?

Google maps api 3 为什么MarkerClustererPlus.js的mouseover和mouseout事件没有为我的集群触发?,google-maps-api-3,google-maps-markers,mouseover,mouseout,markerclusterer,Google Maps Api 3,Google Maps Markers,Mouseover,Mouseout,Markerclusterer,根据的,mouseover和mouseout事件没有为MarkerCluster类触发。我甚至试着把它塞进clusteringend事件中,因为我注意到,在对集群执行任何其他操作之前,您需要等待它,但运气不好 var map = new google.maps.Map(document.getElementById('map'), { zoom: 10, center: new google.maps.LatLng(arrLocLatLng[0], arrLocLatLng[1]

根据的,
mouseover
mouseout
事件没有为MarkerCluster类触发。我甚至试着把它塞进
clusteringend
事件中,因为我注意到,在对集群执行任何其他操作之前,您需要等待它,但运气不好

var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 10,
    center: new google.maps.LatLng(arrLocLatLng[0], arrLocLatLng[1]),
    mapTypeId: google.maps.MapTypeId.ROADMAP
});

var arrMarkers = [
    new google.maps.Marker({
        position: new google.maps.LatLng(myLat1, myLng1)
    }),
    new google.maps.Marker({
        position: new google.maps.LatLng(myLat2, myLng2)
    })
];

var mcOptions = {gridSize: 50, maxZoom: 15};
var mc = new MarkerClusterer(map, arrMarkers, mcOptions);

// need to wait for clusteringend, otherwise clusters may not be in DOM
google.maps.event.addListener(mc, 'clusteringend', function () {

    var arrClusters = mc.getClusters(); // will just be one

    // THIS IS NOT FIRING
    // Event name: mouseout
    // Event args: c:Cluster
    // Event Desc: This event is fired when the mouse moves out of a cluster marker.
    google.maps.event.addListener(arrClusters[0], 'mouseover', function ()
    {
        alert('mouseover event triggered on this particular cluster);
    });

    // ALSO NOT FIRING
    // Event name: mouseover
    // Event args: c:Cluster
    // Event Desc: This event is fired when the mouse moves over a cluster marker.
    google.maps.event.addListener(arrClusters[0], 'mouseout', function ()
    {
        alert('mouseout event triggered on this particular cluster);
    });
});

找到了。自2013年1月29日起,markerclusterer.js文件版本2.0.15中存在一个bug

在MarkerClusterer.js文件(非打包版本)中,更改以下内容:

google.maps.event.addDomListener(this.div_, "mouseover", function () {
    var mc = cClusterIcon.cluster_.getMarkerClusterer();
    /**
     * This event is fired when the mouse moves over a cluster marker.
     * @name MarkerClusterer#mouseover
     * @param {Cluster} c The cluster that the mouse moved over.
     * @event
     */
    google.maps.event.trigger(mc, "mouseover", cClusterIcon.cluster_);
});

google.maps.event.addDomListener(this.div_, "mouseout", function () {
    var mc = cClusterIcon.cluster_.getMarkerClusterer();
    /**
     * This event is fired when the mouse moves out of a cluster marker.
     * @name MarkerClusterer#mouseout
     * @param {Cluster} c The cluster that the mouse moved out of.
     * @event
     */
    google.maps.event.trigger(mc, "mouseout", cClusterIcon.cluster_);
});
})

为此:

google.maps.event.addDomListener(this.div_, "mouseover", function () {
    var c = cClusterIcon.cluster_;
    /**
     * This event is fired when the mouse moves over a cluster marker.
     * @name MarkerClusterer#mouseover
     * @param {Cluster} c The cluster that the mouse moved over.
     * @event
     */
    google.maps.event.trigger(c, "mouseover", cClusterIcon.cluster_);
});

google.maps.event.addDomListener(this.div_, "mouseout", function () {
    var c = cClusterIcon.cluster_;
    /**
     * This event is fired when the mouse moves out of a cluster marker.
     * @name MarkerClusterer#mouseout
     * @param {Cluster} c The cluster that the mouse moved out of.
     * @event
     */
    google.maps.event.trigger(c, "mouseout", cClusterIcon.cluster_);
});

。。。它会工作。

别忘了更改脚本以使用非打包版本(
markerclusterer.js
)验证修复。myCluster从何而来?它的定义是什么?@Marcelo-很好。输入错误,应该是[0]。更新。。。