2

根据MarkerClusterPlus 文档,不会为 MarkerCluster 类触发mouseoverand事件。我什至尝试在事件中填充它,因为我注意到你需要等待这个,然后再对集群进行任何其他操作,但没有运气。mouseoutclusteringend

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

1 回答 1

3

找到了。截至 2013 年 1 月 29 日,markerclusterer.js 文件版本 2.0.15 中有一个错误。

在 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_);
});

...它会工作。

于 2013-01-29T18:51:51.197 回答