Skip to content

Commit

Permalink
Introduce db cache
Browse files Browse the repository at this point in the history
  • Loading branch information
vshcherb committed Feb 21, 2025
1 parent b9861a3 commit e3eefc9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

public interface ExplorePlacesProvider {

public final int MAX_LEVEL_ZOOM_CACHE = 13;
@NotNull List<ExploreTopPlacePoint> getDataCollection(QuadRect mapRect);

@NotNull List<ExploreTopPlacePoint> getDataCollection(QuadRect mapRect, int limit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ExplorePlacesProviderJava implements ExplorePlacesProvider {
private static final int DEFAULT_LIMIT_POINTS = 200;
private static final int NEARBY_MIN_RADIUS = 50;

private final int MAX_LEVEL_ZOOM_CACHE = 13;

private static final int MAX_TILES_PER_QUAD_RECT = 12;
private static final double LOAD_ALL_TINY_RECT = 0.5;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class ExploreTopPlacesLayer extends OsmandMapLayer implements IContextMen
private Bitmap cachedSmallIconBitmap;

private QuadRect requestQuadRect = null; // null means disabled
private int requestZoom = 0; // null means disabled


private ExploreTopPlacesTileProvider topPlacesMapLayerProvider;
Expand Down Expand Up @@ -113,16 +114,18 @@ public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSett
boolean nightMode = settings != null && settings.isNightMode();
boolean nightModeChanged = this.nightMode != nightMode;
this.nightMode = nightMode;
QuadRect cachedRect = requestQuadRect;
boolean placesUpdated = false;
if (requestQuadRect != null) {
int exploreDataVersion = explorePlacesProvider.getDataVersion();
if (!cachedRect.contains(tileBox.getLatLonBounds()) || cachedExploreDataVersion < exploreDataVersion ||
places == null) {
if (!requestQuadRect.contains(tileBox.getLatLonBounds()) ||
cachedExploreDataVersion < exploreDataVersion || places == null ||
(requestZoom < tileBox.getZoom() && requestZoom < ExplorePlacesProvider.MAX_LEVEL_ZOOM_CACHE)) {
placesUpdated = true;
RotatedTileBox extended = tileBox.copy();
extended.increasePixelDimensions(tileBox.getPixWidth() / 2, tileBox.getPixHeight() / 2);
requestQuadRect = extended.getLatLonBounds();
requestZoom = tileBox.getZoom();

cachedExploreDataVersion = explorePlacesProvider.getDataVersion();
places = explorePlacesProvider.getDataCollection(requestQuadRect);
scheduleImageRefreshes(places);
Expand Down Expand Up @@ -353,7 +356,8 @@ public void onPrepareLoad(Drawable placeHolderDrawable) {
}

public void enableLayer(boolean enable) {
requestQuadRect = enable ? new QuadRect() : null;
requestQuadRect = enable ?
new QuadRect() : null;
}

@Override
Expand Down

0 comments on commit e3eefc9

Please sign in to comment.