diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index cdc08da50e..d4efabb4af 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -135,6 +135,7 @@ import net.osmand.plus.routing.TransportRoutingHelper.TransportRouteCalculationP import net.osmand.plus.search.QuickSearchDialogFragment; import net.osmand.plus.search.QuickSearchDialogFragment.QuickSearchTab; import net.osmand.plus.search.QuickSearchDialogFragment.QuickSearchType; +import net.osmand.plus.server.ApiRouter; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.OsmAndAppCustomization.OsmAndAppCustomizationListener; import net.osmand.plus.settings.backend.OsmandSettings; @@ -308,6 +309,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven int h = dm.heightPixels - statusBarHeight; mapView = new OsmandMapTileView(this, w, h); + ApiRouter.mapActivity = this; if (app.getAppInitializer().checkAppVersionChanged() && WhatsNewDialogFragment.SHOW) { SecondSplashScreenFragment.SHOW = false; WhatsNewDialogFragment.SHOW = false; diff --git a/OsmAnd/src/net/osmand/plus/server/ApiRouter.java b/OsmAnd/src/net/osmand/plus/server/ApiRouter.java index 6dfbe7796e..40fba76882 100644 --- a/OsmAnd/src/net/osmand/plus/server/ApiRouter.java +++ b/OsmAnd/src/net/osmand/plus/server/ApiRouter.java @@ -1,5 +1,7 @@ package net.osmand.plus.server; +import android.graphics.Bitmap; +import android.graphics.Canvas; import android.util.Log; import android.webkit.MimeTypeMap; @@ -8,24 +10,19 @@ import com.google.gson.Gson; import net.osmand.data.FavouritePoint; import net.osmand.plus.OsmandApplication; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; +import java.io.*; import java.nio.charset.Charset; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.concurrent.Callable; import fi.iki.elonen.NanoHTTPD; +import net.osmand.plus.activities.MapActivity; import static fi.iki.elonen.NanoHTTPD.newFixedLengthResponse; public class ApiRouter { private OsmandApplication androidContext; - public OsmandApplication getAndroidContext() { return androidContext; } @@ -33,12 +30,13 @@ public class ApiRouter { private final String FOLDER_NAME = "server"; private Gson gson = new Gson(); private Map endpoints = new HashMap<>(); + public static MapActivity mapActivity; public ApiRouter(){ - initFavorites(); + initRoutes(); } - private void initFavorites() { + private void initRoutes() { ApiEndpoint favorites = new ApiEndpoint(); favorites.uri = "/favorites"; favorites.apiCall = new ApiEndpoint.ApiCall(){ @@ -48,6 +46,26 @@ public class ApiRouter { } }; endpoints.put(favorites.uri,favorites); + + ApiEndpoint tile = new ApiEndpoint(); + tile.uri = "/tile"; + tile.apiCall = new ApiEndpoint.ApiCall(){ + @Override + public NanoHTTPD.Response call(NanoHTTPD.IHTTPSession session) { + Bitmap bitmap = mapActivity.getMapView().currentCanvas; + //androidContext.getApplicationContext().get + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); + byte[] byteArray = stream.toByteArray(); + ByteArrayInputStream str = new ByteArrayInputStream(byteArray); + return newFixedLengthResponse( + NanoHTTPD.Response.Status.OK, + "image/png", + str, + str.available()); + } + }; + endpoints.put(tile.uri,tile); } public void setAndroidContext(OsmandApplication androidContext) { diff --git a/OsmAnd/src/net/osmand/plus/server/ServerSessionHandler.java b/OsmAnd/src/net/osmand/plus/server/ServerSessionHandler.java index 764960f392..13d54fcab8 100644 --- a/OsmAnd/src/net/osmand/plus/server/ServerSessionHandler.java +++ b/OsmAnd/src/net/osmand/plus/server/ServerSessionHandler.java @@ -3,6 +3,7 @@ package net.osmand.plus.server; import net.osmand.plus.OsmandApplication; import fi.iki.elonen.NanoHTTPD; +import net.osmand.plus.activities.MapActivity; public class ServerSessionHandler { private OsmandApplication androidApplication; @@ -18,6 +19,11 @@ public class ServerSessionHandler { router.setAndroidContext(androidApplication); } + public void setMapActivity(MapActivity activity) { + //todo + router.mapActivity = activity; + } + public NanoHTTPD.Response handle(NanoHTTPD.IHTTPSession session) { return router.route(session); } diff --git a/OsmAnd/src/net/osmand/plus/server/map/LayersDraw.java b/OsmAnd/src/net/osmand/plus/server/map/LayersDraw.java new file mode 100644 index 0000000000..a54b40f44d --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/server/map/LayersDraw.java @@ -0,0 +1,99 @@ +package net.osmand.plus.server.map; + +import net.osmand.StateChangedListener; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandPlugin; +import net.osmand.plus.measurementtool.MeasurementToolLayer; +import net.osmand.plus.render.MapVectorLayer; +import net.osmand.plus.routing.RoutingHelper; +import net.osmand.plus.views.MapTileLayer; +import net.osmand.plus.views.OsmandMapTileView; +import net.osmand.plus.views.layers.*; + +public class LayersDraw { + public static void createLayers(OsmandApplication app, final OsmandMapTileView mapView) { + RoutingHelper routingHelper = app.getRoutingHelper(); + // first create to make accessible + MapTextLayer mapTextLayer = new MapTextLayer(); + // 5.95 all labels + mapView.addLayer(mapTextLayer, 5.95f); + // 8. context menu layer + //ContextMenuLayer contextMenuLayer = new ContextMenuLayer(activity); + //mapView.addLayer(contextMenuLayer, 8); + // mapView.addLayer(underlayLayer, -0.5f); + MapTileLayer mapTileLayer = new MapTileLayer(true); + mapView.addLayer(mapTileLayer, 0.0f); + mapView.setMainLayer(mapTileLayer); + + // 0.5 layer + MapVectorLayer mapVectorLayer = new MapVectorLayer(mapTileLayer, false); + mapView.addLayer(mapVectorLayer, 0.5f); + + //DownloadedRegionsLayer downloadedRegionsLayer = new DownloadedRegionsLayer(activity); + //mapView.addLayer(downloadedRegionsLayer, 0.5f); + + // 0.9 gpx layer + GPXLayer gpxLayer = new GPXLayer(); + mapView.addLayer(gpxLayer, 0.9f); + + // 1. route layer + RouteLayer routeLayer = new RouteLayer(routingHelper); + mapView.addLayer(routeLayer, 1); + + // 2. osm bugs layer + // 3. poi layer + //POIMapLayer poiMapLayer = new POIMapLayer(activity); + //mapView.addLayer(poiMapLayer, 3); + // 4. favorites layer + FavouritesLayer mFavouritesLayer = new FavouritesLayer(); + mapView.addLayer(mFavouritesLayer, 4); + // 4.6 measurement tool layer + MeasurementToolLayer measurementToolLayer = new MeasurementToolLayer(); + mapView.addLayer(measurementToolLayer, 4.6f); + // 5. transport layer + //TransportStopsLayer transportStopsLayer = new TransportStopsLayer(activity); + //mapView.addLayer(transportStopsLayer, 5); + // 5.95 all text labels + // 6. point location layer + //PointLocationLayer locationLayer = new PointLocationLayer(activity.getMapViewTrackingUtilities()); + //mapView.addLayer(locationLayer, 6); + // 7. point navigation layer + //PointNavigationLayer navigationLayer = new PointNavigationLayer(activity); + //mapView.addLayer(navigationLayer, 7); + // 7.3 map markers layer + //MapMarkersLayer mapMarkersLayer = new MapMarkersLayer(activity); + //mapView.addLayer(mapMarkersLayer, 7.3f); + // 7.5 Impassible roads + //ImpassableRoadsLayer impassableRoadsLayer = new ImpassableRoadsLayer(activity); + //mapView.addLayer(impassableRoadsLayer, 7.5f); + // 7.8 ruler control layer + //RulerControlLayer rulerControlLayer = new RulerControlLayer(activity); + //mapView.addLayer(rulerControlLayer, 7.8f); + // 8. context menu layer + // 9. map info layer + //MapInfoLayer mapInfoLayer = new MapInfoLayer(activity, routeLayer); + //mapView.addLayer(mapInfoLayer, 9); + // 11. route info layer + //MapControlsLayer mapControlsLayer = new MapControlsLayer(activity); + //mapView.addLayer(mapControlsLayer, 11); + // 12. quick actions layer + //MapQuickActionLayer mapQuickActionLayer = new MapQuickActionLayer(activity, contextMenuLayer); + //mapView.addLayer(mapQuickActionLayer, 12); + //contextMenuLayer.setMapQuickActionLayer(mapQuickActionLayer); + //mapControlsLayer.setMapQuickActionLayer(mapQuickActionLayer); + +// StateChangedListener transparencyListener = new StateChangedListener() { +// @Override +// public void stateChanged(Integer change) { +// mapTileLayer.setAlpha(change); +// mapVectorLayer.setAlpha(change); +// mapView.refreshMap(); +// } +// }; + // app.getSettings().MAP_TRANSPARENCY.addListener(transparencyListener); + + //return OsmandPlugin.createLayers(mapView, app); + //app.getAppCustomization().createLayers(mapView, activity); + //app.getAidlApi().registerMapLayers(activity); + } +} diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index 260f30fa50..c0bc2251d6 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; + public Bitmap currentCanvas = null; private class CanvasColors { int colorDay = MAP_DEFAULT_COLOR; @@ -574,6 +575,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback { if (!bufferBitmap.isRecycled()) { RectF rct = new RectF(x1, y1, x2, y2); canvas.drawBitmap(bufferBitmap, null, rct, paintImg); + currentCanvas = bufferBitmap; } canvas.rotate(-rot, currentViewport.getCenterPixelX(), currentViewport.getCenterPixelY()); }