Fix rulers

This commit is contained in:
Alexander Sytnyk 2017-07-31 16:25:07 +03:00
parent c8a57806ad
commit 03c54f27d4
2 changed files with 14 additions and 2 deletions

View file

@ -18,6 +18,7 @@ import net.osmand.data.QuadPoint;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.RulerMode; import net.osmand.plus.OsmandSettings.RulerMode;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
@ -46,6 +47,8 @@ public class RulerControlLayer extends OsmandMapLayer {
private int acceptableTouchRadius; private int acceptableTouchRadius;
private QuadPoint cacheCenter; private QuadPoint cacheCenter;
private float cacheMapDensity;
private OsmandSettings.OsmandPreference<Float> mapDensity;
private int cacheIntZoom; private int cacheIntZoom;
private double cacheTileX; private double cacheTileX;
private double cacheTileY; private double cacheTileY;
@ -87,6 +90,8 @@ public class RulerControlLayer extends OsmandMapLayer {
public void initLayer(final OsmandMapTileView view) { public void initLayer(final OsmandMapTileView view) {
app = mapActivity.getMyApplication(); app = mapActivity.getMyApplication();
this.view = view; this.view = view;
mapDensity = mapActivity.getMyApplication().getSettings().MAP_DENSITY;
cacheMapDensity = mapDensity.get();
cacheDistances = new ArrayList<>(); cacheDistances = new ArrayList<>();
cacheCenter = new QuadPoint(); cacheCenter = new QuadPoint();
maxRadiusInDp = mapActivity.getResources().getDimensionPixelSize(R.dimen.map_ruler_width); maxRadiusInDp = mapActivity.getResources().getDimensionPixelSize(R.dimen.map_ruler_width);
@ -298,12 +303,13 @@ public class RulerControlLayer extends OsmandMapLayer {
} }
boolean move = tb.getZoom() != cacheIntZoom || Math.abs(tb.getCenterTileX() - cacheTileX) > 1 || boolean move = tb.getZoom() != cacheIntZoom || Math.abs(tb.getCenterTileX() - cacheTileX) > 1 ||
Math.abs(tb.getCenterTileY() - cacheTileY) > 1; Math.abs(tb.getCenterTileY() - cacheTileY) > 1 || mapDensity.get() != cacheMapDensity;
if (!tb.isZoomAnimated() && move) { if (!tb.isZoomAnimated() && move) {
cacheIntZoom = tb.getZoom(); cacheIntZoom = tb.getZoom();
cacheTileX = tb.getCenterTileX(); cacheTileX = tb.getCenterTileX();
cacheTileY = tb.getCenterTileY(); cacheTileY = tb.getCenterTileY();
cacheMapDensity = mapDensity.get();
cacheDistances.clear(); cacheDistances.clear();
updateDistance(tb); updateDistance(tb);
} }

View file

@ -1048,6 +1048,8 @@ public class RouteInfoWidgetsFactory {
private MapActivity ma; private MapActivity ma;
private String cacheRulerText; private String cacheRulerText;
private int maxWidth; private int maxWidth;
private float cacheMapDensity;
private OsmandSettings.OsmandPreference<Float> mapDensity;
private int cacheRulerZoom; private int cacheRulerZoom;
private double cacheRulerTileX; private double cacheRulerTileX;
private double cacheRulerTileY; private double cacheRulerTileY;
@ -1061,6 +1063,8 @@ public class RouteInfoWidgetsFactory {
textShadow = (TextView) ma.findViewById(R.id.map_ruler_text_shadow); textShadow = (TextView) ma.findViewById(R.id.map_ruler_text_shadow);
maxWidth = ma.getResources().getDimensionPixelSize(R.dimen.map_ruler_width); maxWidth = ma.getResources().getDimensionPixelSize(R.dimen.map_ruler_width);
orientationPortrait = AndroidUiHelper.isOrientationPortrait(ma); orientationPortrait = AndroidUiHelper.isOrientationPortrait(ma);
mapDensity = ma.getMyApplication().getSettings().MAP_DENSITY;
cacheMapDensity = mapDensity.get();
} }
public void updateTextSize(boolean isNight, int textColor, int textShadowColor, int shadowRadius) { public void updateTextSize(boolean isNight, int textColor, int textShadowColor, int shadowRadius) {
@ -1077,10 +1081,12 @@ public class RouteInfoWidgetsFactory {
} else if (!orientationPortrait && ma.getRoutingHelper().isRoutePlanningMode()) { } else if (!orientationPortrait && ma.getRoutingHelper().isRoutePlanningMode()) {
visible = false; visible = false;
} else if (!tb.isZoomAnimated() && (tb.getZoom() != cacheRulerZoom || Math.abs(tb.getCenterTileX() - cacheRulerTileX) > 1 || Math } else if (!tb.isZoomAnimated() && (tb.getZoom() != cacheRulerZoom || Math.abs(tb.getCenterTileX() - cacheRulerTileX) > 1 || Math
.abs(tb.getCenterTileY() - cacheRulerTileY) > 1) && tb.getPixWidth() > 0 && maxWidth > 0) { .abs(tb.getCenterTileY() - cacheRulerTileY) > 1 || mapDensity.get() != cacheMapDensity) &&
tb.getPixWidth() > 0 && maxWidth > 0) {
cacheRulerZoom = tb.getZoom(); cacheRulerZoom = tb.getZoom();
cacheRulerTileX = tb.getCenterTileX(); cacheRulerTileX = tb.getCenterTileX();
cacheRulerTileY = tb.getCenterTileY(); cacheRulerTileY = tb.getCenterTileY();
cacheMapDensity = mapDensity.get();
final double dist = tb.getDistance(0, tb.getPixHeight() / 2, tb.getPixWidth(), tb.getPixHeight() / 2); final double dist = tb.getDistance(0, tb.getPixHeight() / 2, tb.getPixWidth(), tb.getPixHeight() / 2);
double pixDensity = tb.getPixWidth() / dist; double pixDensity = tb.getPixWidth() / dist;
double roundedDist = OsmAndFormatter.calculateRoundedDist(maxWidth / double roundedDist = OsmAndFormatter.calculateRoundedDist(maxWidth /