【问题标题】:Osmdroid - Polyline is not rendered smoothlyOsmdroid - 折线渲染不平滑
【发布时间】:2018-04-25 00:33:34
【问题描述】:

我正在使用 Osmdroid 库来显示离线地图,并且我正在使用折线在地图上画线。但结果线不是连续的。如果街道是弯曲的,那么这条线就被打破了。

我的代码:

    Polyline polyline = new Polyline();
    ArrayList<GeoPoint> geoPoints = new ArrayList<>();
    // add Gepoint to array here.
    polyline.setPoints(geoPoints);
    polyline.setWidth(mywidth);
    polyline.setColor(mycolor);
    map.getOverlayManager().add(polyline);
    map.invalidate();

我该如何解决这个问题?

【问题讨论】:

    标签: java android openstreetmap osmdroid


    【解决方案1】:

    尝试修改折线的Paint

    Paint 有两个属性:stroke join 和 stroke cap。笔划连接控制路径的各个部分如何连接,笔划帽控制整个路径的结束方式。

    假设可以假设这段代码可以解决问题:

    polyline.getPaint().setStrokeJoin(Paint.Join.ROUND)
    

    但不会。 Osmdroid 库显然做了一些简洁的性能优化,并且没有将整个折线渲染为一条路径。相反,它将其呈现在不同的部分中。通过设置笔画上限可以改善它的视觉外观。

    polyline.getPaint().setStrokeCap(Cap.Join.ROUND)
    

    【讨论】:

    • 嗨约瑟夫·亚当西克。我只是尝试将您的代码添加到我的代码中,但它不起作用。
    • @Foxes 我看到了,我检查了 osmdroid 库的源代码,似乎有一些巧妙的渲染优化导致了这种情况。尝试改用polyline.getPaint().setStrokeCap(Cap.ROUND);,这样可以解决问题并改善poliline的外观。我会相应地更新我的回复。
    • 我明白了。使用 polyline.getPaint().setStrokeCap(Paint.Cap.ROUND);感谢@Josef Adamcik 的帮助。请分享你看到的 Osmdroid 库。我想清楚地知道。
    • 源码可以在github上找到,折线类:github.com/osmdroid/osmdroid/blob/…
    • getPaint 已弃用?有最新的语法吗?
    猜你喜欢
    • 2014-03-21
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    • 2012-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多