public boolean updateInfo(RotatedTileBox tb, DrawSettings nightMode) {
      boolean visible = true;
      OsmandMapTileView view = ma.getMapView();
      // update cache
      if (view.isZooming()) {
        visible = false;
      } else if (!orientationPortrait && ma.getRoutingHelper().isRoutePlanningMode()) {
        visible = false;
      } else if ((tb.getZoom() != cacheRulerZoom
              || Math.abs(tb.getCenterTileX() - cacheRulerTileX) > 1
              || Math.abs(tb.getCenterTileY() - cacheRulerTileY) > 1)
          && tb.getPixWidth() > 0
          && maxWidth > 0) {
        cacheRulerZoom = tb.getZoom();
        cacheRulerTileX = tb.getCenterTileX();
        cacheRulerTileY = tb.getCenterTileY();
        final double dist =
            tb.getDistance(0, tb.getPixHeight() / 2, tb.getPixWidth(), tb.getPixHeight() / 2);
        double pixDensity = tb.getPixWidth() / dist;
        double roundedDist =
            OsmAndFormatter.calculateRoundedDist(maxWidth / pixDensity, view.getApplication());

        int cacheRulerDistPix = (int) (pixDensity * roundedDist);
        cacheRulerText =
            OsmAndFormatter.getFormattedDistance((float) roundedDist, view.getApplication());
        textShadow.setText(cacheRulerText);
        text.setText(cacheRulerText);
        ViewGroup.LayoutParams lp = layout.getLayoutParams();
        lp.width = cacheRulerDistPix;
        layout.setLayoutParams(lp);
        layout.requestLayout();
      }
      updateVisibility(layout, visible);
      return true;
    }
Ejemplo n.º 2
0
 private void refreshMapInternal(DrawSettings drawSettings) {
   handler.removeMessages(MAP_REFRESH_MESSAGE);
   SurfaceHolder holder = getHolder();
   long ms = SystemClock.elapsedRealtime();
   synchronized (holder) {
     Canvas canvas = holder.lockCanvas();
     if (canvas != null) {
       try {
         final float ratioy = mapPosition == OsmandSettings.BOTTOM_CONSTANT ? 0.8f : 0.5f;
         final int cy = (int) (ratioy * getHeight());
         if (currentViewport.getPixWidth() != getWidth()
             || currentViewport.getPixHeight() != getHeight()
             || currentViewport.getCenterPixelY() != cy) {
           currentViewport.setPixelDimensions(getWidth(), getHeight(), 0.5f, ratioy);
           refreshBufferImage(drawSettings);
         }
         // make copy to avoid concurrency
         RotatedTileBox viewportToDraw = currentViewport.copy();
         fillCanvas(canvas, drawSettings);
         drawOverMap(canvas, viewportToDraw, drawSettings);
       } finally {
         holder.unlockCanvasAndPost(canvas);
       }
     }
     if (MEASURE_FPS) {
       main.calculateFPS(ms, SystemClock.elapsedRealtime());
     }
   }
 }
Ejemplo n.º 3
0
  private void showOnMap(LatLon latLon, boolean updateCoords, boolean ignoreCoef) {
    AnimateDraggingMapThread thread = map.getAnimatedDraggingThread();
    int fZoom = map.getZoom();
    double flat = latLon.getLatitude();
    double flon = latLon.getLongitude();

    RotatedTileBox cp = map.getCurrentRotatedTileBox().copy();
    if (ignoreCoef) {
      cp.setCenterLocation(0.5f, 0.5f);
    } else {
      cp.setCenterLocation(
          0.5f, map.getMapPosition() == OsmandSettings.BOTTOM_CONSTANT ? 0.15f : 0.5f);
    }
    cp.setLatLonCenter(flat, flon);
    flat = cp.getLatFromPixel(cp.getPixWidth() / 2, cp.getPixHeight() / 2);
    flon = cp.getLonFromPixel(cp.getPixWidth() / 2, cp.getPixHeight() / 2);

    if (updateCoords) {
      mapCenter = new LatLon(flat, flon);
      menu.setMapCenter(mapCenter);
      origMarkerX = cp.getCenterPixelX();
      origMarkerY = cp.getCenterPixelY();
    }

    thread.startMoving(flat, flon, fZoom, true);
  }
Ejemplo n.º 4
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.º 5
0
  private void showOnMap(
      LatLon latLon, boolean updateCoords, boolean needMove, boolean alreadyAdjusted) {
    // AnimateDraggingMapThread thread = map.getAnimatedDraggingThread(); todo amimation
    int fZoom = getZoom();
    double flat = latLon.getLatitude();
    double flon = latLon.getLongitude();

    RotatedTileBox cp = getBox();
    // cp.setCenterLocation(0.5f, map.getMapPosition() == OsmandSettings.BOTTOM_CONSTANT ? 0.15f :
    // 0.5f);
    cp.setLatLonCenter(flat, flon);
    cp.setZoom(fZoom);
    flat = cp.getLatFromPixel(cp.getPixWidth() / 2, cp.getPixHeight() / 2);
    flon = cp.getLonFromPixel(cp.getPixWidth() / 2, cp.getPixHeight() / 2);

    if (updateCoords) {
      mapCenter = new LatLon(flat, flon);
      menu.setMapCenter(mapCenter);
      origMarkerX = cp.getCenterPixelX();
      origMarkerY = cp.getCenterPixelY();
    }

    if (!alreadyAdjusted) {
      LatLon adjustedLatLon =
          getAdjustedMarkerLocation(getPosY(), new LatLon(flat, flon), true, fZoom);
      flat = adjustedLatLon.getLatitude();
      flon = adjustedLatLon.getLongitude();
    }

    if (needMove) {
      // thread.startMoving(flat, flon, fZoom, true); todo animation
      PointI targetI = Utilities.convertLatLonTo31(new net.osmand.core.jni.LatLon(flat, flon));
      getMainActivity().setTarget(targetI);
      getMainActivity().setZoom(fZoom);
    }
  }