From 39f4461f62d0e17fc4efb3a684d78ab7cd5ecd5e Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sat, 11 Dec 2010 11:20:51 +0000 Subject: [PATCH] implement amenity search from map index git-svn-id: https://osmand.googlecode.com/svn/trunk@796 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8 --- .../src/net/osmand/ToDoConstants.java | 11 +++- OsmAnd/res/layout-land/menu.xml | 2 +- .../osmand/AmenityIndexRepositoryBinary.java | 63 ++++++++++++++++--- OsmAnd/src/net/osmand/ResourceManager.java | 1 + 4 files changed, 65 insertions(+), 12 deletions(-) diff --git a/DataExtractionOSM/src/net/osmand/ToDoConstants.java b/DataExtractionOSM/src/net/osmand/ToDoConstants.java index 379601615b..b0defa8ecf 100644 --- a/DataExtractionOSM/src/net/osmand/ToDoConstants.java +++ b/DataExtractionOSM/src/net/osmand/ToDoConstants.java @@ -14,11 +14,20 @@ public class ToDoConstants { // For 0.5 release // 104. Add activity to show current loaded indexes and information about them - // 97. For voice navigation consider current speed of vehicle. Especially when speed > 50 pronounce more than 200 m // 108. Auto switch at night rendering. + + // 97. For voice navigation consider current speed of vehicle. Especially when speed > 50 pronounce more than 200 m + // 112. Investigate exiting/minimizing app (Issue) // 92. Support poi index with standard map index and unify POI categories (unify done +) + // Done partially (works very slow), + // possibly introduce settings to limit usage of functionality or put poi index into binary index // Outside base 0.5 release + // 109. Update download index activity (introduce select/deselect all, update existing) + // and make green text for already loaded indexes. + // 113. Calculate speed cameras/bumps on the road (announce about them) + // 110. Use android voice for pronounce command (could be used in future to pronounce street) + // 111. Investigate showing street name while driving // 86. Allow to add/edit custom tags to POI objects (Issue) // 96. Introduce settings for MPH, imperial units (Issue) diff --git a/OsmAnd/res/layout-land/menu.xml b/OsmAnd/res/layout-land/menu.xml index 65f8c60e26..ae95837d4b 100644 --- a/OsmAnd/res/layout-land/menu.xml +++ b/OsmAnd/res/layout-land/menu.xml @@ -10,7 +10,7 @@ + android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginLeft="15dp"/> diff --git a/OsmAnd/src/net/osmand/AmenityIndexRepositoryBinary.java b/OsmAnd/src/net/osmand/AmenityIndexRepositoryBinary.java index d326c8be36..d31d70b365 100644 --- a/OsmAnd/src/net/osmand/AmenityIndexRepositoryBinary.java +++ b/OsmAnd/src/net/osmand/AmenityIndexRepositoryBinary.java @@ -3,6 +3,7 @@ package net.osmand; import gnu.trove.list.array.TIntArrayList; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import org.apache.commons.logging.Log; @@ -17,6 +18,7 @@ import net.osmand.binary.BinaryMapIndexReader.SearchRequest; import net.osmand.binary.BinaryMapIndexReader.TagValuePair; import net.osmand.data.Amenity; import net.osmand.data.AmenityType; +import net.osmand.osm.LatLon; import net.osmand.osm.MapRenderingTypes; import net.osmand.osm.MapUtils; import net.sf.junidecode.Junidecode; @@ -164,24 +166,65 @@ public class AmenityIndexRepositoryBinary implements AmenityIndexRepository { } - @Override - public boolean checkCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom, - String filterId, List toFill, boolean fillFound) { - // TODO Auto-generated method stub - return false; - } + + + // Work with cache (for map copied from AmenityIndexRepositoryOdb) + private String cFilterId; + protected List cachedObjects = new ArrayList(); + protected double cTopLatitude; + protected double cBottomLatitude; + protected double cLeftLongitude; + protected double cRightLongitude; + protected int cZoom; + + public synchronized boolean checkCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, + int zoom, String filterId, List toFill, boolean fillFound){ + boolean inside = cTopLatitude >= topLatitude && cLeftLongitude <= leftLongitude && cRightLongitude >= rightLongitude + && cBottomLatitude <= bottomLatitude && zoom == cZoom; + boolean noNeedToSearch = inside && Algoritms.objectEquals(filterId, cFilterId); + if((inside || fillFound) && toFill != null && Algoritms.objectEquals(filterId, cFilterId)){ + for(Amenity a : cachedObjects){ + LatLon location = a.getLocation(); + if (location.getLatitude() <= topLatitude && location.getLongitude() >= leftLongitude && location.getLongitude() <= rightLongitude + && location.getLatitude() >= bottomLatitude) { + toFill.add(a); + } + } + } + return noNeedToSearch; + } + @Override public void clearCache() { - // TODO Auto-generated method stub - + cachedObjects.clear(); + cTopLatitude = 0; + cBottomLatitude = 0; + cRightLongitude = 0; + cLeftLongitude = 0; + cZoom = 0; + cFilterId = null; } @Override public void evaluateCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom, int limitPoi, PoiFilter filter, List toFill) { - // TODO Auto-generated method stub - + cTopLatitude = topLatitude + (topLatitude - bottomLatitude); + cBottomLatitude = bottomLatitude - (topLatitude - bottomLatitude); + cLeftLongitude = leftLongitude - (rightLongitude - leftLongitude); + cRightLongitude = rightLongitude + (rightLongitude - leftLongitude); + cFilterId = filter == null ? null : filter.getFilterId(); + cZoom = zoom; + // first of all put all entities in temp list in order to not freeze other read threads + ArrayList tempList = new ArrayList(); + searchAmenities(cTopLatitude, cLeftLongitude, cBottomLatitude, cRightLongitude, limitPoi, filter, tempList); + synchronized (this) { + cachedObjects.clear(); + cachedObjects.addAll(tempList); + } + + checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, cZoom, filter.getFilterId(), toFill, true); + } diff --git a/OsmAnd/src/net/osmand/ResourceManager.java b/OsmAnd/src/net/osmand/ResourceManager.java index 58e4ad121b..3103f37b59 100644 --- a/OsmAnd/src/net/osmand/ResourceManager.java +++ b/OsmAnd/src/net/osmand/ResourceManager.java @@ -406,6 +406,7 @@ public class ResourceManager { } if(index.containsMapData()){ // that's not fully acceptable + // TODO // try { // RandomAccessFile raf = new RandomAccessFile(f, "r"); //$NON-NLS-1$ // amenityRepositories.add(new AmenityIndexRepositoryBinary(new BinaryMapIndexReader(raf)));