叠加的多段线未对齐

我目前正在开发一个 Android 应用程序来订购出租车。该应用程序的核心基于一个片段,其中包含一个 MapView 和一些其他视图。

一旦用户输入了上车地址和下车地址,我就可以使用此算法 here 在这两个坐标之间绘制一条弯曲的折线。

现在我想添加一个动画来可视化旅行的方向。看起来像这样

叠加的多段线未对齐

如您所料,我使用了 2 条折线,一条是静态的“背景”折线,另一条是动画的“前景”折线。 要为第二条折线设置动画,我只需根据我的动画师的动画分数获取第一条折线的点的子列表,并在每次动画更新时对其进行更新

override fun onAnimationUpdate(animation: ValueAnimator) {
    val backgroundPolylinesize = backgroundPolyline.points.size
    val foregroundEnd = ceil(animation.animatedFraction * backgroundPolylinesize).toInt()
    val foregroundPointCounts = (backgroundPolylinesize * 0.1).toInt() // 10% of the total trip
    foregroundPolyline.points = backgroundPolyline.points.subList(
        max(0,foregroundEnd - foregroundPointCounts),foregroundEnd
    )
}

结果还可以,但并不完美。事实上,我注意到两条折线(重叠)没有正确对齐

叠加的多段线未对齐

我不知道为什么,我对两条折线使用了相同的点,但看起来它们的绘制方式不同。

这是我使用的折线选项

val polylineOptions = PolylineOptions()
        .color(backgroundColor)
        .width(POLYLINE_WIDTH)
        .geodesic(false)
        .jointType(JointType.ROUND)
        .zIndex(0f)
        .addAll(polylineCoordinates)
    backgroundPolyline = map.addPolyline(polylineOptions)

    val foregroundPolylineOptions = PolylineOptions()
        .color(foregroundColor)
        .width(FOREGROUND_POLYLINE_WIDTH)
        .jointType(JointType.ROUND)
        .geodesic(false)
        .zIndex(1f)
    foregroundPolyline = map.addPolyline(foregroundPolylineOptions)
studyhost 回答:叠加的多段线未对齐

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/28262.html

大家都在问