diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2012-04-14 12:32:39 +0200 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2012-04-14 12:52:17 +0200 |
| commit | 01700beb4d05b01502cdd46d80d2fc5beb3d458d (patch) | |
| tree | d71f89808b95e6426c2463ecd2080e05a5dc22a4 | |
| parent | 82ee19f07fdc8c43ba6746eb1831309fea6c2f81 (diff) | |
| download | cgeo-01700beb4d05b01502cdd46d80d2fc5beb3d458d.zip cgeo-01700beb4d05b01502cdd46d80d2fc5beb3d458d.tar.gz cgeo-01700beb4d05b01502cdd46d80d2fc5beb3d458d.tar.bz2 | |
Use Viewport instead of cooked-up list of Numbers
| -rw-r--r-- | main/src/cgeo/geocaching/cgData.java | 28 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgeoapplication.java | 5 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/connector/gc/GCBase.java | 7 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/maps/CGeoMap.java | 23 |
4 files changed, 15 insertions, 48 deletions
diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java index 4a013dd..9fa3df1 100644 --- a/main/src/cgeo/geocaching/cgData.java +++ b/main/src/cgeo/geocaching/cgData.java @@ -10,6 +10,7 @@ import cgeo.geocaching.enumerations.LogType; import cgeo.geocaching.enumerations.WaypointType; import cgeo.geocaching.files.LocalStorage; import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.geopoint.Viewport; import cgeo.geocaching.utils.Log; import org.apache.commons.collections.CollectionUtils; @@ -1748,34 +1749,13 @@ public class cgData { return true; } - public List<Number> getBounds(Set<String> geocodes) { + public Viewport getBounds(final Set<String> geocodes) { if (CollectionUtils.isEmpty(geocodes)) { return null; } final Set<cgCache> caches = loadCaches(geocodes, LoadFlags.LOAD_CACHE_OR_DB); - - double latMin = 360.0; - double latMax = -360.0; - double lonMin = 360.0; - double lonMax = -360.0; - for (cgCache cache : caches) { - final Geopoint coords = cache.getCoords(); - double latitude = coords.getLatitude(); - latMin = Math.min(latitude, latMin); - latMax = Math.max(latitude, latMax); - double longitude = coords.getLongitude(); - lonMin = Math.min(longitude, lonMin); - lonMax = Math.max(longitude, lonMax); - } - - final List<Number> viewport = new ArrayList<Number>(); - viewport.add(caches.size()); - viewport.add(latMin); - viewport.add(latMax); - viewport.add(lonMin); - viewport.add(lonMax); - return viewport; + return Viewport.containing(caches); } /** @@ -2733,7 +2713,7 @@ public class cgData { /** * Loads the geocodes of caches in a viewport from CacheCache and/or Database - * + * * @param stored * True - query only stored caches, False - query cached ones as well * @param centerLat diff --git a/main/src/cgeo/geocaching/cgeoapplication.java b/main/src/cgeo/geocaching/cgeoapplication.java index 9ad9c4c..abead59 100644 --- a/main/src/cgeo/geocaching/cgeoapplication.java +++ b/main/src/cgeo/geocaching/cgeoapplication.java @@ -7,6 +7,7 @@ import cgeo.geocaching.enumerations.LoadFlags.LoadFlag; import cgeo.geocaching.enumerations.LoadFlags.RemoveFlag; import cgeo.geocaching.enumerations.LogType; import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.geopoint.Viewport; import cgeo.geocaching.utils.Log; import org.apache.commons.lang3.StringUtils; @@ -276,7 +277,7 @@ public class cgeoapplication extends Application { return storage.allDetailedThere(); } - public List<Number> getBounds(String geocode) { + public Viewport getBounds(String geocode) { if (geocode == null) { return null; } @@ -285,7 +286,7 @@ public class cgeoapplication extends Application { } /** {@link cgData#getBounds(Set)} */ - public List<Number> getBounds(final Set<String> geocodes) { + public Viewport getBounds(final Set<String> geocodes) { return storage.getBounds(geocodes); } diff --git a/main/src/cgeo/geocaching/connector/gc/GCBase.java b/main/src/cgeo/geocaching/connector/gc/GCBase.java index dc95793..99282c1 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCBase.java +++ b/main/src/cgeo/geocaching/connector/gc/GCBase.java @@ -188,10 +188,9 @@ public class GCBase { if ((lastSearchViewport == null) || !lastSearchViewport.contains(center)) { SearchResult search = cgBase.searchByCoords(null, center, Settings.getCacheType(), false); if (search != null && !search.isEmpty()) { - - List<Number> bounds = cgeoapplication.getInstance().getBounds(search.getGeocodes()); - lastSearchViewport = new Viewport(bounds.get(1).doubleValue(), bounds.get(2).doubleValue(), bounds.get(4).doubleValue(), bounds.get(3).doubleValue()); - searchResult.addGeocodes(search.getGeocodes()); + final Set<String> geocodes = search.getGeocodes(); + lastSearchViewport = cgeoapplication.getInstance().getBounds(geocodes); + searchResult.addGeocodes(geocodes); } } } diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index e3c7ea8..6853c3b 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -1526,10 +1526,6 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto } } - private static Viewport listToViewport(final List<Number> l) { - return new Viewport(new Geopoint(l.get(1).doubleValue(), l.get(3).doubleValue()), new Geopoint(l.get(2).doubleValue(), l.get(4).doubleValue())); - } - // move map to view results of searchIntent private void centerMap(String geocodeCenter, final SearchResult searchCenter, final Geopoint coordsCenter, int[] mapState) { @@ -1545,27 +1541,18 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto alreadyCentered = true; } else if (!centered && (geocodeCenter != null || searchIntent != null)) { try { - List<Number> vp = null; + Viewport viewport = null; if (geocodeCenter != null) { - vp = app.getBounds(geocodeCenter); - } else { - if (searchCenter != null) { - vp = app.getBounds(searchCenter.getGeocodes()); - } + viewport = app.getBounds(geocodeCenter); + } else if (searchCenter != null) { + viewport = app.getBounds(searchCenter.getGeocodes()); } - if (vp == null || vp.size() < 5) { + if (viewport == null) { return; } - int cnt = (Integer) vp.get(0); - if (cnt <= 0) { - return; - } - - final Viewport viewport = listToViewport(vp); - mapController.setCenter(mapProvider.getGeoPointBase(viewport.center)); if (viewport.getLatitudeSpan() != 0 && viewport.getLongitudeSpan() != 0) { mapController.zoomToSpan((int) (viewport.getLatitudeSpan() * 1e6), (int) (viewport.getLongitudeSpan() * 1e6)); |
