Skip to content

Commit

Permalink
Added a some what makeshift imperial units scale/grid
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpoole committed Aug 16, 2015
1 parent 9ae3604 commit b601a64
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 43 deletions.
11 changes: 9 additions & 2 deletions .tx/config
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,21 @@ file_filter = res/values-<lang>/addresstags.xml
lang_map = cs: cs-rCZ, zh_TW: zh-rTW, pt_BR: pt-rBR
source_file = res/values/addresstags.xml
source_lang = en
minimum_perc = 5
minimum_perc = 100

[vespucci.bugfilterxml]
file_filter = res/values-<lang>/bugfilter.xml
lang_map = cs: cs-rCZ, zh_TW: zh-rTW, pt_BR: pt-rBR
source_file = res/values/bugfilter.xml
source_lang = en
minimum_perc = 5
minimum_perc = 100

[vespucci.scalexml]
file_filter = res/values-<lang>/scale.xml
lang_map = cs: cs-rCZ, zh_TW: zh-rTW, pt_BR: pt-rBR
source_file = res/values/scale.xml
source_lang = en
minimum_perc = 100

[vespucci.introductionmd]
file_filter = markdown/<lang>/Introduction.md
Expand Down
2 changes: 1 addition & 1 deletion AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:tools="https://schemas.android.com/tools"
package="de.blau.android"
android:versionName="@string/app_version"
android:versionCode="53"
android:versionCode="55"
android:installLocation="auto"
>

Expand Down
10 changes: 10 additions & 0 deletions res/values-de/scale.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version='1.0' encoding='UTF-8'?>
<resources>
<string-array name="scale_entries">
<item>Keins</item>
<item>Skala (metrisch)</item>
<item>Gitter (metrisch)</item>
<item>Skala (ft/mile)</item>
<item>Gitter (ft/mile)</item>
</string-array>
</resources>
4 changes: 2 additions & 2 deletions res/values/appname.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string translatable="false" name="app_name">Vespucci</string>
<string translatable="false" name="app_version">0.9.7.0.1022</string>
<string translatable="false" name="app_name_version">Vespucci 0.9.7b1022</string>
<string translatable="false" name="app_version">0.9.7.0.1023</string>
<string translatable="false" name="app_name_version">Vespucci 0.9.7b1023</string>
</resources>
4 changes: 4 additions & 0 deletions res/values/scale.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
<item>None</item>
<item>Scale (metric)</item>
<item>Grid (metric)</item>
<item>Scale (imperial)</item>
<item>Grid (imperial)</item>
</string-array>
<string-array translatable="false" name="scale_values">
<item>SCALE_NONE</item>
<item>SCALE_METRIC</item>
<item>SCALE_GRID_METRIC</item>
<item>SCALE_IMPERIAL</item>
<item>SCALE_GRID_IMPERIAL</item>
</string-array>
</resources>

