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:
parent
865b834fb6
commit
748dd85321
7 changed files with 39 additions and 6 deletions
|
@ -88,7 +88,7 @@ public class AmenityIndexRepository {
|
|||
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();
|
||||
cTopLatitude = topLatitude + (topLatitude -bottomLatitude);
|
||||
cBottomLatitude = bottomLatitude - (topLatitude -bottomLatitude);
|
||||
|
@ -97,7 +97,7 @@ public class AmenityIndexRepository {
|
|||
cFilterId = filter == null? null :filter.getFilterId();
|
||||
// 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, -1, filter, tempList);
|
||||
searchAmenities(cTopLatitude, cLeftLongitude, cBottomLatitude, cRightLongitude, limit, filter, tempList);
|
||||
synchronized (this) {
|
||||
cachedAmenities.clear();
|
||||
cachedAmenities.addAll(tempList);
|
||||
|
|
|
@ -273,5 +273,19 @@ public class OsmandSettings {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,9 @@ import android.content.Context;
|
|||
public class PoiFiltersHelper {
|
||||
|
||||
public static PoiFilter getFilterById(Context ctx, String filterId){
|
||||
if(filterId == null){
|
||||
return null;
|
||||
}
|
||||
if(filterId.startsWith(PoiFilter.USER_PREFIX)){
|
||||
List<PoiFilter> filters = getUserDefinedPoiFilters(ctx);
|
||||
for(PoiFilter f : filters){
|
||||
|
|
|
@ -23,6 +23,7 @@ import com.osmand.data.preparation.MapTileDownloader.DownloadRequest;
|
|||
import com.osmand.data.preparation.MapTileDownloader.IMapDownloaderCallback;
|
||||
import com.osmand.map.ITileSource;
|
||||
import com.osmand.osm.MapUtils;
|
||||
import com.osmand.views.POIMapLayer;
|
||||
|
||||
/**
|
||||
* Resource manager is responsible to work with all resources
|
||||
|
@ -358,7 +359,7 @@ public class ResourceManager {
|
|||
if(!amenityLoaded){
|
||||
AmenityLoadRequest r = (AmenityLoadRequest) req;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -330,6 +330,7 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
|
|||
mapView.setZoom(OsmandSettings.getLastKnownMapZoom(this));
|
||||
}
|
||||
backToLocation.setVisibility(View.INVISIBLE);
|
||||
poiMapLayer.setFilter(OsmandSettings.getPoiFilterForMap(this));
|
||||
|
||||
|
||||
if(mapView.getLayers().contains(poiMapLayer) != OsmandSettings.isShowingPoiOverMap(this)){
|
||||
|
|
|
@ -16,6 +16,7 @@ import android.widget.ImageView;
|
|||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.osmand.OsmandSettings;
|
||||
import com.osmand.PoiFilter;
|
||||
import com.osmand.PoiFiltersHelper;
|
||||
import com.osmand.R;
|
||||
|
@ -41,6 +42,7 @@ public class SearchPoiFilterActivity extends ListActivity {
|
|||
Bundle bundle = new Bundle();
|
||||
Intent newIntent = new Intent(SearchPoiFilterActivity.this, SearchPOIActivity.class);
|
||||
// folder selected
|
||||
OsmandSettings.setPoiFilterForMap(this, filter.getFilterId());
|
||||
bundle.putString(SearchPOIActivity.AMENITY_FILTER, filter.getFilterId());
|
||||
newIntent.putExtras(bundle);
|
||||
startActivityForResult(newIntent, 0);
|
||||
|
|
|
@ -12,25 +12,37 @@ import android.graphics.RectF;
|
|||
import android.widget.Toast;
|
||||
|
||||
import com.osmand.OsmandSettings;
|
||||
import com.osmand.PoiFilter;
|
||||
import com.osmand.ResourceManager;
|
||||
import com.osmand.data.Amenity;
|
||||
import com.osmand.osm.MapUtils;
|
||||
|
||||
public class POIMapLayer implements OsmandMapLayer {
|
||||
// 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 OsmandMapTileView view;
|
||||
private List<Amenity> objects = new ArrayList<Amenity>();
|
||||
|
||||
private ResourceManager resourceManager;
|
||||
private PoiFilter filter;
|
||||
|
||||
@Override
|
||||
public boolean onLongPressEvent(PointF point) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public PoiFilter getFilter() {
|
||||
return filter;
|
||||
}
|
||||
|
||||
public void setFilter(PoiFilter filter) {
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(PointF point) {
|
||||
|
@ -79,7 +91,7 @@ public class POIMapLayer implements OsmandMapLayer {
|
|||
public int getRadiusPoi(int zoom){
|
||||
if(zoom < startZoom){
|
||||
return 0;
|
||||
} else if(zoom == 15){
|
||||
} else if(zoom <= 15){
|
||||
return 7;
|
||||
} else if(zoom == 16){
|
||||
return 10;
|
||||
|
@ -105,7 +117,7 @@ public class POIMapLayer implements OsmandMapLayer {
|
|||
double rightLongitude = MapUtils.getLongitudeFromTile(view.getZoom(), tileRect.right);
|
||||
|
||||
objects.clear();
|
||||
resourceManager.searchAmenitiesAsync(topLatitude, leftLongitude, bottomLatitude, rightLongitude, null, objects);
|
||||
resourceManager.searchAmenitiesAsync(topLatitude, leftLongitude, bottomLatitude, rightLongitude, filter, objects);
|
||||
for (Amenity o : objects) {
|
||||
int x = view.getMapXForPoint(o.getLocation().getLongitude());
|
||||
int y = view.getMapYForPoint(o.getLocation().getLatitude());
|
||||
|
|
Loading…
Reference in a new issue