简体   繁体   English

集群标记后,osmdroid标记信息窗口不显示

[英]osmdroid marker info window dont show after clustering markers

I'm using osmdroid to display open street map in an android app the problem is when clustering markers when click on marker, info window of markers do not shows. 我正在使用osmdroid在android应用程序中显示开放的街道地图,问题是当在单击标记时对标记进行聚类时,标记的信息窗口不显示。 this is how i add markers for clustering: 这就是我为聚类添加标记的方式:

    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);
    }

ReadiusMarkerClusterer is not supposed to show info windows for clusters. ReadiusMarkerClusterer不应显示群集的信息窗口。 A cluster represents a group of individual markers and so it's impossible to decide, which info window should be displayed. 群集代表一组单独的标记,因此无法决定应显示哪个信息窗口。

You can check source code of the RadiusMarkerClusterer class. 您可以检查RadiusMarkerClusterer类的源代码

Markers (which represents clusters) are instantiated in the method buildClusterMarker : 标记(代表集群)在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;
}

If you want to have info windows for your clusters, you can create custom MarkerClusterer class, by inheriting from RadiusMarkerClusterer and overriding this method. 如果要为群集提供信息窗口,则可以通过从RadiusMarkerClusterer继承并覆盖此方法来创建自定义MarkerClusterer类。 Just call parent version and inject your desired info window into the Marker instance. 只需调用父版本,然后将所需的信息窗口注入Marker实例即可。

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

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