Avoid overlapping cluster
mariusgab opened this issue · 3 comments
mariusgab commented
MKergall 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?
mariusgab commented
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()
}
mariusgab commented
ok so the issue doesn't occur anymore when i set shouldClear true