MKergall / osmbonuspack

A third-party library of (very) useful additional objects for osmdroid

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Avoid overlapping cluster

mariusgab opened this issue · comments

Is there any way to avoid the overlap of cluster markers? When multiple clusters overlap they should aggregate into one single cluster to clearly display the count of pins, just like the default behaviour of MapKit in ios

From this:
Screenshot 2023-07-25 at 14 26 12

To this:
Screenshot 2023-07-25 at 15 00 49

commented

I've never seen this behaviour.
Maybe your custom icon is too big, compared to the "clustering" criteria?
Or is it an issue linked to "hdpi" (or "even-bigger-than-hdpi") resolution?

the custom icon is this drawable:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid android:color="@color/map_pin" />
    <size
        android:width="60dp"
        android:height="60dp" />
</shape>

The full map setup code:


fun setupMap(shouldClear: Boolean = false,
                    context: Context,
                    map: MapView,
                    infoWindow: ((Job) -> InfoWindow),
                    locations: ArrayList<Location>) {

    if (shouldClear) {
        map.overlays.removeAll { true }
        map.tileProvider.clearTileCache()
    }


    val poiMarkers = RadiusMarkerClusterer(context)
    val clusterIcon =
        BonusPackHelper.getBitmapFromVectorDrawable(context, R.drawable.cluster)
    poiMarkers.setIcon(clusterIcon);
    poiMarkers.textPaint.textSize = 12 * context.resources.displayMetrics.density
    poiMarkers.mAnchorV = Marker.ANCHOR_BOTTOM
    poiMarkers.mTextAnchorU = Marker.ANCHOR_CENTER
    poiMarkers.mTextAnchorV = Marker.ANCHOR_CENTER
    map.overlays.add(poiMarkers)

    val startPoint = GeoPoint(46.55,  7.6333)
    val mapController = map.controller
    mapController.setZoom(9)
    mapController.setCenter(startPoint)

    for (i in 0 until locations.count()) {
        try {
            val location = locations[i]

            val startPoint = GeoPoint(location.lat, location.lng)
                    val marker = Marker(map)
                    marker.title = "title"
                    marker.snippet = "snippet"
                    marker.position = startPoint
                    marker.subDescription = "subDescription"
                    marker.infoWindow = infoWindow(job)
                    marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM)

                    val markerDrawable = context.resources.getDrawable(R.drawable.pin_20)
                    val desiredWidth = 20 // Set the desired width in pixels
                    val desiredHeight = 20 // Set the desired height in pixels
                    markerDrawable.setBounds(0, 0, desiredWidth, desiredHeight)
                    marker.icon = markerDrawable

                    poiMarkers.add(marker)
        }
        catch (e: Exception) {
            print(e)
        }

    }

    map.invalidate()

}

ok so the issue doesn't occur anymore when i set shouldClear true