Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can't get the bitmap to where the <code>Mapview</code>canvas is drawing.</p> <p>The approach should be following:</p> <ul> <li>First you create your own (empty and transparent) bitmap, with the same size as the <code>MapView</code> canvas</li> <li>Then you create your won canvas for your bitmap (this canvas is the drawing tool that you are using to draw to your bitmap) and you draw the path using it.</li> <li>Finally you draw your bitmap (with the path already drawn) to the <code>MapView</code> canvas.</li> </ul> <p>However the performance/efficiency issues you are refering are probably due to incorrect design of your existing solution. I can draw paths with 10.000 points without using bitmap (and there are a few good reasons to not use them) in about 3ms in a medium range device.</p> <p>There are a few hints on how to approach it, on my answer to this post: <a href="https://stackoverflow.com/questions/12931564/overlay-draw-calls-many-times/12936520#12936520">Overlay.draw() calls many times</a>. Check also the answer from @shkschneider in the same post. </p> <p>--EDITED--</p> <p>Just by looking at the code, I can't figure out why you are getting this warning ... But are making it much more complex then it needs to be.</p> <p>Organize you code in the following way:</p> <p><strong>draw</strong></p> <p>The <code>draw()</code>methos only checks if there is a zoom change (if so ask the path to be rebuild) and if map has moved (if so offset path) and finally draws the path.</p> <pre><code>@Override public void draw(Canvas canvas, MapView mapview, boolean shadow) { super.draw(canvas, mapview, shadow); if(shadow) return; if(mp.getPoints() == null || mp.getPoints().size() &lt; 2) return; Projection projection = mapview.getProjection(); int lonSpanNew = projection.fromPixels(0,mapview.getHeight()/2).getLongitudeE6() - projection.fromPixels(mapview.getWidth(),mapview.getHeight()/2).getLongitudeE6(); if(lonSpanNew != pathInitialLonSpan) pathBuild(); else{ //check if path need to be offset projection.toPixels(mp.getPoints().get(0), p1); if(p1.x != pathInitialPoint.x || p1.y != pathInitialPoint.y){ path.offset(p1.x - pathInitialPoint.x, p1.y - pathInitialPoint.y); pathInitialPoint.x = p1.x; pathInitialPoint.y = p1.y; } } canvas.drawPath(path, paint); } </code></pre> <p><strong>pathBuild</strong></p> <p>The path has to be built every time zoom changes. The zoom change detection is done using <code>pathInitialLonSpan</code> as <code>getZoomLevel()</code> is not shyncronous with map zoom animation.</p> <pre><code>private void pathBuild(){ path.rewind(); if(mp.getPoints() == null || mp.getPoints().size() &lt; 2) return; Projection projection = mapView.getProjection(); pathInitialLonSpan = projection.fromPixels(0,mapView.getHeight()/2).getLongitudeE6() - projection.fromPixels(mapView.getWidth(),mapView.getHeight()/2).getLongitudeE6(); projection.toPixels(mp.getPoints().get(0), pathInitialPoint); path.moveTo(pathInitialPoint.x,pathInitialPoint.y); for(int i=1; i&lt;mp.getPoints().size(); i++){ projection.toPixels(mp.getPoints().get(i), p1); int distance2 = (pPrev.x - p1.x) * (pPrev.x - p1.x) + (pPrev.y - p1.y) * (pPrev.y - p1.y); if(distance2 &gt; 9){ path.lineTo(p1.x,p1.y); pPrev.set(p1.x, p1.y); } } </code></pre> <p>Some objects (i.e. p1, pPrev, etc) are defined at class level to avoid creating new ones everytime the methos runs.</p> <p><code>Note:</code> I've changed the variable names to fit the ones you are using. I hope I've not made any mistake, but you should be able to figure that out.</p> <p>Regards.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload