From b5a24dc23bc05c5c97bc0402affccaa163b72841 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 11 Sep 2020 11:25:22 +0200 Subject: [PATCH] Fix viewport change --- .../osmand/plus/server/endpoints/TileEndpoint.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/server/endpoints/TileEndpoint.java b/OsmAnd/src/net/osmand/plus/server/endpoints/TileEndpoint.java index 3c4bde9ad7..40501b9b3f 100644 --- a/OsmAnd/src/net/osmand/plus/server/endpoints/TileEndpoint.java +++ b/OsmAnd/src/net/osmand/plus/server/endpoints/TileEndpoint.java @@ -7,6 +7,7 @@ import net.osmand.PlatformUtil; import net.osmand.data.RotatedTileBox; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.resources.AsyncLoadingThread; +import net.osmand.plus.resources.ResourceManager; import net.osmand.plus.server.OsmAndHttpServer; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.util.MapUtils; @@ -80,6 +81,7 @@ public class TileEndpoint implements OsmAndHttpServer.ApiEndpoint { private synchronized MetaTileFileSystemCache.MetaTileCache requestMetatile(int x, int y, int zoom) { long tm = System.currentTimeMillis(); MapActivity mapActivity = server.getMapActivity(); + ResourceManager resourceManager = mapActivity.getMyApplication().getResourceManager(); if (mapActivity == null) { return null; } @@ -91,9 +93,10 @@ public class TileEndpoint implements OsmAndHttpServer.ApiEndpoint { mapActivity.getMapView().setCurrentViewport(res.bbox); int timeout = 0; try { - AsyncLoadingThread athread = mapActivity.getMyApplication().getResourceManager().getAsyncLoadingThread(); - mapActivity.getMyApplication().getResourceManager().updateRendererMap(res.bbox, null); + AsyncLoadingThread athread = resourceManager.getAsyncLoadingThread(); + resourceManager.updateRendererMap(res.bbox, null); Thread.sleep(TIMEOUT_STEP); // to do line should be removed in future + // wait till all resources rendered and loaded while (athread.areResourcesLoading() && timeout < TIMEOUT) { if(lastRequestedZoom != zoom) { return null; @@ -101,6 +104,13 @@ public class TileEndpoint implements OsmAndHttpServer.ApiEndpoint { Thread.sleep(TIMEOUT_STEP); timeout += TIMEOUT_STEP; } + mapActivity.getMapView().refreshMap(); + // wait for image to be refreshed + while(!resourceManager.getRenderingBufferImageThread().getLooper().getQueue().isIdle() && + timeout < TIMEOUT) { + Thread.sleep(TIMEOUT_STEP); + timeout += TIMEOUT_STEP; + } Bitmap rbmp = mapActivity.getMapView().getBufferBitmap(); if (timeout >= TIMEOUT) { return null;