0

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: Maximum zoom level

And here's how it looks like when I zoom out slightly: Lower zoom level

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: Cluttered with labels

d.aemon
  • 761
  • 1
  • 7
  • 20
  • Can you add some screenshot how it looks now and how you want it to work. A code sample may be also useful: how you have defined your data layer – JaakL Jan 15 '21 at 04:58
  • @JaakL I added what you asked for. Thanks for taking a look. – d.aemon Jan 15 '21 at 09:00
  • I think you are using same datasource for both marker and BalloonPopup. So the cluster view thinks there are 2 items on the same position and mark it with number 2. Place the BalloonPopup in separate datasource. – binu j Apr 27 '21 at 16:51

0 Answers0