Ejemplo n.º 1
0
  private void drawOverMap(Canvas canvas, RotatedTileBox tileBox, DrawSettings drawSettings) {
    final QuadPoint c = tileBox.getCenterPixelPoint();
    synchronized (this) {
      if (bufferBitmap != null && !bufferBitmap.isRecycled()) {
        canvas.save();
        canvas.rotate(tileBox.getRotate(), c.x, c.y);
        drawBasemap(canvas);
        canvas.restore();
      }
    }

    for (int i = 0; i < layers.size(); i++) {
      try {
        OsmandMapLayer layer = layers.get(i);
        canvas.save();
        // rotate if needed
        if (!layer.drawInScreenPixels()) {
          canvas.rotate(tileBox.getRotate(), c.x, c.y);
        }
        layer.onDraw(canvas, tileBox, drawSettings);
        canvas.restore();
      } catch (IndexOutOfBoundsException e) {
        // skip it
      }
    }
    if (showMapPosition) {
      canvas.drawCircle(c.x, c.y, 3 * dm.density, paintCenter);
      canvas.drawCircle(c.x, c.y, 7 * dm.density, paintCenter);
    }
  }
Ejemplo n.º 2
0
 @Override
 public void onZoomEnded(double relativeToStart, float angleRelative) {
   // 1.5 works better even on dm.density=1 devices
   float dz = (float) (Math.log(relativeToStart) / Math.log(2)) * 1.5f;
   setIntZoom(Math.round(dz) + initialViewport.getZoom());
   if (Math.abs(angleRelative) < ANGLE_THRESHOLD) {
     angleRelative = 0;
   }
   rotateToAnimate(initialViewport.getRotate() + angleRelative);
   final int newZoom = getZoom();
   if (application.getInternalAPI().accessibilityEnabled()) {
     if (newZoom != initialViewport.getZoom()) {
       showMessage(getContext().getString(R.string.zoomIs) + " " + newZoom); // $NON-NLS-1$
     } else {
       final LatLon p1 = initialViewport.getLatLonFromPixel(x1, y1);
       final LatLon p2 = initialViewport.getLatLonFromPixel(x2, y2);
       showMessage(
           OsmAndFormatter.getFormattedDistance(
               (float)
                   MapUtils.getDistance(
                       p1.getLatitude(), p1.getLongitude(), p2.getLatitude(), p2.getLongitude()),
               application));
     }
   }
 }
Ejemplo n.º 3
0
  private void drawBasemap(Canvas canvas) {
    if (bufferImgLoc != null) {
      float rot = -bufferImgLoc.getRotate();
      canvas.rotate(rot, currentViewport.getCenterPixelX(), currentViewport.getCenterPixelY());
      final RotatedTileBox calc = currentViewport.copy();
      calc.setRotate(bufferImgLoc.getRotate());

      int cz = getZoom();
      QuadPoint lt = bufferImgLoc.getLeftTopTile(cz);
      QuadPoint rb = bufferImgLoc.getRightBottomTile(cz);
      final float x1 = calc.getPixXFromTile(lt.x, lt.y, cz);
      final float x2 = calc.getPixXFromTile(rb.x, rb.y, cz);
      final float y1 = calc.getPixYFromTile(lt.x, lt.y, cz);
      final float y2 = calc.getPixYFromTile(rb.x, rb.y, cz);
      if (!bufferBitmap.isRecycled()) {
        canvas.drawBitmap(bufferBitmap, null, new RectF(x1, y1, x2, y2), paintImg);
      }
      canvas.rotate(-rot, currentViewport.getCenterPixelX(), currentViewport.getCenterPixelY());
    }
  }
Ejemplo n.º 4
0
    private void changeZoomPosition(float dz, float angle) {
      final QuadPoint cp = initialViewport.getCenterPixelPoint();
      float dx = cp.x - initialMultiTouchCenterPoint.x;
      float dy = cp.y - initialMultiTouchCenterPoint.y;
      final RotatedTileBox calc = initialViewport.copy();
      calc.setLatLonCenter(initialCenterLatLon.getLatitude(), initialCenterLatLon.getLongitude());

      float calcZoom = initialViewport.getZoom() + dz + initialViewport.getZoomScale();
      float calcRotate = calc.getRotate() + angle;
      calc.setRotate(calcRotate);
      calc.setZoomAnimation(dz);
      final LatLon r = calc.getLatLonFromPixel(cp.x + dx, cp.y + dy);
      setLatLon(r.getLatitude(), r.getLongitude());
      zoomToAnimate(calcZoom, true);
      rotateToAnimate(calcRotate);
    }
Ejemplo n.º 5
0
 private void refreshBaseMapInternal(RotatedTileBox tileBox, DrawSettings drawSettings) {
   if (tileBox.getPixHeight() == 0 || tileBox.getPixWidth() == 0) {
     return;
   }
   if (bufferBitmapTmp == null
       || tileBox.getPixHeight() != bufferBitmapTmp.getHeight()
       || tileBox.getPixWidth() != bufferBitmapTmp.getWidth()) {
     bufferBitmapTmp =
         Bitmap.createBitmap(tileBox.getPixWidth(), tileBox.getPixHeight(), Config.RGB_565);
   }
   long start = SystemClock.elapsedRealtime();
   final QuadPoint c = tileBox.getCenterPixelPoint();
   Canvas canvas = new Canvas(bufferBitmapTmp);
   fillCanvas(canvas, drawSettings);
   for (int i = 0; i < layers.size(); i++) {
     try {
       OsmandMapLayer layer = layers.get(i);
       canvas.save();
       // rotate if needed
       if (!layer.drawInScreenPixels()) {
         canvas.rotate(tileBox.getRotate(), c.x, c.y);
       }
       layer.onPrepareBufferImage(canvas, tileBox, drawSettings);
       canvas.restore();
     } catch (IndexOutOfBoundsException e) {
       // skip it
     }
   }
   Bitmap t = bufferBitmap;
   synchronized (this) {
     bufferImgLoc = tileBox;
     bufferBitmap = bufferBitmapTmp;
     bufferBitmapTmp = t;
   }
   long end = SystemClock.elapsedRealtime();
   additional.calculateFPS(start, end);
 }
Ejemplo n.º 6
0
 public float getRotate() {
   return currentViewport.getRotate();
 }