tiles added

This commit is contained in:
simon 2020-09-08 15:32:39 +03:00
parent 2442759d07
commit ad444aadaf
3 changed files with 32 additions and 30 deletions

View file

@ -23,10 +23,10 @@ public class OsmAndHttpServer extends NanoHTTPD {
super(hostname, port); super(hostname, port);
} }
public void start(MapActivity mapActivity) throws IOException { @Override
this.mapActivity = mapActivity; public void stop() {
registerEndpoints(); mapActivity.getMapView().setServerRendering(false);
start(NanoHTTPD.SOCKET_READ_TIMEOUT, false); super.stop();
} }
@Override @Override
@ -41,6 +41,13 @@ public class OsmAndHttpServer extends NanoHTTPD {
return getStatic(uri); return getStatic(uri);
} }
public void start(MapActivity mapActivity) throws IOException {
this.mapActivity = mapActivity;
registerEndpoints();
start(NanoHTTPD.SOCKET_READ_TIMEOUT, false);
mapActivity.getMapView().setServerRendering(true);
}
public String getUrl() { public String getUrl() {
return "http://" + getHostname() + ":" + getListeningPort(); return "http://" + getHostname() + ":" + getListeningPort();
} }

View file

@ -1,23 +1,17 @@
package net.osmand.plus.server.endpoints; package net.osmand.plus.server.endpoints;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import fi.iki.elonen.NanoHTTPD; import fi.iki.elonen.NanoHTTPD;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.resources.AsyncLoadingThread; import net.osmand.plus.resources.AsyncLoadingThread;
import net.osmand.plus.server.OsmAndHttpServer; import net.osmand.plus.server.OsmAndHttpServer;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import static fi.iki.elonen.NanoHTTPD.newFixedLengthResponse; import static fi.iki.elonen.NanoHTTPD.newFixedLengthResponse;
@ -27,7 +21,7 @@ public class TileEndpoint implements OsmAndHttpServer.ApiEndpoint {
private static final int TILE_DENSITY = 2; private static final int TILE_DENSITY = 2;
private static final int TIMEOUT_STEP = 500; private static final int TIMEOUT_STEP = 500;
private static final int TIMEOUT = 5000; private static final int TIMEOUT = 5000;
private static final int METATILE_SIZE = 2; private static final int METATILE_SIZE = 1;
private static final int MAX_CACHE_SIZE = 4; private static final int MAX_CACHE_SIZE = 4;
private static final Log LOG = PlatformUtil.getLog(TileEndpoint.class); private static final Log LOG = PlatformUtil.getLog(TileEndpoint.class);
@ -72,7 +66,7 @@ public class TileEndpoint implements OsmAndHttpServer.ApiEndpoint {
if (extInd >= 0) { if (extInd >= 0) {
url = url.substring(0, extInd); url = url.substring(0, extInd);
} }
if(url.charAt(0) == '/') { if (url.charAt(0) == '/') {
url = url.substring(1); url = url.substring(1);
} }
String[] prms = url.split("/"); String[] prms = url.split("/");
@ -82,20 +76,18 @@ public class TileEndpoint implements OsmAndHttpServer.ApiEndpoint {
int zoom = Integer.parseInt(prms[1]); int zoom = Integer.parseInt(prms[1]);
int x = Integer.parseInt(prms[2]); int x = Integer.parseInt(prms[2]);
int y = Integer.parseInt(prms[3]); int y = Integer.parseInt(prms[3]);
MetaTileCache res = null; //incorrect condition
for (MetaTileCache r : cache) { // for (MetaTileCache r : cache) {
if (r.zoom == zoom && r.ex >= x && r.ey >= y && r.sx <= x && r.sy <= y) { // if (r.zoom == zoom && r.ex >= x && r.ey >= y && r.sx <= x && r.sy <= y) {
res = r; // res = r;
} // }
} // }
if(res == null) { MetaTileCache res = requestMetatile(x, y, zoom);
res = requestMetatile(x, y, zoom);
}
if (res == null) { if (res == null) {
return OsmAndHttpServer.ErrorResponses.response500; return OsmAndHttpServer.ErrorResponses.response500;
} }
ByteArrayOutputStream stream = new ByteArrayOutputStream(); ByteArrayOutputStream stream = new ByteArrayOutputStream();
Bitmap bmp = res.getSubtile(x, y); Bitmap bmp = res.bmp;
if (bmp == null) { if (bmp == null) {
return OsmAndHttpServer.ErrorResponses.response500; return OsmAndHttpServer.ErrorResponses.response500;
} }
@ -119,8 +111,6 @@ public class TileEndpoint implements OsmAndHttpServer.ApiEndpoint {
.setZoom(zoom) .setZoom(zoom)
.setPixelDimensions(TILE_SIZE_PX * TILE_DENSITY * METATILE_SIZE, TILE_SIZE_PX * TILE_DENSITY * METATILE_SIZE, 0.5f, 0.5f).build(); .setPixelDimensions(TILE_SIZE_PX * TILE_DENSITY * METATILE_SIZE, TILE_SIZE_PX * TILE_DENSITY * METATILE_SIZE, 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();
@ -138,10 +128,8 @@ public class TileEndpoint implements OsmAndHttpServer.ApiEndpoint {
res.ey = my + METATILE_SIZE - 1; res.ey = my + METATILE_SIZE - 1;
res.zoom = zoom; res.zoom = zoom;
RotatedTileBox tilebox = mapActivity.getMapView().getBufferImgLoc(); RotatedTileBox tilebox = mapActivity.getMapView().getBufferImgLoc();
// TODO here we need to properly cut image according to tilebox
res.bmp = mapActivity.getMapView().getBufferBitmap(); res.bmp = mapActivity.getMapView().getBufferBitmap();
LOG.debug(mapActivity.getMapView().getBufferImgLoc()); LOG.debug(mapActivity.getMapView().getBufferImgLoc());
addToMemoryCache(res); addToMemoryCache(res);
} }
return res; return res;
@ -150,6 +138,4 @@ public class TileEndpoint implements OsmAndHttpServer.ApiEndpoint {
} }
return null; return null;
} }
} }

