From a92bac55f7a116504f80d1b7ba357c36f16b420f Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 7 Sep 2020 18:37:12 +0200 Subject: [PATCH] Fix exception --- .../plus/server/endpoints/TileEndpoint.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/server/endpoints/TileEndpoint.java b/OsmAnd/src/net/osmand/plus/server/endpoints/TileEndpoint.java index 31d940be08..2774bb6eab 100644 --- a/OsmAnd/src/net/osmand/plus/server/endpoints/TileEndpoint.java +++ b/OsmAnd/src/net/osmand/plus/server/endpoints/TileEndpoint.java @@ -17,6 +17,8 @@ import org.apache.commons.logging.Log; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.net.URL; +import java.util.ArrayList; +import java.util.List; import java.util.Scanner; import static fi.iki.elonen.NanoHTTPD.newFixedLengthResponse; @@ -28,6 +30,15 @@ public class TileEndpoint implements OsmAndHttpServer.ApiEndpoint { private static final Log LOG = PlatformUtil.getLog(TileEndpoint.class); private final MapActivity mapActivity; + private final List cache = new ArrayList<>(); + + private static class MetaTileCache { + Bitmap bmp; + int x; + int y; + int zoom; + + } public TileEndpoint(MapActivity mapActivity) { this.mapActivity = mapActivity; @@ -37,11 +48,14 @@ public class TileEndpoint implements OsmAndHttpServer.ApiEndpoint { public NanoHTTPD.Response process(NanoHTTPD.IHTTPSession session, String url) { // https://tile.osmand.net/hd/6/55/25.png int extInd = url.indexOf('.'); - if(extInd >= 0) { + if (extInd >= 0) { url = url.substring(0, extInd); } + if(url.charAt(0) == '/') { + url = url.substring(1); + } String[] prms = url.split("/"); - if(prms.length < 4) { + if (prms.length < 4) { return OsmAndHttpServer.ErrorResponses.response500; } int zoom = Integer.parseInt(prms[1]); @@ -63,15 +77,17 @@ public class TileEndpoint implements OsmAndHttpServer.ApiEndpoint { private synchronized Bitmap requestTile(int x, int y, int zoom) { double lat = MapUtils.getLatitudeFromTile(zoom, y); double lon = MapUtils.getLongitudeFromTile(zoom, x); + final RotatedTileBox cp = mapActivity.getMapView().getCurrentRotatedTileBox(); final RotatedTileBox rotatedTileBox = new RotatedTileBox.RotatedTileBoxBuilder() .setLocation(lat, lon) + .setMapDensity(cp.getMapDensity()).density(cp.getDensity()) .setZoom(zoom) .setPixelDimensions(TILE_SIZE_PX, TILE_SIZE_PX, 0.5f, 0.5f).build(); mapActivity.getMapView().setCurrentViewport(rotatedTileBox); int timeout = 0; try { AsyncLoadingThread athread = mapActivity.getMyApplication().getResourceManager().getAsyncLoadingThread(); - + Thread.sleep(TIMEOUT_STEP); // line not correct Bitmap res = null; while (athread.areResourcesLoading() && timeout < TIMEOUT) { Thread.sleep(TIMEOUT_STEP);