api router mapactivity changes
This commit is contained in:
parent
e6a345e0e9
commit
6a95630076
2 changed files with 25 additions and 47 deletions
|
@ -19,6 +19,7 @@ import net.osmand.plus.server.map.LayersDraw;
|
||||||
import net.osmand.plus.server.map.MapTileMiniLayer;
|
import net.osmand.plus.server.map.MapTileMiniLayer;
|
||||||
import net.osmand.plus.server.map.OsmandMapMiniLayer;
|
import net.osmand.plus.server.map.OsmandMapMiniLayer;
|
||||||
import net.osmand.plus.server.map.OsmandMapTileMiniView;
|
import net.osmand.plus.server.map.OsmandMapTileMiniView;
|
||||||
|
import net.osmand.plus.views.OsmandMapLayer;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
@ -38,6 +39,7 @@ public class ApiRouter {
|
||||||
private final String FOLDER_NAME = "server";
|
private final String FOLDER_NAME = "server";
|
||||||
private Gson gson = new Gson();
|
private Gson gson = new Gson();
|
||||||
private Map<String, ApiEndpoint> endpoints = new HashMap<>();
|
private Map<String, ApiEndpoint> endpoints = new HashMap<>();
|
||||||
|
//change to weakreference
|
||||||
public static MapActivity mapActivity;
|
public static MapActivity mapActivity;
|
||||||
|
|
||||||
public ApiRouter(){
|
public ApiRouter(){
|
||||||
|
@ -76,55 +78,31 @@ public class ApiRouter {
|
||||||
return ErrorResponses.response500;
|
return ErrorResponses.response500;
|
||||||
}
|
}
|
||||||
Log.d("TILE","HAVING VALUES" + zoom + " " + lat + " " + lon);
|
Log.d("TILE","HAVING VALUES" + zoom + " " + lat + " " + lon);
|
||||||
ITileSource map = TileSourceManager.getMapillaryVectorSource();
|
RotatedTileBox rotatedTileBox = mapActivity.getMapView().getCurrentRotatedTileBox().copy();
|
||||||
Bitmap bitmap = Bitmap.createBitmap(512,512,Bitmap.Config.ARGB_8888);//mapActivity.getMapView().currentCanvas;
|
rotatedTileBox.setZoom(zoom);
|
||||||
//OsmandMapTileView tileView = new OsmandMapTileView(mapActivity,300,300);
|
rotatedTileBox.setLatLonCenter(lat,lon);
|
||||||
OsmandMapTileMiniView tileView = new OsmandMapTileMiniView(androidContext,512,512);
|
rotatedTileBox.setPixelDimensions(512,512);
|
||||||
|
mapActivity.getMapView().setIntZoom(zoom);
|
||||||
|
mapActivity.getMapView().setLatLon(lat,lon);
|
||||||
|
OsmandMapLayer.DrawSettings param =
|
||||||
|
new OsmandMapLayer.DrawSettings(androidContext.getDaynightHelper().isNightMode(),
|
||||||
|
false);
|
||||||
|
mapActivity.getMapView().refreshMap();
|
||||||
|
mapActivity.getMapView().refreshMapInternal(param);
|
||||||
|
mapActivity.getMapView().refreshBaseMapInternal(rotatedTileBox, param);
|
||||||
|
Bitmap bitmap = mapActivity.getMapView().currentCanvas;
|
||||||
Canvas canvas = new Canvas(bitmap);
|
Canvas canvas = new Canvas(bitmap);
|
||||||
RotatedTileBox tileBox = tileView.getCurrentRotatedTileBox();
|
OsmandMapLayer.DrawSettings drawSettings = new OsmandMapLayer.DrawSettings(
|
||||||
tileBox.setLatLonCenter(lat,lon);
|
androidContext.getDaynightHelper().isNightMode(),
|
||||||
tileBox.setZoom(zoom);
|
true);
|
||||||
LayersDraw.createLayers(androidContext,canvas, tileView);
|
// mapActivity.getMapView().drawOverMap(canvas,
|
||||||
Paint p = new Paint();
|
// rotatedTileBox,
|
||||||
p.setStyle(Paint.Style.FILL_AND_STROKE);
|
// drawSettings);
|
||||||
p.setColor(Color.BLACK);
|
//Bitmap bitmap = Bitmap.createBitmap(512,512,Bitmap.Config.ARGB_8888);
|
||||||
//canvas.drawBitmap(bitmap ,0, 0, null);
|
|
||||||
boolean nightMode = androidContext.getDaynightHelper().isNightMode();
|
|
||||||
OsmandMapMiniLayer.DrawSettings drawSettings = new OsmandMapMiniLayer.DrawSettings(nightMode, false);
|
|
||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
//bitmap = tileView.currentCanvas;
|
|
||||||
final QuadRect tilesRect = tileView.getCurrentRotatedTileBox().getTileBounds();
|
|
||||||
int left = (int) Math.floor(tilesRect.left);
|
|
||||||
int top = (int) Math.floor(tilesRect.top);
|
|
||||||
int width = (int) Math.ceil(tilesRect.right - left);
|
|
||||||
int height = (int) Math.ceil(tilesRect.bottom - top);
|
|
||||||
int dzoom = 1;
|
|
||||||
int div = (int) Math.pow(2.0, dzoom);
|
|
||||||
tileView.drawOverMap(canvas,tileView.getCurrentRotatedTileBox(),drawSettings);
|
|
||||||
|
|
||||||
ResourceManager mgr = androidContext.getResourceManager();
|
|
||||||
int tileX = (left ) / div;
|
|
||||||
int tileY = (top) / div;
|
|
||||||
String tileId = mgr.calculateTileId(map, tileX, tileY, 14);
|
|
||||||
//androidContext.getResourceManager().
|
|
||||||
// getMapTileDownloader().
|
|
||||||
//String imgTileId = mgr.calculateTileId(map, tileX / div, tileY / div, nzoom - kzoom);
|
|
||||||
Map<String, Pair<QuadPointDouble, GeometryTile>> tiles = new HashMap<>();
|
|
||||||
//bitmap = null;
|
|
||||||
boolean first = true;
|
|
||||||
//while (bitmap == null){
|
|
||||||
// bitmap = androidContext.getResourceManager().getBitmapTilesCache().getTileForMapAsync(
|
|
||||||
// tileId,map,tileX,tileY,14,first
|
|
||||||
// );
|
|
||||||
// first = false;
|
|
||||||
//}
|
|
||||||
canvas.drawLine(0,0,canvas.getWidth(),canvas.getHeight(), p);
|
|
||||||
//bitmap = tileView.currentCanvas;
|
|
||||||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
|
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
|
||||||
|
|
||||||
byte[] byteArray = stream.toByteArray();
|
byte[] byteArray = stream.toByteArray();
|
||||||
ByteArrayInputStream str = new ByteArrayInputStream(byteArray);
|
ByteArrayInputStream str = new ByteArrayInputStream(byteArray);
|
||||||
|
|
||||||
return newFixedLengthResponse(
|
return newFixedLengthResponse(
|
||||||
NanoHTTPD.Response.Status.OK,
|
NanoHTTPD.Response.Status.OK,
|
||||||
"image/png",
|
"image/png",
|
||||||
|
|
|
@ -581,7 +581,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshBaseMapInternal(RotatedTileBox tileBox, DrawSettings drawSettings) {
|
public void refreshBaseMapInternal(RotatedTileBox tileBox, DrawSettings drawSettings) {
|
||||||
if (tileBox.getPixHeight() == 0 || tileBox.getPixWidth() == 0) {
|
if (tileBox.getPixHeight() == 0 || tileBox.getPixWidth() == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -618,7 +618,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
|
||||||
additional.calculateFPS(start, end);
|
additional.calculateFPS(start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshMapInternal(DrawSettings drawSettings) {
|
public void refreshMapInternal(DrawSettings drawSettings) {
|
||||||
if (view == null) {
|
if (view == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -823,7 +823,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
|
||||||
|
|
||||||
// this method could be called in non UI thread
|
// this method could be called in non UI thread
|
||||||
public void refreshMap(final boolean updateVectorRendering) {
|
public void refreshMap(final boolean updateVectorRendering) {
|
||||||
if (view != null && view.isShown()) {
|
if (view != null) {
|
||||||
boolean nightMode = application.getDaynightHelper().isNightMode();
|
boolean nightMode = application.getDaynightHelper().isNightMode();
|
||||||
Boolean currentNightMode = this.nightMode;
|
Boolean currentNightMode = this.nightMode;
|
||||||
boolean forceUpdateVectorDrawing = currentNightMode != null && currentNightMode != nightMode;
|
boolean forceUpdateVectorDrawing = currentNightMode != null && currentNightMode != nightMode;
|
||||||
|
|
Loading…
Reference in a new issue