根据MarkerClustererPlus documentation,不会为MarkerCluster类触发mouseover
和mouseout
个事件。我甚至尝试在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);
});
});
答案 0 :(得分:3)
找到它。自13/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_);
});
......它会起作用。