diff --git a/OsmAnd/src/net/osmand/plus/render/MapVectorLayer.java b/OsmAnd/src/net/osmand/plus/render/MapVectorLayer.java index 86dfd6a301..52fcaf64b0 100644 --- a/OsmAnd/src/net/osmand/plus/render/MapVectorLayer.java +++ b/OsmAnd/src/net/osmand/plus/render/MapVectorLayer.java @@ -1,5 +1,6 @@ package net.osmand.plus.render; +import android.util.Log; import net.osmand.core.android.MapRendererView; import net.osmand.core.android.TileSourceProxyProvider; import net.osmand.core.jni.MapLayerConfiguration; @@ -156,13 +157,19 @@ public class MapVectorLayer extends BaseMapLayer { mapRenderer.setVisualZoomShift(zoomMagnifier - 1.0f); } else { if (!view.isZooming()) { - if (resourceManager.updateRenderedMapNeeded(tilesRect, drawSettings) && - !view.isScreenViewDetached()) { + if (resourceManager.updateRenderedMapNeeded(tilesRect, drawSettings) || + view.isScreenViewDetached()) { // pixRect.set(-view.getWidth(), -view.getHeight() / 2, 2 * view.getWidth(), 3 * // view.getHeight() / 2); final RotatedTileBox copy = tilesRect.copy(); - copy.increasePixelDimensions(copy.getPixWidth() / 3, copy.getPixHeight() / 4); - resourceManager.updateRendererMap(copy, null); + Log.d("SERVER: ","SERVER: interrupt in layer"); + if (view.isScreenViewDetached()){ + resourceManager.getRenderer().loadMap(copy, resourceManager.getMapTileDownloader()); + } + else { + copy.increasePixelDimensions(copy.getPixWidth() / 3, copy.getPixHeight() / 4); + resourceManager.updateRendererMap(copy, null); + } } } @@ -175,7 +182,7 @@ public class MapVectorLayer extends BaseMapLayer { private boolean drawRenderedMap(Canvas canvas, Bitmap bmp, RotatedTileBox bmpLoc, RotatedTileBox currentViewport) { boolean shown = false; - if (bmp != null && bmpLoc != null) { + if (bmp != null && bmpLoc != null) { float rot = -bmpLoc.getRotate(); canvas.rotate(rot, currentViewport.getCenterPixelX(), currentViewport.getCenterPixelY()); final RotatedTileBox calc = currentViewport.copy(); diff --git a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java index 8b276c889a..74ca69c70c 100644 --- a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java +++ b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java @@ -1040,7 +1040,7 @@ public class ResourceManager { return renderer.updateMapIsNeeded(rotatedTileBox, drawSettings); } - public void updateRendererMap(RotatedTileBox rotatedTileBox, OnMapLoadedListener mapLoadedListener){ + public synchronized void updateRendererMap(RotatedTileBox rotatedTileBox, OnMapLoadedListener mapLoadedListener){ renderer.interruptLoadingMap(); asyncLoadingThread.requestToLoadMap(new MapLoadRequest(rotatedTileBox, mapLoadedListener)); } diff --git a/OsmAnd/src/net/osmand/plus/server/endpoints/TileEndpoint.java b/OsmAnd/src/net/osmand/plus/server/endpoints/TileEndpoint.java index 40501b9b3f..bb4cffa3d8 100644 --- a/OsmAnd/src/net/osmand/plus/server/endpoints/TileEndpoint.java +++ b/OsmAnd/src/net/osmand/plus/server/endpoints/TileEndpoint.java @@ -1,16 +1,13 @@ package net.osmand.plus.server.endpoints; -import android.graphics.*; -import androidx.annotation.GuardedBy; +import android.graphics.Bitmap; import fi.iki.elonen.NanoHTTPD; 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; +import net.osmand.plus.views.OsmandMapLayer; import org.apache.commons.logging.Log; import java.io.ByteArrayInputStream; @@ -36,7 +33,6 @@ public class TileEndpoint implements OsmAndHttpServer.ApiEndpoint { } - @Override public NanoHTTPD.Response process(NanoHTTPD.IHTTPSession session, String url) { // https://tile.osmand.net/hd/6/55/25.png @@ -56,7 +52,9 @@ public class TileEndpoint implements OsmAndHttpServer.ApiEndpoint { int y = Integer.parseInt(prms[3]); MetaTileFileSystemCache.MetaTileCache res = cache.get(zoom, x, y); if (res == null) { - lastRequestedZoom = zoom; + synchronized (this) { + lastRequestedZoom = zoom; + } res = requestMetatile(x, y, zoom); if (res == null) { return OsmAndHttpServer.ErrorResponses.response500; @@ -93,42 +91,30 @@ public class TileEndpoint implements OsmAndHttpServer.ApiEndpoint { mapActivity.getMapView().setCurrentViewport(res.bbox); int timeout = 0; try { - AsyncLoadingThread athread = resourceManager.getAsyncLoadingThread(); - resourceManager.updateRendererMap(res.bbox, null); + LOG.debug("SERVER: interrupt in request"); + resourceManager.getRenderer().loadMap(res.bbox, resourceManager.getMapTileDownloader()); + Thread.sleep(TIMEOUT_STEP); // to do line should be removed in future + OsmandMapLayer.DrawSettings drawSettings = + new OsmandMapLayer.DrawSettings(mapActivity.getMapView().getSettings().isLightContent(), + true); + mapActivity.getMapView().refreshMapInternal(drawSettings); + mapActivity.getMapView().refreshBaseMapInternal(res.bbox, drawSettings); 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; - } - Thread.sleep(TIMEOUT_STEP); - timeout += TIMEOUT_STEP; - } - mapActivity.getMapView().refreshMap(); // wait for image to be refreshed - while(!resourceManager.getRenderingBufferImageThread().getLooper().getQueue().isIdle() && + 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; -// Canvas canvas = new Canvas(tempBmp); -// Paint paint = new Paint(); -// paint.setColor(Color.RED); -// paint.setTextSize(12); -// paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); -// canvas.drawText("TIMEOUT", tempBmp.getWidth() / 2, tempBmp.getHeight() / 2, paint); - // here we could return stub - } res.bmp = rbmp.copy(rbmp.getConfig(), true); this.cache.put(res); - LOG.debug("Render metatile: " + (System.currentTimeMillis() - tm)/1000.0f); + LOG.debug("SERVER: metatile: " + (System.currentTimeMillis() - tm) / 1000.0f); return res; - } catch (InterruptedException e) { + } catch (Exception e) { LOG.error(e); } + LOG.debug("SERVER: metatile1: " + (System.currentTimeMillis() - tm) / 1000.0f); return null; } } diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index a3d06de9d7..71429e92f3 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -588,7 +588,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback { } } - private void refreshBaseMapInternal(RotatedTileBox tileBox, DrawSettings drawSettings) { + public void refreshBaseMapInternal(RotatedTileBox tileBox, DrawSettings drawSettings) { if (tileBox.getPixHeight() == 0 || tileBox.getPixWidth() == 0) { return; } @@ -625,7 +625,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback { additional.calculateFPS(start, end); } - private void refreshMapInternal(DrawSettings drawSettings) { + public void refreshMapInternal(DrawSettings drawSettings) { if (view == null) { return; } @@ -788,7 +788,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback { canvas.drawCircle(x, y, 7 * dm.density, paintCenter); } - private void refreshBufferImage(final DrawSettings drawSettings) { + public void refreshBufferImage(final DrawSettings drawSettings) { if (mapRenderer != null) { return; } @@ -831,16 +831,16 @@ public class OsmandMapTileView implements IMapDownloaderCallback { // this method could be called in non UI thread public void refreshMap(final boolean updateVectorRendering) { if ((view != null && view.isShown()) || isScreenViewDetached) { - boolean nightMode = application.getDaynightHelper().isNightMode(); - Boolean currentNightMode = this.nightMode; - boolean forceUpdateVectorDrawing = currentNightMode != null && currentNightMode != nightMode; - if (forceUpdateVectorDrawing) { - resetDefaultColor(); - } - this.nightMode = nightMode; - DrawSettings drawSettings = new DrawSettings(nightMode, updateVectorRendering || forceUpdateVectorDrawing); - sendRefreshMapMsg(drawSettings, 20); - refreshBufferImage(drawSettings); +// boolean nightMode = application.getDaynightHelper().isNightMode(); +// Boolean currentNightMode = this.nightMode; +// boolean forceUpdateVectorDrawing = currentNightMode != null && currentNightMode != nightMode; +// if (forceUpdateVectorDrawing) { +// resetDefaultColor(); +// } +// this.nightMode = nightMode; +// DrawSettings drawSettings = new DrawSettings(nightMode, updateVectorRendering || forceUpdateVectorDrawing); +// sendRefreshMapMsg(drawSettings, 20); +// refreshBufferImage(drawSettings); } } @@ -880,7 +880,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback { public void setCurrentViewport(RotatedTileBox viewport) { currentViewport = viewport; - refreshMap(true); + //refreshMap(true); } public Bitmap getBufferBitmap() {