View file

@ -77,6 +77,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
protected OsmandSettings settings = null; protected OsmandSettings settings = null;
private CanvasColors canvasColors = null; private CanvasColors canvasColors = null;
private Boolean nightMode = null; private Boolean nightMode = null;
private boolean isServerRendering = false;
private class CanvasColors { private class CanvasColors {
int colorDay = MAP_DEFAULT_COLOR; int colorDay = MAP_DEFAULT_COLOR;
@ -283,6 +284,14 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
return layers.contains(layer); return layers.contains(layer);
} }
public boolean isServerRendering() {
return isServerRendering;
}
public void setServerRendering(boolean serverRendering) {
isServerRendering = serverRendering;
}
public float getZorder(OsmandMapLayer layer) { public float getZorder(OsmandMapLayer layer) {
Float z = zOrders.get(layer); Float z = zOrders.get(layer);
if (z == null) { if (z == null) {
@ -643,9 +652,9 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
} }
final int cy = (int) (ratioy * view.getHeight()); final int cy = (int) (ratioy * view.getHeight());
final int cx = (int) (ratiox * view.getWidth()); final int cx = (int) (ratiox * view.getWidth());
if (currentViewport.getPixWidth() != view.getWidth() || currentViewport.getPixHeight() != view.getHeight() || if ((currentViewport.getPixWidth() != view.getWidth() || currentViewport.getPixHeight() != view.getHeight() ||
currentViewport.getCenterPixelY() != cy || currentViewport.getCenterPixelY() != cy ||
currentViewport.getCenterPixelX() != cx) { currentViewport.getCenterPixelX() != cx) && !isServerRendering) {
currentViewport.setPixelDimensions(view.getWidth(), view.getHeight(), ratiox, ratioy); currentViewport.setPixelDimensions(view.getWidth(), view.getHeight(), ratiox, ratioy);
refreshBufferImage(drawSettings); refreshBufferImage(drawSettings);
} }