2011-01-11 9 views
0

다음 코드는 많은 경로 집합을 처리하기 때문에 MapView의 속도를 높여야합니다. 불행히도 "else"부분은 아무 것도 그려지지 않습니다. 누군가가 나를 이해하도록 도와 줄 수 있었습니까? 들으Android MapView 비트 맵 문제

public boolean draw(Canvas canvas, MapView mapv, boolean shadow, long when) { 

    if ((bmap == null) || (lastLatSpan != mapv.getLatitudeSpan())) { 
     // bitmap is null - so we haven't previously drawn the path, OR 
     // the map has been zoomed in/out, so we're gonna re-draw it anyway 
     // (alternatively, I could have tried scaling the bitmap... might 
     // be worth investigating if that is more efficient) 

     // create a new bitmap, the size of the map view 
     Canvas offscreencanvas = new Canvas(); 
     bmap = Bitmap.createBitmap(mapv.getWidth(), mapv.getHeight(), 
       Bitmap.Config.ARGB_8888); 
     offscreencanvas.setBitmap(bmap); 

     Path path = null; 

     Projection projection = mapv.getProjection(); 

     // lastLatSpan = mapv.getLatitudeSpan(); 

     for (int j = 0; j < mTourenArray.length; j++) { 
      GeoPoint[] route = GeoPointFactory 
        .createGeoPointArray(mTourenArray[j].getGeoPointArray()); 
      defaultColor = mTourenArray[j].getColorByCat(); 
      path = new Path(); 
      Paint polyPaint = new Paint(); 
      polyPaint.setColor(defaultColor); 

      for (int i = 0; i < route.length - 1; i++) { 
       GeoPoint gp1 = route[i]; 
       GeoPoint gp2 = route[i + 1]; 

       if (shadow == false) { 
        polyPaint.setAntiAlias(true); 
        Point point = new Point(); 
        projection.toPixels(gp1, point); 
        // mode=1&#65306;start 
        if (i == 0) { 
         RectF oval = new RectF(point.x - mRadius, point.y 
           - mRadius, point.x + mRadius, point.y 
           + mRadius); 
         // start point 
         canvas.drawOval(oval, polyPaint); 
         Point point2 = new Point(); 
         projection.toPixels(gp2, point2); 

         path.moveTo(point.x, point.y); 
         path.lineTo(point2.x, point2.y); 
        } 
        /* mode=3&#65306;end */ 
        else if (i == route.length - 2) { 
         /* the last path */ 
         Point point2 = new Point(); 
         projection.toPixels(gp2, point2); 
         path.lineTo(point2.x, point2.y); 

         RectF oval = new RectF(point2.x - mRadius, point2.y 
           - mRadius, point2.x + mRadius, point2.y 
           + mRadius); 
         /* end point */ 
         polyPaint.setAlpha(255); 
         offscreencanvas.drawOval(oval, polyPaint); 
        } 
        // mode=2&#65306;path 
        else if (i < route.length - 2 & i != 0) { 
         Point point2 = new Point(); 
         projection.toPixels(gp2, point2); 
         path.lineTo(point2.x, point2.y); 

        } 

       } 
      } 

      // create an off-screen canvas to prepare new bitmap, and 
      // draw path on to it 
      polyPaint.setStrokeWidth(5); 
      polyPaint.setStyle(Paint.Style.STROKE); 
      polyPaint.setAntiAlias(true); 
      polyPaint 
        .setAlpha(defaultColor == Color.parseColor("#6C8715") ? 220 
          : 120); 

      offscreencanvas.drawPath(path, polyPaint); 

     } // Outer For End 

     // draw the bitmap of the path onto my map view's canvas 
     canvas.drawBitmap(bmap, 0, 0, null); 

     // make a note of where we put the bitmap, so we know how 
     // much we 
     // we need to move it by if the user pans the map 
     mapStartPosition = projection.fromPixels(0, 0); 

    } else { 
     // as we're in onDraw, we think the user has panned/moved the map 
     // if we're in here, the zoom level hasn't changed, and 
     // we've already got a bitmap with a drawing of the route path 

     Projection proj = mapv.getProjection(); 

     // where has the mapview been panned to? 
     Point offsetPt = new Point(); 

     proj.toPixels(mapStartPosition, offsetPt); 
     Paint tmpPaint = new Paint(); 

     // create a new bitmap, the size of the map view 
     // draw the bitmap in the new correct location 
     canvas.drawBitmap(bmap, offsetPt.x, offsetPt.y, tmpPaint); 

    } 
    return super.draw(canvas, mapv, shadow, when); 
} 

답변

0

들으 당신의 대답을 etteyafed

문제였다 여기

if (shadow == false) 

작업 코드 :

