Location Clustering
//Enabling clustering
MapsIndoors.getSolution()?.config?.setEnableClustering(true)
//Disabling clustering
MapsIndoors.getSolution()?.config?.setEnableClustering(false)private fun initMapControl(view: View) {
val mapConfig: MPMapConfig = MPMapConfig.Builder(requireActivity(), mMap!!, getString(R.string.google_maps_key), view, true).setClusterIconAdapter { return@setClusterIconAdapter getCircularImageWithText(it.size.toString(), 15, 30, 30) }.build()
MapControl.create(mapConfig) { mapControl: MapControl?, miError: MIError? -> }
}
private fun getCircularImageWithText(text: String, textSize: Int, width: Int, height: Int): Bitmap {
val background = Paint()
background.color = Color.WHITE
// Now add the icon on the left side of the background rect
val result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
val canvas = Canvas(result)
val radius = width shr 1
canvas.drawCircle(radius.toFloat(), radius.toFloat(), radius.toFloat(), background)
background.color = Color.BLACK
background.style = Paint.Style.STROKE
background.strokeWidth = 3f
canvas.drawCircle(radius.toFloat(), radius.toFloat(), (radius - 2).toFloat(), background)
val tp = TextPaint()
tp.textSize = textSize.toFloat()
tp.color = Color.BLACK
val bounds = Rect()
tp.getTextBounds(text, 0, text.length, bounds)
val textHeight: Int = bounds.height()
val textWidth: Int = bounds.width()
val textPosX = width - textWidth shr 1
val textPosY = height + textHeight shr 1
canvas.drawText(text, textPosX.toFloat(), textPosY.toFloat(), tp)
return result
}Last updated
Was this helpful?