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

标签 google-maps-api-3 google-maps-markers mouseover mouseout markerclusterer

根据MarkerClustererPlus documentation,MarkerCluster 类不会触发 mouseovermouseout 事件。 。我什至尝试将其填充到 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 中存在错误。

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

...它会起作用的。

关于google-maps-api-3 - 为什么我的集群没有触发 MarkerClustererPlus.js 的 mouseover 和 mouseout 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14589958/

相关文章:

java - 在 Google map 上使用 JSON 表示经纬度

java - 在 MapView 中使用 Bottomsheet 时出现错误

javascript - 在传单 map 上捕获 d3 中的鼠标悬停

javascript - 标记过多时如何在谷歌地图上优化 MarkerWithLabel

javascript - 鼠标悬停和鼠标移出在 Firefox 上不起作用?

jquery - 鼠标悬停在带有附加信息的 div 上滑动 - 如何?

javascript - 谷歌地图 API v3 : Remove Default start/end markers

jquery - 如何使用 jQuery 访问多维 JSON 的值并将它们绘制在 Google map 上

Javascript - Google map - 自动填充

javascript - 无法获取属性值 'offsetWidth' : object is null or undefined error