Home>

I need to draw an arrow in the direction of movement, and the first problem I encountered and cannot find an answer is to draw at least some kind of arrow, I tried to draw separate lines, and let them insert the end of the arrow on the Bitmap, but I decided that it was the wrong solution and started digging found some strange method that should draw a line and it has the addArrow function, but it does not output anything at all,

code that I tried

fun MapObjectCollection.createArrowPolyLine1 (
    context: Context,
    points: List <
Point >
,
    strokeWidth: Float= 2f,
    outlineWidth: Float= 8f,
    color: Int= R.color.white_dark,
    outlineColor: Int= R.color.blue
)=
    this.addColoredPolyline (Polyline (points)). also {
        it.addArrow (
            PolylinePosition (0, 0.9),
            200f,
            color
        )
        it.zIndex= 2f
        it.strokeWidth= strokeWidth
        it.outlineColor= context.color (outlineColor)
        it.outlineWidth= outlineWidth
    }

What I want to get

  • Answer # 1

    Since I found a solution to this problem only two weeks later, I will leave my solution here, let the next one who will do this will not spend so much time on it

    fun MapObjectCollection.createArrowPolyLine (
        context: Context,
        points: List <
    Point >
    ,
        strokeWidth: Float= 5f,
        outlineColor: Int= R.color.blue_white,
        outlineWidth: Float= 0f,
        outlineColorArrow: Int= R.color.orange,
        color: Int= R.color.blue_white,
        zIndex: Float= 30f
    )= this.addColoredPolyline (Polyline (points)). also {
        (0 until points.size -1) .forEach {segment ->
            if (segment% 6== 0) {
                it.addArrow (
                    PolylinePosition (segment, 0.1),
                    30f,
                    context.color (outlineColorArrow)
                )
            }
        }
        it.arrows (). forEach {arrow ->
            arrow.outlineWidth= 0f
            arrow.outlineColor= context.color (outlineColorArrow)
            arrow.triangleHeight= 10f
        }
        it.outlineColor= outlineColor
        it.outlineWidth= outlineWidth
        it.strokeWidth= strokeWidth
        it.setPaletteColor (0, context.color (color))
        it.setColors (List (points.size -1) {0})
        it.zIndex= zIndex
    }
    

    the meaning is simple, creates throughsetPaletteColorcolor and index to it and throughsetColorssheet equal in length to the number of segments (straight line from point to point). consisting of the index of the color in which this line should be colored -this applies to the line on which the arrows will be drawn, and for the arrow itself through the methodaddArrowwe transfer the segment in which we want to draw it, the point on the segment where to draw (from 0 to 1), the length and color, I think you can figure out the rest yourself)