introduce filter for POI to show on map

git-svn-id: https://osmand.googlecode.com/svn/trunk@155 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-06-12 07:49:44 +00:00
parent 865b834fb6
commit 748dd85321
7 changed files with 39 additions and 6 deletions

View file

@ -88,7 +88,7 @@ public class AmenityIndexRepository {
cFilterId = null; cFilterId = null;
} }
public void evaluateCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, PoiFilter filter, List<Amenity> toFill){ public void evaluateCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int limit, PoiFilter filter, List<Amenity> toFill){
cachedAmenities.clear(); cachedAmenities.clear();
cTopLatitude = topLatitude + (topLatitude -bottomLatitude); cTopLatitude = topLatitude + (topLatitude -bottomLatitude);
cBottomLatitude = bottomLatitude - (topLatitude -bottomLatitude); cBottomLatitude = bottomLatitude - (topLatitude -bottomLatitude);
@ -97,7 +97,7 @@ public class AmenityIndexRepository {
cFilterId = filter == null? null :filter.getFilterId(); cFilterId = filter == null? null :filter.getFilterId();
// first of all put all entities in temp list in order to not freeze other read threads // first of all put all entities in temp list in order to not freeze other read threads
ArrayList<Amenity> tempList = new ArrayList<Amenity>(); ArrayList<Amenity> tempList = new ArrayList<Amenity>();
searchAmenities(cTopLatitude, cLeftLongitude, cBottomLatitude, cRightLongitude, -1, filter, tempList); searchAmenities(cTopLatitude, cLeftLongitude, cBottomLatitude, cRightLongitude, limit, filter, tempList);
synchronized (this) { synchronized (this) {
cachedAmenities.clear(); cachedAmenities.clear();
cachedAmenities.addAll(tempList); cachedAmenities.addAll(tempList);

View file

@ -273,5 +273,19 @@ public class OsmandSettings {
return prefs.edit().remove(LAST_SEARCHED_INTERSECTED_STREET).commit(); return prefs.edit().remove(LAST_SEARCHED_INTERSECTED_STREET).commit();
} }
public static final String SELECTED_POI_FILTER_FOR_MAP = "selected_poi_filter_for_map";
public static boolean setPoiFilterForMap(Context ctx, String filterId){
SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
return prefs.edit().putString(SELECTED_POI_FILTER_FOR_MAP, filterId).commit();
}
public static PoiFilter getPoiFilterForMap(Context ctx){
SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
String filterId = prefs.getString(SELECTED_POI_FILTER_FOR_MAP, null);
PoiFilter filter = PoiFiltersHelper.getFilterById(ctx, filterId);
if(filter != null){
return filter;
}
return new PoiFilter(null);
}
} }

View file

@ -12,6 +12,9 @@ import android.content.Context;
public class PoiFiltersHelper { public class PoiFiltersHelper {
public static PoiFilter getFilterById(Context ctx, String filterId){ public static PoiFilter getFilterById(Context ctx, String filterId){
if(filterId == null){
return null;
}
if(filterId.startsWith(PoiFilter.USER_PREFIX)){ if(filterId.startsWith(PoiFilter.USER_PREFIX)){
List<PoiFilter> filters = getUserDefinedPoiFilters(ctx); List<PoiFilter> filters = getUserDefinedPoiFilters(ctx);
for(PoiFilter f : filters){ for(PoiFilter f : filters){

View file

@ -23,6 +23,7 @@ import com.osmand.data.preparation.MapTileDownloader.DownloadRequest;
import com.osmand.data.preparation.MapTileDownloader.IMapDownloaderCallback; import com.osmand.data.preparation.MapTileDownloader.IMapDownloaderCallback;
import com.osmand.map.ITileSource; import com.osmand.map.ITileSource;
import com.osmand.osm.MapUtils; import com.osmand.osm.MapUtils;
import com.osmand.views.POIMapLayer;
/** /**
* Resource manager is responsible to work with all resources * Resource manager is responsible to work with all resources
@ -358,7 +359,7 @@ public class ResourceManager {
if(!amenityLoaded){ if(!amenityLoaded){
AmenityLoadRequest r = (AmenityLoadRequest) req; AmenityLoadRequest r = (AmenityLoadRequest) req;
r.repository.evaluateCachedAmenities(r.topLatitude, r.leftLongitude, r.repository.evaluateCachedAmenities(r.topLatitude, r.leftLongitude,
r.bottomLatitude, r.rightLongitude, r.filter, null); r.bottomLatitude, r.rightLongitude, POIMapLayer.LIMIT_POI, r.filter, null);
amenityLoaded = true; amenityLoaded = true;
} }
} }

View file

@ -330,6 +330,7 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
mapView.setZoom(OsmandSettings.getLastKnownMapZoom(this)); mapView.setZoom(OsmandSettings.getLastKnownMapZoom(this));
} }
backToLocation.setVisibility(View.INVISIBLE); backToLocation.setVisibility(View.INVISIBLE);
poiMapLayer.setFilter(OsmandSettings.getPoiFilterForMap(this));
if(mapView.getLayers().contains(poiMapLayer) != OsmandSettings.isShowingPoiOverMap(this)){ if(mapView.getLayers().contains(poiMapLayer) != OsmandSettings.isShowingPoiOverMap(this)){

View file

@ -16,6 +16,7 @@ import android.widget.ImageView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import com.osmand.OsmandSettings;
import com.osmand.PoiFilter; import com.osmand.PoiFilter;
import com.osmand.PoiFiltersHelper; import com.osmand.PoiFiltersHelper;
import com.osmand.R; import com.osmand.R;
@ -41,6 +42,7 @@ public class SearchPoiFilterActivity extends ListActivity {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
Intent newIntent = new Intent(SearchPoiFilterActivity.this, SearchPOIActivity.class); Intent newIntent = new Intent(SearchPoiFilterActivity.this, SearchPOIActivity.class);
// folder selected // folder selected
OsmandSettings.setPoiFilterForMap(this, filter.getFilterId());
bundle.putString(SearchPOIActivity.AMENITY_FILTER, filter.getFilterId()); bundle.putString(SearchPOIActivity.AMENITY_FILTER, filter.getFilterId());
newIntent.putExtras(bundle); newIntent.putExtras(bundle);
startActivityForResult(newIntent, 0); startActivityForResult(newIntent, 0);

View file

@ -12,25 +12,37 @@ import android.graphics.RectF;
import android.widget.Toast; import android.widget.Toast;
import com.osmand.OsmandSettings; import com.osmand.OsmandSettings;
import com.osmand.PoiFilter;
import com.osmand.ResourceManager; import com.osmand.ResourceManager;
import com.osmand.data.Amenity; import com.osmand.data.Amenity;
import com.osmand.osm.MapUtils; import com.osmand.osm.MapUtils;
public class POIMapLayer implements OsmandMapLayer { public class POIMapLayer implements OsmandMapLayer {
// it is very slow to use with 15 level // it is very slow to use with 15 level
private static final int startZoom = 15; private static final int startZoom = 10;
public static final int LIMIT_POI = 100;
private Paint pointAltUI; private Paint pointAltUI;
private OsmandMapTileView view; private OsmandMapTileView view;
private List<Amenity> objects = new ArrayList<Amenity>(); private List<Amenity> objects = new ArrayList<Amenity>();
private ResourceManager resourceManager; private ResourceManager resourceManager;
private PoiFilter filter;
@Override @Override
public boolean onLongPressEvent(PointF point) { public boolean onLongPressEvent(PointF point) {
return false; return false;
} }
public PoiFilter getFilter() {
return filter;
}
public void setFilter(PoiFilter filter) {
this.filter = filter;
}
@Override @Override
public boolean onTouchEvent(PointF point) { public boolean onTouchEvent(PointF point) {
@ -79,7 +91,7 @@ public class POIMapLayer implements OsmandMapLayer {
public int getRadiusPoi(int zoom){ public int getRadiusPoi(int zoom){
if(zoom < startZoom){ if(zoom < startZoom){
return 0; return 0;
} else if(zoom == 15){ } else if(zoom <= 15){
return 7; return 7;
} else if(zoom == 16){ } else if(zoom == 16){
return 10; return 10;
@ -105,7 +117,7 @@ public class POIMapLayer implements OsmandMapLayer {
double rightLongitude = MapUtils.getLongitudeFromTile(view.getZoom(), tileRect.right); double rightLongitude = MapUtils.getLongitudeFromTile(view.getZoom(), tileRect.right);
objects.clear(); objects.clear();
resourceManager.searchAmenitiesAsync(topLatitude, leftLongitude, bottomLatitude, rightLongitude, null, objects); resourceManager.searchAmenitiesAsync(topLatitude, leftLongitude, bottomLatitude, rightLongitude, filter, objects);
for (Amenity o : objects) { for (Amenity o : objects) {
int x = view.getMapXForPoint(o.getLocation().getLongitude()); int x = view.getMapXForPoint(o.getLocation().getLongitude());
int y = view.getMapYForPoint(o.getLocation().getLatitude()); int y = view.getMapYForPoint(o.getLocation().getLatitude());