diff --git a/OsmAnd/src/net/osmand/plus/server/OsmAndHttpServer.java b/OsmAnd/src/net/osmand/plus/server/OsmAndHttpServer.java index 15db8a651b..6bc3ea272e 100644 --- a/OsmAnd/src/net/osmand/plus/server/OsmAndHttpServer.java +++ b/OsmAnd/src/net/osmand/plus/server/OsmAndHttpServer.java @@ -23,10 +23,10 @@ public class OsmAndHttpServer extends NanoHTTPD { super(hostname, port); } - public void start(MapActivity mapActivity) throws IOException { - this.mapActivity = mapActivity; - registerEndpoints(); - start(NanoHTTPD.SOCKET_READ_TIMEOUT, false); + @Override + public void stop() { + mapActivity.getMapView().setServerRendering(false); + super.stop(); } @Override @@ -41,6 +41,13 @@ public class OsmAndHttpServer extends NanoHTTPD { 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() { return "http://" + getHostname() + ":" + getListeningPort(); } diff --git a/OsmAnd/src/net/osmand/plus/server/endpoints/TileEndpoint.java b/OsmAnd/src/net/osmand/plus/server/endpoints/TileEndpoint.java index 3811a098fe..949f503f7f 100644 --- a/OsmAnd/src/net/osmand/plus/server/endpoints/TileEndpoint.java +++ b/OsmAnd/src/net/osmand/plus/server/endpoints/TileEndpoint.java @@ -1,23 +1,17 @@ package net.osmand.plus.server.endpoints; 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.server.OsmAndHttpServer; import net.osmand.util.MapUtils; - import org.apache.commons.logging.Log; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; import java.util.concurrent.ConcurrentLinkedQueue; 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 TIMEOUT_STEP = 500; 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 Log LOG = PlatformUtil.getLog(TileEndpoint.class); @@ -72,7 +66,7 @@ public class TileEndpoint implements OsmAndHttpServer.ApiEndpoint { if (extInd >= 0) { url = url.substring(0, extInd); } - if(url.charAt(0) == '/') { + if (url.charAt(0) == '/') { url = url.substring(1); } String[] prms = url.split("/"); @@ -82,20 +76,18 @@ public class TileEndpoint implements OsmAndHttpServer.ApiEndpoint { int zoom = Integer.parseInt(prms[1]); int x = Integer.parseInt(prms[2]); int y = Integer.parseInt(prms[3]); - MetaTileCache res = null; - for (MetaTileCache r : cache) { - if (r.zoom == zoom && r.ex >= x && r.ey >= y && r.sx <= x && r.sy <= y) { - res = r; - } - } - if(res == null) { - res = requestMetatile(x, y, zoom); - } + //incorrect condition +// for (MetaTileCache r : cache) { +// if (r.zoom == zoom && r.ex >= x && r.ey >= y && r.sx <= x && r.sy <= y) { +// res = r; +// } +// } + MetaTileCache res = requestMetatile(x, y, zoom); if (res == null) { return OsmAndHttpServer.ErrorResponses.response500; } ByteArrayOutputStream stream = new ByteArrayOutputStream(); - Bitmap bmp = res.getSubtile(x, y); + Bitmap bmp = res.bmp; if (bmp == null) { return OsmAndHttpServer.ErrorResponses.response500; } @@ -119,8 +111,6 @@ public class TileEndpoint implements OsmAndHttpServer.ApiEndpoint { .setZoom(zoom) .setPixelDimensions(TILE_SIZE_PX * TILE_DENSITY * METATILE_SIZE, TILE_SIZE_PX * TILE_DENSITY * METATILE_SIZE, 0.5f, 0.5f).build(); mapActivity.getMapView().setCurrentViewport(rotatedTileBox); - - int timeout = 0; try { AsyncLoadingThread athread = mapActivity.getMyApplication().getResourceManager().getAsyncLoadingThread(); @@ -138,10 +128,8 @@ public class TileEndpoint implements OsmAndHttpServer.ApiEndpoint { res.ey = my + METATILE_SIZE - 1; res.zoom = zoom; RotatedTileBox tilebox = mapActivity.getMapView().getBufferImgLoc(); - // TODO here we need to properly cut image according to tilebox res.bmp = mapActivity.getMapView().getBufferBitmap(); LOG.debug(mapActivity.getMapView().getBufferImgLoc()); - addToMemoryCache(res); } return res; @@ -150,6 +138,4 @@ public class TileEndpoint implements OsmAndHttpServer.ApiEndpoint { } return null; } - - } diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index 35e652094b..68b069e556 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -77,6 +77,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback { protected OsmandSettings settings = null; private CanvasColors canvasColors = null; private Boolean nightMode = null; + private boolean isServerRendering = false; private class CanvasColors { int colorDay = MAP_DEFAULT_COLOR; @@ -283,6 +284,14 @@ public class OsmandMapTileView implements IMapDownloaderCallback { return layers.contains(layer); } + public boolean isServerRendering() { + return isServerRendering; + } + + public void setServerRendering(boolean serverRendering) { + isServerRendering = serverRendering; + } + public float getZorder(OsmandMapLayer layer) { Float z = zOrders.get(layer); if (z == null) { @@ -643,9 +652,9 @@ public class OsmandMapTileView implements IMapDownloaderCallback { } final int cy = (int) (ratioy * view.getHeight()); 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.getCenterPixelX() != cx) { + currentViewport.getCenterPixelX() != cx) && !isServerRendering) { currentViewport.setPixelDimensions(view.getWidth(), view.getHeight(), ratiox, ratioy); refreshBufferImage(drawSettings); }