implement amenity search from map index

git-svn-id: https://osmand.googlecode.com/svn/trunk@796 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-12-11 11:20:51 +00:00
parent 1148020d95
commit 39f4461f62
4 changed files with 65 additions and 12 deletions

View file

@ -14,11 +14,20 @@ public class ToDoConstants {
// For 0.5 release // For 0.5 release
// 104. Add activity to show current loaded indexes and information about them // 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. // 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 +) // 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 // 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) // 86. Allow to add/edit custom tags to POI objects (Issue)
// 96. Introduce settings for MPH, imperial units (Issue) // 96. Introduce settings for MPH, imperial units (Issue)

View file

@ -10,7 +10,7 @@
<LinearLayout android:layout_height="wrap_content" android:layout_width="wrap_content" <LinearLayout android:layout_height="wrap_content" android:layout_width="wrap_content"
android:background="@drawable/headliner" android:orientation="horizontal" android:id="@+id/Headliner" > android:background="@drawable/headliner" android:orientation="horizontal" android:id="@+id/Headliner" >
<ImageView android:src="@drawable/headline_osmand_icon" <ImageView android:src="@drawable/headline_osmand_icon"
android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginLeft="5dp"/> android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginLeft="15dp"/>
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" <TextView android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_marginLeft="0dp" android:layout_weight="1" android:layout_marginTop="5dp" android:layout_marginLeft="0dp" android:layout_weight="1" android:layout_marginTop="5dp"
android:text="OsmAnd" android:textColor="#000000" android:typeface="serif" android:textSize="20sp"/> android:text="OsmAnd" android:textColor="#000000" android:typeface="serif" android:textSize="20sp"/>

View file

@ -3,6 +3,7 @@ package net.osmand;
import gnu.trove.list.array.TIntArrayList; import gnu.trove.list.array.TIntArrayList;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.commons.logging.Log; 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.binary.BinaryMapIndexReader.TagValuePair;
import net.osmand.data.Amenity; import net.osmand.data.Amenity;
import net.osmand.data.AmenityType; import net.osmand.data.AmenityType;
import net.osmand.osm.LatLon;
import net.osmand.osm.MapRenderingTypes; import net.osmand.osm.MapRenderingTypes;
import net.osmand.osm.MapUtils; import net.osmand.osm.MapUtils;
import net.sf.junidecode.Junidecode; 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<Amenity> toFill, boolean fillFound) {
// TODO Auto-generated method stub
return false;
}
// Work with cache (for map copied from AmenityIndexRepositoryOdb)
private String cFilterId;
protected List<Amenity> cachedObjects = new ArrayList<Amenity>();
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<Amenity> 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 @Override
public void clearCache() { public void clearCache() {
// TODO Auto-generated method stub cachedObjects.clear();
cTopLatitude = 0;
cBottomLatitude = 0;
cRightLongitude = 0;
cLeftLongitude = 0;
cZoom = 0;
cFilterId = null;
} }
@Override @Override
public void evaluateCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom, public void evaluateCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom,
int limitPoi, PoiFilter filter, List<Amenity> toFill) { int limitPoi, PoiFilter filter, List<Amenity> 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<Amenity> tempList = new ArrayList<Amenity>();
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);
} }

View file

@ -406,6 +406,7 @@ public class ResourceManager {
} }
if(index.containsMapData()){ if(index.containsMapData()){
// that's not fully acceptable // that's not fully acceptable
// TODO
// try { // try {
// RandomAccessFile raf = new RandomAccessFile(f, "r"); //$NON-NLS-1$ // RandomAccessFile raf = new RandomAccessFile(f, "r"); //$NON-NLS-1$
// amenityRepositories.add(new AmenityIndexRepositoryBinary(new BinaryMapIndexReader(raf))); // amenityRepositories.add(new AmenityIndexRepositoryBinary(new BinaryMapIndexReader(raf)));