diff --git a/OsmAnd/src/com/osmand/AmenityIndexRepository.java b/OsmAnd/src/com/osmand/AmenityIndexRepository.java index bc36ca4b57..5fc524133c 100644 --- a/OsmAnd/src/com/osmand/AmenityIndexRepository.java +++ b/OsmAnd/src/com/osmand/AmenityIndexRepository.java @@ -88,7 +88,7 @@ public class AmenityIndexRepository { cFilterId = null; } - public void evaluateCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, PoiFilter filter, List toFill){ + public void evaluateCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int limit, PoiFilter filter, List 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 tempList = new ArrayList(); - searchAmenities(cTopLatitude, cLeftLongitude, cBottomLatitude, cRightLongitude, -1, filter, tempList); + searchAmenities(cTopLatitude, cLeftLongitude, cBottomLatitude, cRightLongitude, limit, filter, tempList); synchronized (this) { cachedAmenities.clear(); cachedAmenities.addAll(tempList); diff --git a/OsmAnd/src/com/osmand/OsmandSettings.java b/OsmAnd/src/com/osmand/OsmandSettings.java index e320499af1..c09ed31e1f 100644 --- a/OsmAnd/src/com/osmand/OsmandSettings.java +++ b/OsmAnd/src/com/osmand/OsmandSettings.java @@ -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); + } } diff --git a/OsmAnd/src/com/osmand/PoiFiltersHelper.java b/OsmAnd/src/com/osmand/PoiFiltersHelper.java index 96c15fa4ea..5b580146eb 100644 --- a/OsmAnd/src/com/osmand/PoiFiltersHelper.java +++ b/OsmAnd/src/com/osmand/PoiFiltersHelper.java @@ -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 filters = getUserDefinedPoiFilters(ctx); for(PoiFilter f : filters){ diff --git a/OsmAnd/src/com/osmand/ResourceManager.java b/OsmAnd/src/com/osmand/ResourceManager.java index 830b818a8b..2b5e43cabc 100644 --- a/OsmAnd/src/com/osmand/ResourceManager.java +++ b/OsmAnd/src/com/osmand/ResourceManager.java @@ -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; } } diff --git a/OsmAnd/src/com/osmand/activities/MapActivity.java b/OsmAnd/src/com/osmand/activities/MapActivity.java index 7024794eef..99192c2c4a 100644 --- a/OsmAnd/src/com/osmand/activities/MapActivity.java +++ b/OsmAnd/src/com/osmand/activities/MapActivity.java @@ -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)){ diff --git a/OsmAnd/src/com/osmand/activities/search/SearchPoiFilterActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchPoiFilterActivity.java index ee0ccdb38e..b961f52613 100644 --- a/OsmAnd/src/com/osmand/activities/search/SearchPoiFilterActivity.java +++ b/OsmAnd/src/com/osmand/activities/search/SearchPoiFilterActivity.java @@ -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); diff --git a/OsmAnd/src/com/osmand/views/POIMapLayer.java b/OsmAnd/src/com/osmand/views/POIMapLayer.java index ac49b2e010..f0ed1cd4b9 100644 --- a/OsmAnd/src/com/osmand/views/POIMapLayer.java +++ b/OsmAnd/src/com/osmand/views/POIMapLayer.java @@ -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 objects = new ArrayList(); 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());