From: Keith Packard Date: Sun, 7 Oct 2018 02:29:01 +0000 (-0700) Subject: altoslib: Switch to maps.altusmetrum.org when no google map key is available X-Git-Tag: 1.8.7~3^2~29 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=c7b1f3c6722ae59d09a888084075664446ff2768;ds=sidebyside altoslib: Switch to maps.altusmetrum.org when no google map key is available The map key is only usable from maps.altusmetrum.org at this point, and that service will be proxying for everyone in the near future. Signed-off-by: Keith Packard --- diff --git a/altosdroid/AndroidManifest.xml.in b/altosdroid/AndroidManifest.xml.in index 3f17188e..43a0787e 100644 --- a/altosdroid/AndroidManifest.xml.in +++ b/altosdroid/AndroidManifest.xml.in @@ -107,8 +107,6 @@ - diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java index 453e898e..1bcb67ef 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java @@ -678,7 +678,6 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener, // Display the Version mVersion = (TextView) findViewById(R.id.version); mVersion.setText("Version: " + BuildInfo.version + - (AltosVersion.has_google_maps_api_key() ? " maps" : "") + " Built: " + BuildInfo.builddate + " " + BuildInfo.buildtime + " " + BuildInfo.buildtz + " (" + BuildInfo.branch + "-" + BuildInfo.commitnum + "-" + BuildInfo.commithash + ")"); diff --git a/altoslib/AltosMapStore.java b/altoslib/AltosMapStore.java index b1cfcbd7..abd8c240 100644 --- a/altoslib/AltosMapStore.java +++ b/altoslib/AltosMapStore.java @@ -48,9 +48,21 @@ public class AltosMapStore { chlat, lat, chlon, lon, maptype_string, zoom, scale == 1 ? "" : String.format("-%d", scale), format_string)); } + public static String google_maps_api_key = null; + + private static String google_map_url(AltosLatLon center, int zoom, int maptype, int px_size, int scale, String format_string) { + return String.format("http://maps.google.com/maps/api/staticmap?center=%.6f,%.6f&zoom=%d&size=%dx%d&scale=%d&sensor=false&maptype=%s&format=%s&key=%s", + center.lat, center.lon, zoom, px_size, px_size, scale, + AltosMap.maptype_names[maptype], format_string, google_maps_api_key); + } + + private static String altos_map_url(AltosLatLon center, int zoom, int maptype, int px_size, int scale, String format_string) { + return String.format("https://maps.altusmetrum.org/altos-map?center=%.6f,%.6f&zoom=%d", + center.lat, center.lon, zoom); + } + private static String map_url(AltosLatLon center, int zoom, int maptype, int px_size, int scale) { String format_string; - int z = zoom; if (maptype == AltosMap.maptype_hybrid || maptype == AltosMap.maptype_satellite || maptype == AltosMap.maptype_terrain) format_string = "jpg"; @@ -58,14 +70,14 @@ public class AltosMapStore { format_string = "png32"; for (int s = 1; s < scale; s <<= 1) - z--; + zoom--; - if (AltosVersion.has_google_maps_api_key()) - return String.format("http://maps.google.com/maps/api/staticmap?center=%.6f,%.6f&zoom=%d&size=%dx%d&scale=%d&sensor=false&maptype=%s&format=%s&key=%s", - center.lat, center.lon, z, px_size/scale, px_size/scale, scale, AltosMap.maptype_names[maptype], format_string, AltosVersion.google_maps_api_key); + px_size /= scale; + + if (google_maps_api_key != null) + return google_map_url(center, zoom, maptype, px_size, scale, format_string); else - return String.format("http://maps.google.com/maps/api/staticmap?center=%.6f,%.6f&zoom=%d&size=%dx%d&scale=%d&sensor=false&maptype=%s&format=%s", - center.lat, center.lon, z, px_size/scale, px_size/scale, AltosMap.maptype_names[maptype], format_string); + return altos_map_url(center, zoom, maptype, px_size, scale, format_string); } public synchronized int status() { @@ -209,24 +221,8 @@ public class AltosMapStore { int new_status; - if (!AltosVersion.has_google_maps_api_key()) { - synchronized (fetch_lock) { - long startTime = System.nanoTime(); - new_status = fetch_url(); - if (new_status == AltosMapTile.fetched) { - long duration_ms = (System.nanoTime() - startTime) / 1000000; - if (duration_ms < google_maps_ratelimit_ms) { - try { - Thread.sleep(google_maps_ratelimit_ms - duration_ms); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - } - } - } - } else { - new_status = fetch_url(); - } + new_status = fetch_url(); + notify_listeners(new_status); } finally { finish_fetcher(); diff --git a/altoslib/AltosVersion.java.in b/altoslib/AltosVersion.java.in index fd9256aa..6b660bb5 100644 --- a/altoslib/AltosVersion.java.in +++ b/altoslib/AltosVersion.java.in @@ -20,10 +20,4 @@ package org.altusmetrum.altoslib_13; public class AltosVersion { public final static String version = "@VERSION@"; - - public final static String google_maps_api_key = "@GOOGLEKEY@"; - - public static boolean has_google_maps_api_key() { - return google_maps_api_key != null && google_maps_api_key.length() > 1; - } } diff --git a/altosuilib/AltosUIConfigure.java b/altosuilib/AltosUIConfigure.java index e466f8b2..e61b5d52 100644 --- a/altosuilib/AltosUIConfigure.java +++ b/altosuilib/AltosUIConfigure.java @@ -270,9 +270,8 @@ public class AltosUIConfigure constraints(0, 3)); row++; - pane.add(new JLabel (String.format("AltOS version %s (%smaps key)", - AltosVersion.version, - AltosVersion.has_google_maps_api_key() ? "" : "no ")), + pane.add(new JLabel (String.format("AltOS version %s", + AltosVersion.version)), constraints(0, 3)); row++; diff --git a/configure.ac b/configure.ac index 1705745d..741fa013 100644 --- a/configure.ac +++ b/configure.ac @@ -172,26 +172,12 @@ AM_CONDITIONAL(FATINSTALL, [test "x$FATDIR" != "xnone"]) AC_SUBST(FATDIR) -AC_ARG_WITH(google-key, AS_HELP_STRING([--with-google-key=PATH], - [Set the file to read the google maps API key from (defaults to ~/altusmetrumllc/google-maps-api-key)]), - [GOOGLEKEYFILE=$withval], [GOOGLEKEYFILE=$HOME/altusmetrumllc/google-maps-api-key]) - -if test -r "$GOOGLEKEYFILE" -a -s "$GOOGLEKEYFILE"; then - GOOGLEKEY=`cat "$GOOGLEKEYFILE"` - HAVE_GOOGLE_KEY="yes" -else - GOOGLEKEY='null' - HAVE_GOOGLE_KEY="no" -fi - AC_ARG_ENABLE(faketime, AS_HELP_STRING([--enable-faketime], [Use faketime program to ensure pdf files are reproducible (default=no)]), [FAKETIME=$enableval], [FAKETIME=no]) AM_CONDITIONAL(FAKETIME, [test x$FAKETIME = xyes]) -AC_SUBST(GOOGLEKEY) - AC_PROG_CC AC_PROG_INSTALL AC_PROG_LN_S