We are using Carto Mobile SDK in our Android application to display map with POI objects on it. There can be many such objects so we use clustering to avoid clutter over the map in lower zoom levels. So far so good.
Every POI can have a label attached to it for which we use balloon popup with text. As this popup uses POI point geometry to define its position it looks like a cluster to a clustered vector layer and unless I zoom-in to the maximum level I can't see the POI and the label separately in the map. It immediately becomes a cluster of 2 objects. I can't find any relevant information about how to avoid clustering of related objects. Can someone shed some light on this problem, please?
EDIT:
Here's how it looks like with maximum zoom - two objects at the same location:
And here's how it looks like when I zoom out slightly:
The code that creates these two geometries is here:
private suspend fun MapLayerData.createPointPoi(
layer: MapLayer,
projection: Projection,
pictogramSetIconsDao: PictogramSetIconsDao
): List<VectorElement> {
val elements = mutableListOf<VectorElement>()
getPoiPictogram(layer.dataPictogramSetId, icon, pictogramSetIconsDao)?.let { pictogram ->
Point(
projection.fromLatLong(vertices.first().lat, vertices.first().lng),
PointStyleBuilder().also {
it.bitmap = pictogram
}.buildStyle()
)
}?.let { point ->
elements.add(point)
if (text.isNotBlank()) {
elements.add(createText(point.geometry, text))
}
}
return elements
}
fun createText(location: Geometry, text: String) = BalloonPopup(
location,
BalloonPopupStyleBuilder().buildStyle(),
text,
""
)
All elements returned from createPointPoi()
method are added to the poiPointsLayer
created as this:
private val poiClusterElementBuilder = DefaultClusterElementBuilder(
res,
res.drawable(R.drawable.poi_cluster, theme)
)
private val poiPointsLayer = ClusteredVectorLayer(poiPointsDataSource, poiClusterElementBuilder)
I am actually now experimenting with balloon popups, but originally we were using texts, because by adding a bottom margin to the text we were able to have it displayed above the pictogram and not over it. But the result - having these two objects merged into one cluster - was exactly the same.
Of course we can move those label type objects out of the clustered layer to a separate vector layer but then we would have plenty of labels on the map over clustered pictograms. Something like this: