Fix exception

This commit is contained in:
Victor Shcherb 2020-09-07 18:37:12 +02:00
parent 2b9db97fb7
commit a92bac55f7

View file

@ -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<MetaTileCache> 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);