Example #1
0
  private void drawZoomLevel(Canvas canvas) {
    String zoomText = view.getZoom() + "";
    float frac = view.getFloatZoom() - view.getZoom();
    while (frac > OsmandMapTileView.ZOOM_DELTA_1) {
      frac -= OsmandMapTileView.ZOOM_DELTA_1;
      zoomText += "'";
    }
    float length = zoomTextPaint.measureText(zoomText);
    if (zoomShadow.getBounds().width() == 0) {
      zoomShadow.setBounds(
          zoomInButton.getLeft() - 2,
          zoomInButton.getTop() - (int) (18 * scaleCoefficient),
          zoomInButton.getRight(),
          zoomInButton.getBottom());
    }
    zoomShadow.draw(canvas);

    ShadowText.draw(
        zoomText,
        canvas,
        zoomInButton.getLeft() + (zoomInButton.getWidth() - length - 2) / 2,
        zoomInButton.getTop() + 4 * scaleCoefficient,
        zoomTextPaint,
        shadowColor);
  }
Example #2
0
  private void drawRuler(Canvas canvas) {
    // update cache
    if (view.isZooming()) {
      cacheRulerText = null;
    } else if (view.getFloatZoom() != cacheRulerZoom
        || Math.abs(view.getXTile() - cacheRulerTileX) + Math.abs(view.getYTile() - cacheRulerTileY)
            > 1) {
      cacheRulerZoom = view.getFloatZoom();
      cacheRulerTileX = view.getXTile();
      cacheRulerTileY = view.getYTile();
      double latitude = view.getLatitude();
      double leftLon = view.calcLongitude(-view.getWidth() / 2);
      double rightLon = view.calcLongitude(+view.getWidth() / 2);
      double dist = MapUtils.getDistance(latitude, leftLon, latitude, rightLon);
      double pixDensity = view.getWidth() / dist;

      double roundedDist =
          OsmAndFormatter.calculateRoundedDist(dist * screenRulerPercent, view.getContext());

      int cacheRulerDistPix = (int) (pixDensity * roundedDist);
      cacheRulerText =
          ShadowText.create(
              OsmAndFormatter.getFormattedDistance((float) roundedDist, view.getContext()));
      cacheRulerTextLen = zoomTextPaint.measureText(cacheRulerText.getText());

      Rect bounds = rulerDrawable.getBounds();
      bounds.right = (int) (view.getWidth() - 7 * scaleCoefficient);
      bounds.bottom =
          (int)
              (view.getHeight()
                  - view.getResources().getDrawable(R.drawable.map_zoom_in).getMinimumHeight());
      bounds.top = bounds.bottom - rulerDrawable.getMinimumHeight();
      bounds.left = bounds.right - cacheRulerDistPix;
      rulerDrawable.setBounds(bounds);
    }
    if (cacheRulerText != null) {
      rulerDrawable.draw(canvas);
      Rect bounds = rulerDrawable.getBounds();
      cacheRulerText.draw(
          canvas,
          bounds.left + (bounds.width() - cacheRulerTextLen) / 2,
          bounds.bottom - 8 * scaleCoefficient,
          rulerTextPaint,
          shadowColor);
    }
  }