我怎样才能将infowindow隐藏在标记集群内部的标记上 [英] How can I hide infowindow on markers which are inside marker cluster
问题描述
我有几个有infowindow和markerclusters的标记。当他们成为地图中标记集群的一部分时,我想隐藏标记的infoWindow,并在它们实际单独显示而不是集群中时显示它们。
I am having few markers which have infowindow and markerclusters. I want to hide the infoWindow of the markers when they become part of marker clusters in the map and show tem when they are actually shown individually rather than in a cluster.
标记和infowindow的代码如下所示:
The code for markers and infowindow is something like:
var marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map,
...
});
var myOptions = {
.......
};
infowindow = new InfoBox(myOptions);
infowindow.open(map, marker);
markers.push(marker);
然后我有标记群集
Then I have marker cluster
var markerCluster = new MarkerClusterer(map, markers,markerClustererOptions);
有人可以提供代码/建议/链接
Can someone provide code/suggestions/link on how to approach this
推荐答案
观察标记的 map_changed
- 事件。当标记的 map
-property为null时,关闭infowindow,否则打开它。
Observe the map_changed
-event of the markers. When the map
-property of a marker is null, close the infowindow, otherwise open it.
google.maps.event.addListener(marker,'map_changed',function(){
if(this.getMap()){
infowindow.open(this.getMap(),this);
}
else{
infowindow.close();
}
});
示例:
Example:
<div id="map"></div>
<script src="https://maps.googleapis.com/maps/api/js"></script>
<script src="https://googlemaps.github.io/js-marker-clusterer/examples/data.json"></script>
<script src="https://googlemaps.github.io/js-marker-clusterer/src/markerclusterer.js"></script>
<script src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox.js"></script>
这篇关于我怎样才能将infowindow隐藏在标记集群内部的标记上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!