重叠的多段线未对齐

ckx4rj1h  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(146)

我目前正在开发一个android应用程序来订购出租车。该应用程序的核心基于一个片段,其中包含一个Map视图和一些其他视图。
一旦用户输入了它的上车地址和下车地址,我就可以使用这个算法在这两个坐标之间画一条曲线多段线https://betterprogramming.pub/curved-lines-on-google-maps-2938bbb15f6a.
现在我想添加一个动画来可视化旅行的方向。看起来像这样
正如您可能猜到的,我使用了两条多段线,一条是静态的“背景”多段线,另一条是动画的“前景”多段线。要设置第二条多段线的动画,我只需根据动画制作者的动画部分,获取第一条多段线的点的子列表,并在每次动画更新时更新它

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)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题