Merge branch 'android_http_server' of https://github.com/osmandapp/Osmand into android_http_server

This commit is contained in:
simon 2020-09-07 19:38:50 +03:00
commit f34b1fdf11

View file

@ -17,6 +17,8 @@ import org.apache.commons.logging.Log;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.net.URL; import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner; import java.util.Scanner;
import static fi.iki.elonen.NanoHTTPD.newFixedLengthResponse; 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 static final Log LOG = PlatformUtil.getLog(TileEndpoint.class);
private final MapActivity mapActivity; 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) { public TileEndpoint(MapActivity mapActivity) {
this.mapActivity = mapActivity; this.mapActivity = mapActivity;
@ -37,11 +48,14 @@ public class TileEndpoint implements OsmAndHttpServer.ApiEndpoint {
public NanoHTTPD.Response process(NanoHTTPD.IHTTPSession session, String url) { public NanoHTTPD.Response process(NanoHTTPD.IHTTPSession session, String url) {
// https://tile.osmand.net/hd/6/55/25.png // https://tile.osmand.net/hd/6/55/25.png
int extInd = url.indexOf('.'); int extInd = url.indexOf('.');
if(extInd >= 0) { if (extInd >= 0) {
url = url.substring(0, extInd); url = url.substring(0, extInd);
} }
if(url.charAt(0) == '/') {
url = url.substring(1);
}
String[] prms = url.split("/"); String[] prms = url.split("/");
if(prms.length < 4) { if (prms.length < 4) {
return OsmAndHttpServer.ErrorResponses.response500; return OsmAndHttpServer.ErrorResponses.response500;
} }
int zoom = Integer.parseInt(prms[1]); 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) { private synchronized Bitmap requestTile(int x, int y, int zoom) {
double lat = MapUtils.getLatitudeFromTile(zoom, y); double lat = MapUtils.getLatitudeFromTile(zoom, y);
double lon = MapUtils.getLongitudeFromTile(zoom, x); double lon = MapUtils.getLongitudeFromTile(zoom, x);
final RotatedTileBox cp = mapActivity.getMapView().getCurrentRotatedTileBox();
final RotatedTileBox rotatedTileBox = new RotatedTileBox.RotatedTileBoxBuilder() final RotatedTileBox rotatedTileBox = new RotatedTileBox.RotatedTileBoxBuilder()
.setLocation(lat, lon) .setLocation(lat, lon)
.setMapDensity(cp.getMapDensity()).density(cp.getDensity())
.setZoom(zoom) .setZoom(zoom)
.setPixelDimensions(TILE_SIZE_PX, TILE_SIZE_PX, 0.5f, 0.5f).build(); .setPixelDimensions(TILE_SIZE_PX, TILE_SIZE_PX, 0.5f, 0.5f).build();
mapActivity.getMapView().setCurrentViewport(rotatedTileBox); mapActivity.getMapView().setCurrentViewport(rotatedTileBox);
int timeout = 0; int timeout = 0;
try { try {
AsyncLoadingThread athread = mapActivity.getMyApplication().getResourceManager().getAsyncLoadingThread(); AsyncLoadingThread athread = mapActivity.getMyApplication().getResourceManager().getAsyncLoadingThread();
Thread.sleep(TIMEOUT_STEP); // line not correct
Bitmap res = null; Bitmap res = null;
while (athread.areResourcesLoading() && timeout < TIMEOUT) { while (athread.areResourcesLoading() && timeout < TIMEOUT) {
Thread.sleep(TIMEOUT_STEP); Thread.sleep(TIMEOUT_STEP);