[OSM-dev] Re: [RFC] Beautify scale bar

Jan-Benedict Glaw jbglaw at lug-owl.de
Sun May 14 14:37:37 BST 2006


On Sun, 2006-05-14 14:27:06 +0100, SteveC <steve at asklater.com> wrote:
> > That sounds like even more bloat:) Here's an updated patch:
> 
> eek, I just applied your last one :-)

No problem, I've diffed it out once again. Though `svn' is really dumb
about merging the conflicts. With proper tracking, that should have
been solved without user interaction:-(

Index: src/org/openstreetmap/processing/OsmApplet.java
===================================================================
--- src/org/openstreetmap/processing/OsmApplet.java	(revision 1025)
+++ src/org/openstreetmap/processing/OsmApplet.java	(working copy)
@@ -397,8 +397,7 @@
 	}
 
 	private void draw_scale_bar() {
-		int num_factors = 3;
-		double factor[] = { 1.0f, 2.5f, 5.0f, };
+		double factor[] = { 1.0f, 2.5f, 5.0f };
 		int exponent = 0;
 		int used_factor = 0;
 		double remains = 1.0f;
@@ -410,11 +409,11 @@
 		int ending_bar_length = getHeight() / 30;
 
 		/* Find the nearest factor */
-		for (i = 0; i < num_factors; i++) {
+		for (i = 0; i < factor.length; i++) {
 			double rest;
 			double log_value;
 
-			log_value = Math.log10(1000.0f * tiles.kilometersPerPixel()
+			log_value = Math.log10(tiles.metersPerPixel()
 					       * min_length / factor[i]);
 			if ((rest = log_value - Math.floor(log_value)) < remains) {
 				remains = rest;
@@ -425,7 +424,7 @@
 
 		/* Calculate the exact bar length */
 		bar_length = (int) (factor[used_factor] * Math.pow(10.0, exponent)
-				    / (1000.0f * tiles.kilometersPerPixel()));
+				    / tiles.metersPerPixel());
 
 		fill(0);
 		strokeWeight(2);
@@ -680,7 +679,7 @@
 
 	public void recalcStrokeWeight() {
 		// 10m roads, but min 2px width
-		strokeWeight = max(0.010f / tiles.kilometersPerPixel(), 2.0f); 
+		strokeWeight = max(10.0f / tiles.metersPerPixel(), 2.0f);
 	}
 
 	public void mouseMoved() {
Index: src/org/openstreetmap/client/Tile.java
===================================================================
--- src/org/openstreetmap/client/Tile.java	(revision 1025)
+++ src/org/openstreetmap/client/Tile.java	(working copy)
@@ -313,8 +313,10 @@
 		}
 	}
 
-	public float kilometersPerPixel() {
-		return (float)((40008.0 / 360.0) * 45.0 * (float)Math.pow(2.0, -6 - (double)zoom));
+	public float metersPerPixel() {
+		return (float)((40008.0 / 360.0) * 45.0
+			       * (float)Math.pow(2.0, -6 - (double)zoom))
+			       * 1000.0f;
 	}
 
 	public synchronized ImBundle getEle() {


MfG, JBG

-- 
Jan-Benedict Glaw       jbglaw at lug-owl.de    . +49-172-7608481             _ O _
"Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg  _ _ O
 für einen Freien Staat voll Freier Bürger"  | im Internet! |   im Irak!   O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.openstreetmap.org/pipermail/dev/attachments/20060514/2624a847/attachment.pgp>


More information about the dev mailing list