if (shadow == false) { 
     if ((bmap == null) || (lastLatSpan != mapv.getLatitudeSpan()) || true) { 
      // bitmap is null - so we haven't previously drawn the path, OR 
      // the map has been zoomed in/out, so we're gonna re-draw it 
      // anyway 
      // (alternatively, I could have tried scaling the bitmap... 
      // might 
      // be worth investigating if that is more efficient) 

      // create a new bitmap, the size of the map view 
      Canvas offscreencanvas = new Canvas(); 
      bmap = Bitmap.createBitmap(mapv.getWidth(), mapv.getHeight(), 
        Bitmap.Config.ARGB_8888); 
      bmap.copy(Config.ARGB_4444, true); 
      offscreencanvas.setBitmap(bmap); 
      mCanvas = offscreencanvas; 

      Path path = null; 

      Projection projection = mapv.getProjection(); 

      lastLatSpan = mapv.getLatitudeSpan(); 

      for (int j = 0; j < mTourenArray.length; j++) { 
       GeoPoint[] route = GeoPointFactory 
         .createGeoPointArray(mTourenArray[j] 
           .getGeoPointArray()); 
       defaultColor = mTourenArray[j].getColorByCat(); 
       path = new Path(); 
       Paint polyPaint = new Paint(); 
       polyPaint.setColor(defaultColor); 

       for (int i = 0; i < route.length - 1; i++) { 
        GeoPoint gp1 = route[i]; 
        GeoPoint gp2 = route[i + 1]; 

        polyPaint.setAntiAlias(true); 
        Point point = new Point(); 
        projection.toPixels(gp1, point); 
        // mode=1&#65306;start 
        if (i == 0) { 
         Point point2 = new Point(); 
         projection.toPixels(gp2, point2); 

         RectF oval = new RectF(point.x - mRadius, point.y 
           - mRadius, point.x + mRadius, point.y 
           + mRadius); 
         // start point 
         offscreencanvas.drawOval(oval, polyPaint); 

         path.moveTo(point.x, point.y); 
         path.lineTo(point2.x, point2.y); 
        } 
        /* mode=3&#65306;end */ 
        else if (i == route.length - 2) { 
         /* the last path */ 
         Point point2 = new Point(); 
         projection.toPixels(gp2, point2); 
         path.lineTo(point2.x, point2.y); 

         RectF oval = new RectF(point2.x - mRadius, point2.y 
           - mRadius, point2.x + mRadius, point2.y 
           + mRadius); 
         /* end point */ 
         polyPaint.setAlpha(255); 
         offscreencanvas.drawOval(oval, polyPaint); 
        } 
        // mode=2&#65306;path 
        else if (i < route.length - 2 & i != 0) { 
         Point point2 = new Point(); 
         projection.toPixels(gp2, point2); 
         path.lineTo(point2.x, point2.y); 

        } 

       } 

       // create an off-screen canvas to prepare new bitmap, and 
       // draw path on to it 
       polyPaint.setStrokeWidth(5); 
       polyPaint.setStyle(Paint.Style.STROKE); 
       polyPaint.setAntiAlias(true); 
       polyPaint.setAlpha(defaultColor == Color 
         .parseColor("#6C8715") ? 220 : 120); 

       offscreencanvas.drawPath(path, polyPaint); 

      } // Outer For End 

      // draw the bitmap of the path onto my map view's canvas 
      // And set these pixels to destination bitmap: 
      canvas.drawBitmap(bmap, 0, 0, null); 

      panAfterZoom(mapv, 600); 
      // make a note of where we put the bitmap, so we know how 
      // much we 
      // we need to move it by if the user pans the map 
      mapStartPosition = projection.fromPixels(0, 0); 

     } else { 
      // as we're in onDraw, we think the user has panned/moved the 
      // map 
      // if we're in here, the zoom level hasn't changed, and 
      // we've already got a bitmap with a drawing of the route path 

      Projection proj = mapv.getProjection(); 

      // where has the mapview been panned to? 
      Point offsetPt = new Point(); 

      proj.toPixels(mapStartPosition, offsetPt); 

      // start point 

      // create a new bitmap, the size of the map view 
      // draw the bitmap in the new correct location 
      canvas.drawBitmap(bmap, offsetPt.x, offsetPt.y, null); 


     } 
    } 
    return super.draw(canvas, mapv, shadow, when); 
} 
0

이것은 명백한 보일지도 모르지만, 난 당신의 방법의 맥락이 무엇인지 잘 모르겠습니다 (또는 멤버 필드의 일부가 들고 무엇을)하지만 당신은 확인할 수있는 몇 가지가 있습니다. mapStartPosition이 현재 위치와 같습니까? super.draw (Canvas, MapView, boolean, long) 호출에 대한 메소드 서명에 익숙하지 않지만 super.draw 메소드를 직접 호출 할 필요가 없거나 도움이되지 않습니다. Doc는 MapView가 Canvas만을 인자로 취하는 뷰에서 Draw를 상속 받았다고 말합니다. 그래서 당신이 무엇을하고 있는지 확신 할 수 없습니다. 일반적으로 저는 캔버스 나 다른 드로어 블 오브젝트에 드로잉을 호출합니다.

저는 이것이 실제로 "대답"이 아니라는 것을 알고 있습니다. 아마도 도움이 될 것입니다. 행운을 빕니다!