MKergall / osmbonuspack

A third-party library of (very) useful additional objects for osmdroid
GNU Lesser General Public License v3.0
604 stars 205 forks source link

Polyline slow performance at higher zoom levels #131

Closed sergeantcrayon closed 9 years ago

sergeantcrayon commented 9 years ago

Context: I am using offline .mbtiles created from MapTiler and simply placing it in the sd card. Using android 5.1, osmbonuspack 5.1, osmdroid 4.2 i have tested this with a physical note 4 device and a virtual nexus 7 from eclipse

Code in question:

        RoadManager roadManager = new OSRMRoadManager();
        ArrayList<GeoPoint> waypoints = new ArrayList<GeoPoint>();
        waypoints.add(new GeoPoint(38.89092396942, -77.01666523201));
        waypoints.add(new GeoPoint(38.9044601962, -77.01684448347));
        waypoints.add(new GeoPoint(38.86768536719, -76.99394261155));
        waypoints.add(new GeoPoint(38.89092396942, -77.01666523201));

        Road road = roadManager.getRoad(waypoints);

        Polyline roadOverlay = RoadManager.buildRoadOverlay(road, mainContainer.getContext());
        mapView.getOverlays().add(roadOverlay);
        mapView.invalidate();

at zoom 16 below, there's no performance issues. It starts to slow down at zoom 17. at zoom 18 its barely moving and i'm getting 'skipping frames' logs on my logcat. the concerning part about this is that there's only 3 polylines created. I have also tried using PathOverlay, it has the same issue. can anyone help me with this issue? thank you.

MKergall commented 9 years ago

osmbonuspack 5.1 is based on osmdroid 4.3.

sergeantcrayon commented 9 years ago

Just updated it. Its still slow. more specifically. its only slow when the screen is only displaying part of the polyline. so its actually okay when the whole polyline is on the screen or none of it at all.

chrisail commented 8 years ago

I have the same problem than you.

Use mbtiles made with "mbutil" tool. Display offline maps with OSMDroid 5.0.1 and OSMBonusPack 5.6.1 on Nexus6p, Android SDK 23. It's works fine.

But when adding a simple Polyline (2 points, no geodesic) define at level 13 (20km), when render on max zoom (150m), consumme a lot of GPU (mainly Misc Time) and scrolling is slow. Go to upper zoom, works better. Problems occur only when adding a Polyline on a zoom level and zoom to a more detailled level. it's worse with Polygon. Logs show that "draw" call is fast, no problem with projection of points or things like this.

Use code from "stellardeveloper", https://github.com/MKergall/osmbonuspack/issues/171 with last changes and works fine. Thanks to him.

I verify it, the last OSMDroid code don't use "stellardeveloper" code, however this code works fine, no bugs detected.

Another solution, tested with success, replace drawPath by drawLines (see stackoverflow). Use original code, add an array of floats, when setting moveTo or lineTo (same for code that split segments exceeding 180°), add coordinates to this array (start and end of segment), use this array with canvas.drawLines() method. Works fine (exceeding 180° not tested). Lines never disappear.