androidyandex-mapsyandex-mapkit

How to animate polyline in Yandex mapkit


I am using Yandex MapKit. I can draw routes(polylines) but how can I animate it like this? - https://yandex.ru/dev/maps/jsbox/2.1/polyline_animation


Solution

  • i tried to do it through ValueAnimator. It worked for my task

    private fun displayRoute(pointsList: List<Point>) {
        val valueAnimator = ValueAnimator.ofInt(1, pointsList.size)
        valueAnimator.duration = 1200
        valueAnimator.addUpdateListener {
            val polylineMapObject = binding?.mapViewOrderDetail?.map?.mapObjects?.addPolyline(
                Polyline(pointsList.subList(0, it.animatedValue as Int))
            )
            polylineMapObject?.strokeColor = ContextCompat.getColor(requireActivity(), R.color.color_black)
        }
        valueAnimator.start()
    }