158 changes: 120 additions & 38 deletions src/de/blau/android/grid/MapOverlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public class MapOverlay extends OpenStreetMapViewOverlay {
private static final float DISTANCE2SIDE = 4f;
private static final float SHORTTICKS = 12f;
private static final float LONGTICKS = 20f;
private static final double METERS2FEET = 3.28084;
private static final double MILE2FEET = 5280;
private static final double YARD2FEET = 3;

/** Map this is an overlay of. */
private final Map map;
Expand Down Expand Up @@ -81,62 +84,141 @@ protected void onDraw(Canvas c, IMapView osmv) {
if (!mode.equals("SCALE_NONE")) {
int w = map.getWidth();
int h = map.getHeight();
boolean grid = mode.equals("SCALE_GRID_METRIC");
boolean metric = mode.equals("SCALE_METRIC") || mode.equals("SCALE_GRID_METRIC");
boolean grid = mode.equals("SCALE_GRID_METRIC") || mode.equals("SCALE_GRID_IMPERIAL");
double centerLat = map.getViewBox().getCenterLat();
double widthInMeters = GeoMath.haversineDistance(map.getViewBox().getLeft()/1E7D, centerLat, map.getViewBox().getRight()/1E7D, centerLat);
// Log.d(DEBUG_TAG,"distance to side " + distance2side + " tick length long " + longTicks + " short " + shortTicks);
if (widthInMeters < 1000000) { // don't show zoomed out

double metersPerPixel = widthInMeters/w;

c.drawLine(distance2side, distance2side, w-distance2side, distance2side, fullLine);
c.drawLine(w-distance2side, distance2side, w-distance2side, h-distance2side, fullLine);
if (grid) {
c.drawLine(distance2side, h-distance2side, w-distance2side, h-distance2side, fullLine);
c.drawLine(distance2side, distance2side, distance2side, h-distance2side, fullLine);
}
if (metric) {
double metersPerPixel = widthInMeters/w;
double log10 = Math.log10(widthInMeters);
double tickDistance = Math.pow(10,Math.floor(log10)-1);
// Log.d(DEBUG_TAG,"log10 " + log10 + " tick distance " + Math.pow(10,Math.floor(log10)-1));
if (widthInMeters/tickDistance <= 20) { // heuristic to make the visual effect a bit nicer
tickDistance = tickDistance /10;
}
float tickDistanceH = Math.round(tickDistance/metersPerPixel);

// metric
double log10 = Math.log10(widthInMeters);
double tickDistance = Math.pow(10,Math.floor(log10)-1);
// Log.d(DEBUG_TAG,"log10 " + log10 + " tick distance " + Math.pow(10,Math.floor(log10)-1));
if (widthInMeters/tickDistance <= 20) { // heuristic to make the visual effect a bit nicer
tickDistance = tickDistance /10;
}
float tickDistanceH = Math.round(tickDistance/metersPerPixel);
boolean km = tickDistance*10 >= 1000;
c.drawText(km ? "km" : "m", distance2side, longTicks + oneDP, labelH);
float nextTick = distance2side;
int i = 0;
int nextLabel = 0;
while (nextTick < (w-distance2side)) {
if (i == 10) {
i = 0;
c.drawLine(nextTick, distance2side, nextTick, grid ? h-distance2side : longTicks, fullLine);
nextLabel = (int) (nextLabel + 10*tickDistance);
c.drawText(Integer.toString(km ? nextLabel/1000: nextLabel), nextTick + 2*oneDP, longTicks + 2*oneDP, labelH);
} else {
c.drawLine(nextTick, distance2side, nextTick, shortTicks, fullLine);
}
i++;
nextTick = nextTick + tickDistanceH;
}

boolean km = tickDistance*10 >= 1000;
c.drawText(km ? "km" : "m", distance2side, longTicks + oneDP, labelH);
float nextTick = distance2side;
int i = 0;
int nextLabel = 0;
while (nextTick < (w-distance2side)) {
if (i == 10) {
i = 0;
c.drawLine(nextTick, distance2side, nextTick, grid ? h-distance2side : longTicks, fullLine);
nextLabel = (int) (nextLabel + 10*tickDistance);
c.drawText(Integer.toString(km ? nextLabel/1000: nextLabel), nextTick + 2*oneDP, longTicks + 2*oneDP, labelH);
nextTick = distance2side + tickDistanceH; // dont't draw first tick
i = 1;
nextLabel = 0;
while (nextTick < (h-distance2side)) {
if (i == 10) {
i = 0;
c.drawLine(w-distance2side, nextTick, grid ? distance2side : w-longTicks, nextTick, fullLine);
nextLabel = (int) (nextLabel + 10*tickDistance);
c.drawText(Integer.toString(km ? nextLabel/1000: nextLabel), w-(shortTicks+distance2side), nextTick + textHeight + oneDP, labelV);
} else {
c.drawLine(w-distance2side, nextTick, w-shortTicks, nextTick, fullLine);
}
i++;
nextTick = nextTick + tickDistanceH;
}
} else { // imperial FIXME we could probably get rid of some duplicate code here
double widthInFeet = widthInMeters * METERS2FEET;
double feetPerPixel = widthInFeet/w;
boolean mile = widthInFeet > MILE2FEET;

double tickDistance = 0;
int smallTickMax = 10;

if (mile) { // between 1 and 12 miles use fractions
if (widthInFeet <= 2*MILE2FEET) {
smallTickMax = 16;
tickDistance = MILE2FEET / smallTickMax;
} else if (widthInFeet <= 6*MILE2FEET) {
smallTickMax = 8;
tickDistance = MILE2FEET / smallTickMax;
} else if (widthInFeet <= 10*MILE2FEET) {
smallTickMax = 4;
tickDistance = MILE2FEET / smallTickMax;
} else if (widthInFeet <= 50*MILE2FEET) {
smallTickMax = 2;
tickDistance = MILE2FEET / smallTickMax;
} else {
double log10 = Math.log10(widthInFeet/MILE2FEET);
tickDistance = MILE2FEET*Math.pow(10,Math.floor(log10)-1);
}
} else {
double log10 = Math.log10(widthInFeet);
tickDistance = Math.pow(10,Math.floor(log10)-1);
// Log.d(DEBUG_TAG,"log10 " + log10 + " tick distance " + Math.pow(10,Math.floor(log10)-1));
if (widthInFeet/tickDistance <= 30) { // heuristic to make the visual effect a bit nicer
tickDistance = tickDistance /10;
}
}

float tickDistanceH = Math.round(tickDistance/feetPerPixel);

c.drawText(mile ? "mile" : "ft", distance2side, longTicks + oneDP, labelH);
float nextTick = distance2side;
int i = 0;
int nextLabel = 0;
while (nextTick < (w-distance2side)) {
if (i == smallTickMax) {
i = 0;
c.drawLine(nextTick, distance2side, nextTick, grid ? h-distance2side : longTicks, fullLine);
if (mile) {
// Log.d(DEBUG_TAG,"mile tick " + nextTick + " label " + nextLabel);
nextLabel = (int) (nextLabel + smallTickMax*tickDistance);
c.drawText(Integer.toString((int)(nextLabel/MILE2FEET)), nextTick + 2*oneDP, longTicks + 2*oneDP, labelH);
} else {
nextLabel = (int) (nextLabel + 10*tickDistance);
c.drawText(Integer.toString((int)(nextLabel)), nextTick + 2*oneDP, longTicks + 2*oneDP, labelH);
}
} else {
c.drawLine(nextTick, distance2side, nextTick, shortTicks, fullLine);

}
i++;
c.drawLine(nextTick, distance2side, nextTick, shortTicks, fullLine);
nextTick = nextTick + tickDistanceH;
}
nextTick = nextTick + tickDistanceH;
}

nextTick = distance2side + tickDistanceH; // dont't draw first tick
i = 1;
nextLabel = 0;
while (nextTick < (h-distance2side)) {
if (i == 10) {
i = 0;
c.drawLine(w-distance2side, nextTick, grid ? distance2side : w-longTicks, nextTick, fullLine);
nextLabel = (int) (nextLabel + 10*tickDistance);
c.drawText(Integer.toString(km ? nextLabel/1000: nextLabel), w-(shortTicks+distance2side), nextTick + textHeight + oneDP, labelV);
} else {
nextTick = distance2side + tickDistanceH; // dont't draw first tick
i = 1;
nextLabel = 0;
while (nextTick < (h-distance2side)) {
if (i == smallTickMax) {
i = 0;
c.drawLine(w-distance2side, nextTick, grid ? distance2side : w-longTicks, nextTick, fullLine);
if (mile) {
nextLabel = (int) (nextLabel + smallTickMax*tickDistance);
c.drawText(Integer.toString((int)(nextLabel/MILE2FEET)), w-(shortTicks+distance2side), nextTick + textHeight + oneDP, labelV);
} else {
nextLabel = (int) (nextLabel + 10*tickDistance);
c.drawText(Integer.toString((int)(mile ? nextLabel/MILE2FEET: nextLabel)), w-(shortTicks+distance2side), nextTick + textHeight + oneDP, labelV);
}
} else {
c.drawLine(w-distance2side, nextTick, w-shortTicks, nextTick, fullLine);
}
i++;
c.drawLine(w-distance2side, nextTick, w-shortTicks, nextTick, fullLine);
nextTick = nextTick + tickDistanceH;
}
nextTick = nextTick + tickDistanceH;
}
}
}
Expand Down

0 comments on commit b601a64

Please sign in to comment.