简体   繁体   English

如何在google maps api v3中的标记簇对象中找到各个簇中的标记?

[英]how to find the markers in the individual clusters in a marker cluster object in google maps api v3?

I followed the tutorial here to add an inforwindow to the individual clusters of markercluster at any zoom level. 我按照这里的教程在任何缩放级别为各个clustercluster集群添加一个inforwindow。 http://krisarnold.com/2010/10/15/adding-info-windows-to-map-clusters-with-google-maps-api-v3/ http://krisarnold.com/2010/10/15/adding-info-windows-to-map-clusters-with-google-maps-api-v3/

I want to add the info of the markers (eg their 'title' s to a list displayed in the info window when clicked on the markercluster object.) contained in respective cluster. 我想在各自的集群中添加标记的信息(例如,将它们的'标题添加到单击标记集群对象时在信息窗口中显示的列表。)。

So if I have 3 clusters at a particular zoom level in view, each having 5 markers insider it. 因此,如果我在视图中具有特定缩放级别的3个聚类,则每个聚类具有5个标记。 How do I display a list of the titles of the 5 (out of total 15 markers in markercluster object) markers aggregated in that particular cluster? 如何显示在该特定群集中聚合的5个(在markercluster对象中的总共15个标记中)标记的列表?

for eg I have 3 markers inside a cluster then how do I show this in the info window? 例如,我在群集中有3个标记,那么如何在信息窗口中显示? titlemarker1 titlemarker2 titlemarker3 titlemarker1 titlemarker2 titlemarker3

edit : as seen here http://www.blogwave.de/wp-content/uploads/2009/05/marker_cluster.png all the different clusters are an instance of one markercluster object. 编辑 :如http://www.blogwave.de/wp-content/uploads/2009/05/marker_cluster.png所示,所有不同的集群都是一个markercluster对象的实例。 So if we use the getmarkers routine of markercluster object as mentioned in one of the answers below then we get list of all markers. 因此,如果我们使用下面其中一个答案中提到的markercluster对象的getmarkers例程,那么我们将获得所有标记的列表。

What I want is for eg to get a list of only those 18 markers from the total markers in the cluster marked with 18, first from left. 我想要的是例如从左边第一个标记为18的簇中的总标记中获得仅18个标记的列表。

Unfortunately, the MarkerClusterer reference is a bit scant. 不幸的是,MarkerClusterer参考有点不足。 After browsing through the source code , it looks like you need to call the getMarkers method of the cluster object passed in (contrary to what I had previously suggested, which was to call the method on the markerClusterer ). 浏览完源代码后 ,看起来你需要调用getMarkerscluster对象的getMarkers方法(与我之前建议的相反,即在markerClusterer上调用该方法)。

For example, using the tutorial you've linked to: 例如,使用您链接到的教程:

google.maps.event.addListener(markerClusterer, 'clusterclick', function(cluster) {
    var content = '';

    // Convert lat/long from cluster object to a usable MVCObject
    var info = new google.maps.MVCObject;
    info.set('position', cluster.center_);

    //----
    //Get markers
    var markers = cluster.getMarkers();

    var titles = "";
    //Get all the titles
    for(var i = 0; i < markers.length; i++) {
        titles += markers[i].getTitle() + "\n";
    }
    //----


    var infowindow = new google.maps.InfoWindow();
    infowindow.close();
    infowindow.setContent(titles); //set infowindow content to titles
    infowindow.open(map, info);

});

EDIT: Updated in response to question edit. 编辑:更新以回应问题编辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM