aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2011-11-07 14:23:44 +0100
committerSamuel Tardieu <sam@rfc1149.net>2011-11-09 20:27:34 +0100
commit97803bb9bfaaa9b1b7cd2b0adf3c582ba3ca04b1 (patch)
treebffe3bb47f8632f9ed5f1026d469c5babdddd42d /main/src/cgeo
parent33ceb51ad3220bad6aaa6cb741d1365fcb061027 (diff)
downloadcgeo-97803bb9bfaaa9b1b7cd2b0adf3c582ba3ca04b1.zip
cgeo-97803bb9bfaaa9b1b7cd2b0adf3c582ba3ca04b1.tar.gz
cgeo-97803bb9bfaaa9b1b7cd2b0adf3c582ba3ca04b1.tar.bz2
Add new Viewport type to encompass Viewport information
Also, remove unused reason parameter.
Diffstat (limited to 'main/src/cgeo')
-rw-r--r--main/src/cgeo/geocaching/cgBase.java10
-rw-r--r--main/src/cgeo/geocaching/geopoint/Viewport.java35
-rw-r--r--main/src/cgeo/geocaching/maps/CGeoMap.java4
3 files changed, 45 insertions, 4 deletions
diff --git a/main/src/cgeo/geocaching/cgBase.java b/main/src/cgeo/geocaching/cgBase.java
index 25bfef4..4734820 100644
--- a/main/src/cgeo/geocaching/cgBase.java
+++ b/main/src/cgeo/geocaching/cgBase.java
@@ -12,6 +12,7 @@ import cgeo.geocaching.files.LocParser;
import cgeo.geocaching.geopoint.DistanceParser;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.geopoint.GeopointFormatter.Format;
+import cgeo.geocaching.geopoint.Viewport;
import cgeo.geocaching.network.HtmlImage;
import cgeo.geocaching.utils.BaseUtils;
import cgeo.geocaching.utils.CancellableHandler;
@@ -2183,12 +2184,15 @@ public class cgBase {
return searchByAny(thread, cacheType, false, reason, showCaptcha, params);
}
- public cgSearch searchByViewport(final String userToken, final double latMin, final double latMax, final double lonMin, final double lonMax, int reason) {
+ public cgSearch searchByViewport(final String userToken, final Viewport viewport) {
final cgSearch search = new cgSearch();
String page = null;
- final String params = "{\"dto\":{\"data\":{\"c\":1,\"m\":\"\",\"d\":\"" + latMax + "|" + latMin + "|" + lonMax + "|" + lonMin + "\"},\"ut\":\"" + StringUtils.defaultString(userToken) + "\"}}";
+ final String params = "{\"dto\":{\"data\":{\"c\":1,\"m\":\"\",\"d\":\"" +
+ viewport.getLatitudeMax() + "|" + viewport.getLatitudeMin() + "|" +
+ viewport.getLongitudeMax() + "|" + viewport.getLongitudeMin() + "\"},\"ut\":\"" +
+ StringUtils.defaultString(userToken) + "\"}}";
final String uri = "http://www.geocaching.com/map/default.aspx/MapAction";
page = requestJSONgc(uri, params);
@@ -2210,7 +2214,7 @@ public class cgBase {
List<cgCache> cacheList = filterSearchResults(search, caches, Settings.isExcludeDisabledCaches(), Settings.isExcludeMyCaches(), Settings.getCacheType());
- app.addSearch(cacheList, reason);
+ app.addSearch(cacheList, 0);
return search;
}
diff --git a/main/src/cgeo/geocaching/geopoint/Viewport.java b/main/src/cgeo/geocaching/geopoint/Viewport.java
new file mode 100644
index 0000000..ef80ae3
--- /dev/null
+++ b/main/src/cgeo/geocaching/geopoint/Viewport.java
@@ -0,0 +1,35 @@
+package cgeo.geocaching.geopoint;
+
+public class Viewport {
+
+ public final Geopoint bottomLeft;
+ public final Geopoint topRight;
+
+ public Viewport(final Geopoint bottomLeft, final Geopoint topRight) {
+ this.bottomLeft = bottomLeft;
+ this.topRight = topRight;
+ }
+
+ public Viewport(final Geopoint center, final double latSpan, final double lonSpan) {
+ final double centerLat = center.getLatitude();
+ final double centerLon = center.getLongitude();
+ bottomLeft = new Geopoint(centerLat - latSpan / 2, centerLon - lonSpan / 2);
+ topRight = new Geopoint(centerLat + latSpan / 2, centerLon + lonSpan / 2);
+ }
+
+ public double getLatitudeMin() {
+ return bottomLeft.getLatitude();
+ }
+
+ public double getLatitudeMax() {
+ return topRight.getLatitude();
+ }
+
+ public double getLongitudeMin() {
+ return bottomLeft.getLongitude();
+ }
+
+ public double getLongitudeMax() {
+ return topRight.getLongitude();
+ }
+}
diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java
index f7648be..67cf398 100644
--- a/main/src/cgeo/geocaching/maps/CGeoMap.java
+++ b/main/src/cgeo/geocaching/maps/CGeoMap.java
@@ -20,6 +20,7 @@ import cgeo.geocaching.apps.cache.navi.NavigationAppFactory;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.WaypointType;
import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.geopoint.Viewport;
import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl;
import cgeo.geocaching.maps.interfaces.GeoPointImpl;
import cgeo.geocaching.maps.interfaces.MapActivityImpl;
@@ -1302,7 +1303,8 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
return;
}
- search = base.searchByViewport(token, latMin, latMax, lonMin, lonMax, 0);
+ final Viewport viewport = new Viewport(new Geopoint(latMin, lonMin), new Geopoint(latMax, lonMax));
+ search = base.searchByViewport(token, viewport);
if (search != null) {
downloaded = true;
}