在 OSMBonusPack 中获取一个集群的所有标记

Get all the markers of a cluster in OSMBonusPack

我正在 android 中使用 RadiusMarkerClusterer 创建标记簇。我想显示组成特定标记簇的标记的位置。在创建集群后,我不知道如何检索标记信息。 有可能这样做吗?如果是那么怎么办?

RadiusMarkerClusterer is quite simple subclass of MarkerClusterer (abstract parent) and it does not provide any information about clustered markers to the caller. But internally the class has this information stored in the instances of StaticCluster

您可以创建自己的实现。查看 RadiusMarkerClusterer 的源代码并将其用作指南或示例。另一种解决方案可能是子类化 RadiusMarkerClusterer 并覆盖方法 buildClusterMarker。您可以通过 setRelatedObjectMethod 添加创建标记所需的信息,也可以使用您想要的任何信息创建信息窗口。

例如:

@Override public Marker buildClusterMarker(StaticCluster cluster, MapView mapView) {
    Marker m = new Marker(mapView);
    m.setPosition(cluster.getPosition());
    m.setInfoWindow(null);
    m.setAnchor(mAnchorU, mAnchorV);

    Bitmap finalIcon = Bitmap.createBitmap(mClusterIcon.getWidth(), mClusterIcon.getHeight(), mClusterIcon.getConfig());
    Canvas iconCanvas = new Canvas(finalIcon);
    iconCanvas.drawBitmap(mClusterIcon, 0, 0, null);
    String text = "" + cluster.getSize();
    int textHeight = (int) (mTextPaint.descent() + mTextPaint.ascent());
    iconCanvas.drawText(text,
            mTextAnchorU * finalIcon.getWidth(),
            mTextAnchorV * finalIcon.getHeight() - textHeight / 2,
            mTextPaint);
    m.setIcon(new BitmapDrawable(mapView.getContext().getResources(), finalIcon));
    //beggining of modification
    List<Marker> markersInCluster = new ArrayList<Marker>();
    for (int i = 0; i < cluster.getSize(); i++) {
        markersInCluster.add(cluster.getItem(i))
    }
    m.setRelatedObject(markersInCluster);
    //end of modification

    return m;

}