Exemple #1
0
  protected void doPaintAxis(final Graphics g) {
    if (scaleSizeInPixel == 0 || mapBackground != null) {
      return;
    }

    final Font font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);
    g.setFont(font);
    g.setColor(0x00000000);

    final int textBottom = height - 4 - SCALE_HEIGTH;
    int left = 0;
    for (int i = 0; i < scaleConfiguration.labelLocation.length; i++) {
      final float location = scaleConfiguration.labelLocation[i];
      final float value = scaleConfiguration.labelValue[i];
      String label = Utils.floatToString(value, true);
      if (location == 0) {
        left = (font.stringWidth(label) / 2) + 2;
      } else if (location == 1) {
        label += " " + scaleConfiguration.unit;
      }
      g.drawString(
          label,
          left + (int) (scaleSizeInPixel * location),
          textBottom,
          Graphics.BOTTOM | Graphics.HCENTER);
    }
    g.drawRect(left, height - 2 - SCALE_HEIGTH, scaleSizeInPixel, SCALE_HEIGTH);
    g.fillRect(left, height - 2 - SCALE_HEIGTH, scaleSizeInPixel / 2, SCALE_HEIGTH);
  }
Exemple #2
0
  protected void onScaleChanged() {
    if (mapBackground != null && currentPoint != null) {
      final double latitude = DataProvider.LATITUDE.getValue(currentPoint) + panLatitude;
      final double longitude = DataProvider.LONGITUDE.getValue(currentPoint) + panLong;
      super.onScaleChanged(
          mapBackground.getScaleX(), mapBackground.getScaleY(latitude), longitude, latitude);
    } else {
      super.onScaleChanged();
    }

    final double widthInMeter =
        Utils.distance(
            getYAxis().minValue, getXAxis().maxValue, getYAxis().maxValue, getXAxis().maxValue);
    if (widthInMeter < 1) {
      scaleSizeInPixel = 0;
      return;
    }

    final double availableLengthInMeter = widthInMeter * 0.9;

    scaleConfiguration =
        Preferences.getInstance().getUnitsConverter().getScaleDistance(availableLengthInMeter);

    scaleSizeInPixel = (int) ((scaleConfiguration.lengthInSourceUnits / widthInMeter) * width);
  }