osmdroid标记信息窗口在聚类标记后不显示

时间:2018-05-13 14:17:13

标签: android dictionary openstreetmap osmdroid

我正在使用osmdroid在Android应用中显示开放的街道地图 问题是当点击标记聚类标记时,标记的信息窗口不显示。 这就是我为聚类添加标记的方法:

    RadiusMarkerClusterer poiMarkers = new RadiusMarkerClusterer(this);
    Drawable clusterIconD = getResources().getDrawable(R.drawable.marker_cluster);
    Bitmap clusterIcon = ((BitmapDrawable) clusterIconD).getBitmap();
    poiMarkers.setIcon(clusterIcon);
    poiMarkers.getTextPaint().setColor(Color.WHITE);
    poiMarkers.getTextPaint().setTextSize(12 * getResources().getDisplayMetrics().density); //taking into account the screen density
    poiMarkers.mAnchorU = Marker.ANCHOR_CENTER;
    poiMarkers.mAnchorV = Marker.ANCHOR_CENTER;
    poiMarkers.mTextAnchorV = 0.40f;
    map.getOverlays().add(poiMarkers);

    for (int i = 0; i < places.size(); i++) {
        final Marker startMarker = new Marker(map);
        startMarker.setPosition(new GeoPoint(places.get(i).getLat(), places.get(i).getLng()));

        startMarker.setIcon(getResources().getDrawable(R.drawable.ic_new_loc));

        startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_CENTER);
        MyInfoWindow infoWindow = new MyInfoWindow(R.layout.map_marker_info_window, map);
        infoWindow.setPlace(places.get(i));
        startMarker.setInfoWindow(infoWindow);
        poiMarkers.add(startMarker);
    }

1 个答案:

答案 0 :(得分:0)

ReadiusMarkerClusterer不应显示群集的信息窗口。群集代表一组单独的标记,因此无法确定,应显示哪个信息窗口。

您可以查看source code of the RadiusMarkerClusterer课程。

标记(表示集群)在方法buildClusterMarker中实例化:

@Override public Marker buildClusterMarker(StaticCluster cluster, MapView mapView) {
    Marker m = new Marker(mapView);
    m.setPosition(cluster.getPosition());
    m.setInfoWindow(null); //<===== there you can see, no info window
    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));

    return m;
}

如果您想拥有群集的信息窗口,可以通过继承MarkerClusterer并覆盖此方法来创建自定义RadiusMarkerClusterer类。只需调用父版本并将所需的信息窗口注入Marker实例。