Skip to content
Permalink
Browse files

MapScaleBar: fix scaling

  • Loading branch information...
devemux86 committed Nov 5, 2019
1 parent 121b93d commit bea5eebefb6a7ff9e609eb4459afb6abe853eff5
@@ -1,7 +1,7 @@
/*
* Copyright 2010, 2011, 2012, 2013 mapsforge.org
* Copyright 2014 Ludwig M Brinckmann
* Copyright 2014-2016 devemux86
* Copyright 2014-2019 devemux86
* Copyright 2014 Erik Duisters
* Copyright 2014 Christian Pesch
*
@@ -18,14 +18,7 @@
*/
package org.mapsforge.map.scalebar;

import org.mapsforge.core.graphics.Canvas;
import org.mapsforge.core.graphics.Cap;
import org.mapsforge.core.graphics.Color;
import org.mapsforge.core.graphics.FontFamily;
import org.mapsforge.core.graphics.FontStyle;
import org.mapsforge.core.graphics.GraphicFactory;
import org.mapsforge.core.graphics.Paint;
import org.mapsforge.core.graphics.Style;
import org.mapsforge.core.graphics.*;
import org.mapsforge.map.model.DisplayModel;
import org.mapsforge.map.model.IMapViewPosition;
import org.mapsforge.map.model.MapViewDimension;
@@ -45,7 +38,6 @@

public enum ScaleBarMode {BOTH, SINGLE}

private final float scale;
private ScaleBarMode scaleBarMode;
private DistanceUnitAdapter secondaryDistanceUnitAdapter;

@@ -61,12 +53,11 @@ public DefaultMapScaleBar(IMapViewPosition mapViewPosition, MapViewDimension map

public DefaultMapScaleBar(IMapViewPosition mapViewPosition, MapViewDimension mapViewDimension,
GraphicFactory graphicFactory, DisplayModel displayModel, float scale) {
super(mapViewPosition, mapViewDimension, displayModel, graphicFactory, (int) (BITMAP_WIDTH * scale), (int) (BITMAP_HEIGHT * scale));
super(mapViewPosition, mapViewDimension, displayModel, graphicFactory, (int) (BITMAP_WIDTH * scale), (int) (BITMAP_HEIGHT * scale), scale);

setMarginHorizontal((int) (DEFAULT_HORIZONTAL_MARGIN * scale));
setMarginVertical((int) (DEFAULT_VERTICAL_MARGIN * scale));

this.scale = scale;
this.scaleBarMode = ScaleBarMode.BOTH;
this.secondaryDistanceUnitAdapter = ImperialUnitAdapter.INSTANCE;

@@ -1,7 +1,7 @@
/*
* Copyright 2010, 2011, 2012, 2013 mapsforge.org
* Copyright 2014 Ludwig M Brinckmann
* Copyright 2014-2016 devemux86
* Copyright 2014-2019 devemux86
* Copyright 2014 Erik Duisters
*
* This program is free software: you can redistribute it and/or modify it under the
@@ -50,8 +50,9 @@
private final IMapViewPosition mapViewPosition;
private int marginHorizontal;
private int marginVertical;
private MapPosition prevMapPosition;
protected MapPosition prevMapPosition;
protected boolean redrawNeeded;
protected final float scale;
protected ScaleBarPosition scaleBarPosition;
private boolean visible;

@@ -69,12 +70,13 @@ public ScaleBarLengthAndValue(int scaleBarLength, int scaleBarValue) {
}

public MapScaleBar(IMapViewPosition mapViewPosition, MapViewDimension mapViewDimension, DisplayModel displayModel,
GraphicFactory graphicFactory, int width, int height) {
GraphicFactory graphicFactory, int width, int height, float scale) {
this.mapViewPosition = mapViewPosition;
this.mapViewDimension = mapViewDimension;
this.displayModel = displayModel;
this.graphicFactory = graphicFactory;
this.mapScaleBitmap = graphicFactory.createBitmap(width, height);
this.scale = scale;

this.scaleBarPosition = DEFAULT_SCALE_BAR_POSITION;

@@ -216,7 +218,7 @@ protected ScaleBarLengthAndValue calculateScaleBarLengthAndValue(DistanceUnitAda
for (int scaleBarValue : scaleBarValues) {
mapScaleValue = scaleBarValue;
scaleBarLength = (int) (mapScaleValue / groundResolution);
if (scaleBarLength < (this.mapScaleBitmap.getWidth() - 10)) {
if (scaleBarLength < (this.mapScaleBitmap.getWidth() - 10 * this.scale)) {
break;
}
}

0 comments on commit bea5eeb

Please sign in to comment.
You can’t perform that action at this time.