2

MarkerClustererPlus documentation에 따라 mouseovermouseout 이벤트가 MarkerCluster 클래스에서 실행되지 않습니다. 나는 심지어 당신이 클러스터를 가지고 다른 것을하기 전에 이것을 기다려야한다는 것을 알았으므로 clusteringend 이벤트에서 그것을 채우려고 시도했다. 그러나 운은 없다.MarkerClustererPlus.js의 mouseover 및 mouseout 이벤트가 내 클러스터에서 발생하지 않는 이유는 무엇입니까?

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); 
    }); 
}); 
+0

myCluster는 어디에서 왔습니까? 정의 된 위치는 어디입니까? – Marcelo

+0

@Marcelo - 잘 잡습니다. 오타, 대신'arrClusters [0]'이어야합니다. 업데이트 중 ... – johntrepreneur

답변

3

발견. 1/29/13 현재 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_); 
}); 

... 그리고 그것은 작동합니다.

+1

수정되지 않은 버전 ('markerclusterer.js')을 사용하여 스크립트가 수정되었는지 확인하는 스크립트를 변경하는 것을 잊지 마십시오. – johntrepreneur