aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/StaticMapsProvider.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/StaticMapsProvider.java')
-rw-r--r--main/src/cgeo/geocaching/StaticMapsProvider.java48
1 files changed, 27 insertions, 21 deletions
diff --git a/main/src/cgeo/geocaching/StaticMapsProvider.java b/main/src/cgeo/geocaching/StaticMapsProvider.java
index 9c17a34..fc55949 100644
--- a/main/src/cgeo/geocaching/StaticMapsProvider.java
+++ b/main/src/cgeo/geocaching/StaticMapsProvider.java
@@ -1,10 +1,10 @@
package cgeo.geocaching;
import cgeo.geocaching.concurrent.BlockingThreadPool;
-import cgeo.geocaching.concurrent.Task;
import cgeo.geocaching.files.LocalStorage;
import cgeo.geocaching.geopoint.GeopointFormatter.Format;
import cgeo.geocaching.network.Network;
+import cgeo.geocaching.network.Parameters;
import cgeo.geocaching.utils.Log;
import org.apache.commons.collections.CollectionUtils;
@@ -30,7 +30,7 @@ public class StaticMapsProvider {
return LocalStorage.getStorageFile(geocode, "map_" + prefix + level, false, createDirs);
}
- private static void downloadDifferentZooms(final cgCache cache, String markerUrl, String prefix, String latlonMap, int edge, String waypoints) {
+ private static void downloadDifferentZooms(final cgCache cache, String markerUrl, String prefix, String latlonMap, int edge, final Parameters waypoints) {
downloadMap(cache, 20, "satellite", markerUrl, prefix, 1, latlonMap, edge, waypoints);
downloadMap(cache, 18, "satellite", markerUrl, prefix, 2, latlonMap, edge, waypoints);
downloadMap(cache, 16, "roadmap", markerUrl, prefix, 3, latlonMap, edge, waypoints);
@@ -38,13 +38,22 @@ public class StaticMapsProvider {
downloadMap(cache, 11, "roadmap", markerUrl, prefix, 5, latlonMap, edge, waypoints);
}
- private static void downloadMap(cgCache cache, int zoom, String mapType, String markerUrl, String prefix, int level, String latlonMap, int edge, String waypoints) {
- final String mapUrl = "http://maps.google.com/maps/api/staticmap?center=" + latlonMap;
- final String url = mapUrl + "&zoom=" + zoom + "&size=" + edge + "x" + edge + "&maptype=" + mapType + "&markers=icon%3A" + markerUrl + "%7C" + latlonMap + waypoints + "&sensor=false";
- final File file = getMapFile(cache.getGeocode(), prefix, level, true);
- final HttpResponse httpResponse = Network.request(url, null, false);
+ private static void downloadMap(cgCache cache, int zoom, String mapType, String markerUrl, String prefix, int level, String latlonMap, int edge, final Parameters waypoints) {
+ final String mapUrl = "http://maps.google.com/maps/api/staticmap";
+ final Parameters params = new Parameters(
+ "center", latlonMap,
+ "zoom", String.valueOf(zoom),
+ "size", edge + "x" + edge,
+ "maptype", mapType,
+ "markers", "icon:" + markerUrl + '|' + latlonMap,
+ "sensor", "false");
+ if (waypoints != null) {
+ params.addAll(waypoints);
+ }
+ final HttpResponse httpResponse = Network.getRequest(mapUrl, params);
if (httpResponse != null) {
+ final File file = getMapFile(cache.getGeocode(), prefix, level, true);
if (LocalStorage.saveEntityToFile(httpResponse, file)) {
// Delete image if it has no contents
final long fileSize = file.length();
@@ -96,7 +105,7 @@ public class StaticMapsProvider {
String wpLatlonMap = waypoint.getCoords().format(Format.LAT_LON_DECDEGREE_COMMA);
String wpMarkerUrl = getWpMarkerUrl(waypoint);
// download map images in separate background thread for higher performance
- downloadMaps(cache, wpMarkerUrl, "wp" + waypoint.getId() + "_", wpLatlonMap, edge, "", waitForResult);
+ downloadMaps(cache, wpMarkerUrl, "wp" + waypoint.getId() + "_", wpLatlonMap, edge, null, waitForResult);
}
public static void storeCacheStaticMap(cgCache cache, Activity activity, final boolean waitForResult) {
@@ -106,22 +115,19 @@ public class StaticMapsProvider {
private static void storeCacheStaticMap(cgCache cache, int edge, final boolean waitForResult) {
final String latlonMap = cache.getCoords().format(Format.LAT_LON_DECDEGREE_COMMA);
- final StringBuilder waypoints = new StringBuilder();
+ final Parameters waypoints = new Parameters();
if (cache.hasWaypoints()) {
for (cgWaypoint waypoint : cache.getWaypoints()) {
if (waypoint.getCoords() == null) {
continue;
}
- String wpMarkerUrl = getWpMarkerUrl(waypoint);
- waypoints.append("&markers=icon%3A");
- waypoints.append(wpMarkerUrl);
- waypoints.append("%7C");
- waypoints.append(waypoint.getCoords().format(Format.LAT_LON_DECDEGREE_COMMA));
+ final String wpMarkerUrl = getWpMarkerUrl(waypoint);
+ waypoints.put("markers", "icon:" + wpMarkerUrl + "|" + waypoint.getCoords().format(Format.LAT_LON_DECDEGREE_COMMA));
}
}
// download map images in separate background thread for higher performance
final String cacheMarkerUrl = getCacheMarkerUrl(cache);
- downloadMaps(cache, cacheMarkerUrl, "", latlonMap, edge, waypoints.toString(), waitForResult);
+ downloadMaps(cache, cacheMarkerUrl, "", latlonMap, edge, waypoints, waitForResult);
}
private static int guessMinDisplaySide(Display display) {
@@ -141,12 +147,12 @@ public class StaticMapsProvider {
}
private static void downloadMaps(final cgCache cache, final String markerUrl, final String prefix, final String latlonMap, final int edge,
- final String waypoints, boolean waitForResult) {
+ final Parameters waypoints, boolean waitForResult) {
if (waitForResult) {
downloadDifferentZooms(cache, markerUrl, prefix, latlonMap, edge, waypoints);
}
else {
- Task currentTask = new Task("getting static map") {
+ final Runnable currentTask = new Runnable() {
@Override
public void run() {
downloadDifferentZooms(cache, markerUrl, prefix, latlonMap, edge, waypoints);
@@ -155,7 +161,7 @@ public class StaticMapsProvider {
try {
pool.add(currentTask, 20, TimeUnit.SECONDS);
} catch (InterruptedException e) {
- Log.e(Settings.tag, "StaticMapsProvider.downloadMaps error adding task: " + e.toString());
+ Log.e("StaticMapsProvider.downloadMaps error adding task: " + e.toString());
}
}
}
@@ -168,12 +174,12 @@ public class StaticMapsProvider {
type += "_disabled";
}
- return Network.urlencode_rfc3986(MARKERS_URL + "marker_cache_" + type + ".png");
+ return MARKERS_URL + "marker_cache_" + type + ".png";
}
private static String getWpMarkerUrl(final cgWaypoint waypoint) {
String type = waypoint.getWaypointType() != null ? waypoint.getWaypointType().id : null;
- return Network.urlencode_rfc3986(MARKERS_URL + "marker_waypoint_" + type + ".png");
+ return MARKERS_URL + "marker_waypoint_" + type + ".png";
}
public static void removeWpStaticMaps(int wp_id, String geocode) {
@@ -183,7 +189,7 @@ public class StaticMapsProvider {
StaticMapsProvider.getMapFile(geocode, "wp" + wp_id + "_", level, false).delete();
}
} catch (Exception e) {
- Log.e(Settings.tag, "StaticMapsProvider.removeWpStaticMaps: " + e.toString());
+ Log.e("StaticMapsProvider.removeWpStaticMaps: " + e.toString());
}
}
}