Remove Polyline In Map

I have three Options, (Car,Bike,Walk).
I am able to make a poly line on those three but they where overlapping.
How can i remove the previous polyline then add the new one?

   private Polyline createPolyline(GHResponse response) {
Paint paintStroke = AndroidGraphicFactory.INSTANCE.createPaint();
paintStroke.setStyle(Style.STROKE);
paintStroke.setColor(Color.argb(255, colorR, colorG, colorB));
paintStroke.setStrokeWidth(20);
Polyline line = new Polyline((org.mapsforge.core.graphics.Paint) paintStroke, AndroidGraphicFactory.INSTANCE);
List<LatLong> geoPoints = line.getLatLongs();
PointList tmp = response.getPoints();
for (int i = 0; i < response.getPoints().getSize(); i++) {
    geoPoints.add(new LatLong(tmp.getLatitude(i), tmp.getLongitude(i)));
}
return line;
  }

 public void calcPath(final double fromLat, final double fromLon,
                 final double toLat, final double toLon) {

Log.e("Calculating", "calculating path ...");
new AsyncTask<Void, Void, GHResponse>() {
    float time;

    protected GHResponse doInBackground(Void... v) {
        StopWatch sw = new StopWatch().start();
        GHRequest req = new GHRequest(fromLat, fromLon, toLat, toLon)
                .setVehicle(vehicleType)
                .setAlgorithm(AlgorithmOptions.DIJKSTRA_BI);
        req.getHints().
                put("instructions", "false");
        GHResponse resp = hopper.route(req);
        time = sw.stop().getSeconds();
        return resp;
    }

    protected void onPostExecute(GHResponse resp) {
        if (!resp.hasErrors()) {
           /* log("from:" + fromLat + "," + fromLon + " to:" + toLat + ","
                    + toLon + " found path with distance:" + resp.getDistance()
                    / 1000f + ", nodes:" + resp.getPoints().getSize() + ", time:"
                    + time + " " + resp.getDebugInfo());
            logUser("the route is " + (int) (resp.getDistance() / 100) / 10f
                    + "km long, time:" + resp.getTime() / 60000f + "min, debug:" + time);*/
            mapView.getLayerManager().getLayers().add(createPolyline(resp));
        } else {
            Log.e("Error:", "" + resp.getErrors());
        }
        shortestPathRunning = false;
    }
}.execute();
}

Im using that code for creating a Polyline.

That’s a Mapsforge related question so better ask in our forum. :smile:

Nevertheless if you keep track of your overlays, then remove can be done in a similar way with add:

mapView.getLayerManager().getLayers().remove

Emux

Oops sorry. I thought it was for graphhopper. Sorry… i will try that code.