mobile-sdk icon indicating copy to clipboard operation
mobile-sdk copied to clipboard

Is it possible to force Text objects to have a maximum width?

Open carlos-mg89 opened this issue 5 years ago • 1 comments

Hi,

I'm trying to add some points along with their text over the map using the following code:

private fun addRoutes(routesVectorDataSource: LocalVectorDataSource) {
        val vectorElementVector = VectorElementVector()
        routes.forEach { route ->
                val originLatitude = route.origin_latitude
                val originLongitude = route.origin_longitude
                val pointPos = baseProjection.fromLatLong(originLatitude, originLongitude)
                val point = Point(pointPos, getRoutePointStyle())
                vectorElementVector.add(point)

                val markerText = Text(pointPos, getLabelTextStyle(), route.getName())
                vectorElementVector.add(markerText)
        }
        routesVectorDataSource.addAll(vectorElementVector)
    }

And It's working quite nice so far, since I added the anchorPointY property so the Text objects are at a certain distance from the markers:

textStyleBuilder.anchorPointY = 2.5f

However, long lines produce an undesired effect. They don't get wrapped. So if the line is pretty long...well, it'll show in a single line over the map. It'd be really nice if we could add some property to control the width of the Text objects. Perhaps, it's already available and I wasn't able to find it?

Cheers

carlos-mg89 avatar Jun 27 '19 13:06 carlos-mg89

Correct, specifying max text width is currently not available. I am tagging this as 'idea maybe future' and we may include this even in 4.2.1 release.

There is a workaround for this, though. You could do text splitting yourself and use '\n' to break lines. In order for this to work properly you need to set TextStyleBuilder.isBreakLines flag to true.

mtehver avatar Jun 30 '19 05:06 mtehver