2017-08-27 35 views

回答

0

RadiusMarkerClusterer是MarkerClusterer(抽象父級)的非常簡單的子類,它不向調用者提供有關聚集標記的任何信息。但內部類有存儲在您可以創建自己的實現的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; 

} 
只是爲了澄清
+0

什麼時候,這buildClusterMarker其實叫什麼名字?就像每當我在RadiusMarkerClusterer的實例中添加標記時一樣? –

+0

它實際上更頻繁。當縮放變化時,MarkerClusterer的當前細節會重建簇。來源:https://github.com/MKergall/osmbonuspack/blob/f08a121031abd6fabcc17a0c08de60821d595537/OSMBonusPack/src/main/java/org/osmdroid/bonuspack/clustering/MarkerClusterer.java#L97 –

相關問題