Search code examples
javaandroidopenstreetmaposmdroid

Osmdroid - Polyline is not rendered smoothly


I am using Osmdroid library to display an offline map and I am using Polyline to draw line over the map. But resulting line is not continuous. If street is curved then the line is broken.

example of broken line

My code :

    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();

How can I resolve this ?


Solution

  • Try to modify Paint of the Polyline.

    Paint has two attributes: stroke join and stroke cap. Stroke join controls how segments of a path are connected, stroke cap controls how whole path is ended.

    Given that one can assume that this code would fix the problem:

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

    But it won't. The Osmdroiod library apparently does some neat performance optimizations and doesn't render whole Polyline as one path. Instead it renders it in distinct segments. It's visual appearance can be improved by setting the stroke cap.

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