Implement buffer image to increase FPS

This commit is contained in:
vshcherb 2013-10-16 17:39:58 +02:00
parent 0e8a0507f6
commit ec83f9f72c
22 changed files with 417 additions and 240 deletions

View file

@ -55,8 +55,8 @@ public class RotatedTileBox {
rotateCos = r.rotateCos;
rotateSin = r.rotateSin;
oxTile = r.oxTile;
oyTile =r.oyTile;
if (r.tileBounds != null) {
oyTile = r.oyTile;
if (r.tileBounds != null && r.latLonBounds != null) {
tileBounds = new QuadRect(r.tileBounds);
latLonBounds = new QuadRect(r.latLonBounds);
tileLT = new QuadPoint(r.tileLT);
@ -404,9 +404,6 @@ public class RotatedTileBox {
// thread safe
box = box.copy();
box.checkTileRectangleCalculated();
if(box.zoom != zoom){
throw new UnsupportedOperationException();
}
if(!containsTilePoint(box.tileLB)){
return false;
}

View file

@ -138,12 +138,12 @@ public class RenderingRuleProperty {
if(colon != -1) {
int c = 0;
if(colon > 0) {
c += Integer.parseInt(value.substring(0, colon));
c += (int) Float.parseFloat(value.substring(0, colon));
}
c += Integer.parseInt(value.substring(colon + 1));
c += (int) Float.parseFloat(value.substring(colon + 1));
return c;
}
return Integer.parseInt(value);
return (int) Float.parseFloat(value);
} catch (NumberFormatException e) {
log.error("Rendering parse " + value);
}
@ -165,7 +165,7 @@ public class RenderingRuleProperty {
try {
int colon = value.indexOf(':');
if(colon != -1) {
return Integer.parseInt(value.substring(colon + 1));
return (int) Float.parseFloat(value.substring(colon + 1));
}
return 0;
} catch (NumberFormatException e) {

View file

@ -11,7 +11,7 @@
-->
<string name="route_distance_close">Close</string>
<string name="route_distance_far">Far</string>
<string name="route_distance_farest">Farthest</string>
<string name="route_distance_farthest">Farthest</string>
<string name="route_distance_settings_descr">Configure map view distance (TODO naming)</string>
<string name="route_distance_settings">Map view distance (TODO naming)</string>
<string name="map_magnifier">Map magnifier</string>

View file

@ -664,7 +664,7 @@ public class OsmandSettings {
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<RouteViewDistance> ROUTE_VIEW_DISTANCE =
new EnumIntPreference<RouteViewDistance>("route_view_distance", RouteViewDistance.FAREST,
new EnumIntPreference<RouteViewDistance>("route_view_distance", RouteViewDistance.FARTHEST,
RouteViewDistance.values()).makeProfile().cache();
public final CommonPreference<Boolean> SNAP_TO_ROAD = new BooleanPreference("snap_to_road", false).makeProfile().cache();
@ -1518,7 +1518,7 @@ public class OsmandSettings {
}
public enum RouteViewDistance {
FAREST(R.string.route_distance_farest, 1f),
FARTHEST(R.string.route_distance_farthest, 1f),
FAR(R.string.route_distance_far, 1.4f),
CLOSE(R.string.route_distance_close, 2f)
;

View file

@ -80,14 +80,18 @@ public class AudioNotesLayer extends OsmandMapLayer implements IContextMenuProvi
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings settings) {
if (tb.getZoom() >= startZoom) {
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
}
@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
if (tileBox.getZoom() >= startZoom) {
DataTileManager<Recording> recs = plugin.getRecordings();
final QuadRect tiles = tb.getTileBounds();
final QuadRect tiles = tileBox.getTileBounds();
List<Recording> objects = recs.getObjects(tiles. top, tiles.left, tiles.bottom, tiles.right);
for (Recording o : objects) {
int x = tb.getPixXFromLatLon(o.getLatitude(), o.getLongitude());
int y = tb.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
int x = tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude());
int y = tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
Bitmap b;
if (o.isPhoto()) {
b = photo;

View file

@ -61,7 +61,9 @@ public class OsmandDevelopmentPlugin extends OsmandPlugin {
if(!mv.isMeasureFPS()) {
mv.setMeasureFPS(true);
}
setText(Integer.toString((int) mv.getFPS()), "FPS");
setText("", Integer.toString((int) mv.getFPS()) + "/"
+ Integer.toString((int) mv.getSecondaryFPS())
+ " FPS");
return true;
}
};

View file

@ -16,14 +16,20 @@ import net.osmand.IndexConstants;
import net.osmand.access.AccessibleToast;
import net.osmand.data.LatLon;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.*;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.Route;
import net.osmand.plus.GPXUtilities.Track;
import net.osmand.plus.GPXUtilities.TrkSegment;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.ContextMenuLayer;
import net.osmand.plus.views.MapInfoLayer;
@ -34,7 +40,6 @@ import net.osmand.util.MapUtils;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.graphics.Bitmap;
@ -50,9 +55,7 @@ import android.graphics.PointF;
import android.os.AsyncTask;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
@ -467,8 +470,9 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
return false;
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
if (measurementPoints.size() > 0) {
path.reset();
int marginY = originIcon.getHeight();
@ -512,6 +516,10 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
}
}
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
}
@Override
public void destroyLayer() {

View file

@ -15,8 +15,11 @@ import net.osmand.access.AccessibleToast;
import net.osmand.data.LatLon;
import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.*;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.DialogProvider;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.osmedit.OsmPoint.Action;
@ -31,7 +34,6 @@ import org.xmlpull.v1.XmlPullParserException;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Canvas;
import android.graphics.Paint;
@ -41,10 +43,8 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.DisplayMetrics;
import android.util.Xml;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.Toast;
@ -144,20 +144,23 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings nightMode) {
if (tb.getZoom() >= startZoom) {
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
if (tileBox.getZoom() >= startZoom) {
// request to load
final QuadRect latLonBounds = tb.getLatLonBounds();
requestToLoad(latLonBounds.top, latLonBounds.left, latLonBounds.bottom, latLonBounds.right, tb.getZoom());
final QuadRect latLonBounds = tileBox.getLatLonBounds();
requestToLoad(latLonBounds.top, latLonBounds.left, latLonBounds.bottom, latLonBounds.right, tileBox.getZoom());
for (OpenStreetNote o : objects) {
int x = tb.getPixXFromLonNoRot(o.getLongitude());
int y = tb.getPixYFromLatNoRot(o.getLatitude());
canvas.drawCircle(x, y, getRadiusBug(tb), o.isLocal() ? pointNotSubmitedUI : (o.isOpened() ? pointOpenedUI
int x = tileBox.getPixXFromLonNoRot(o.getLongitude());
int y = tileBox.getPixYFromLatNoRot(o.getLatitude());
canvas.drawCircle(x, y, getRadiusBug(tileBox), o.isLocal() ? pointNotSubmitedUI : (o.isOpened() ? pointOpenedUI
: pointClosedUI));
}
}
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
}
public int getRadiusBug(RotatedTileBox tb) {
int z;

View file

@ -91,8 +91,10 @@ public class OsMoDroidLayer extends OsmandMapLayer implements ContextMenuLayer.I
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings nightMode) {
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
for (OsMoDroidPoint op : OsMoDroidPointArrayList) {
LatLon newLatlon;
@ -121,10 +123,10 @@ public class OsMoDroidLayer extends OsmandMapLayer implements ContextMenuLayer.I
prevlongitude = op.prevlatlon.getLongitude();
}
int locationX = tb.getPixXFromLatLon(latitude, longitude);
int locationY = tb.getPixYFromLatLon(latitude, longitude);
int prevlocationX = tb.getPixXFromLatLon(prevlatitude, prevlongitude);
int prevlocationY = tb.getPixYFromLatLon(prevlatitude, prevlongitude);
int locationX = tileBox.getPixXFromLatLon(latitude, longitude);
int locationY = tileBox.getPixYFromLatLon(latitude, longitude);
int prevlocationX = tileBox.getPixXFromLatLon(prevlatitude, prevlongitude);
int prevlocationY = tileBox.getPixYFromLatLon(prevlatitude, prevlongitude);
// int y = opIcon.getHeight()/2;
// int x = opIcon.getWidth()/2;
@ -141,7 +143,10 @@ public class OsMoDroidLayer extends OsmandMapLayer implements ContextMenuLayer.I
// op.prevlatlon=op.latlon;
}
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {}
public void getOsMoDroidPointFromPoint(RotatedTileBox tb,PointF point, List<? super OsMoDroidPoint> om) {
if (myOsMoDroidPlugin.getOsMoDroidPointArrayList(layerId) != null) {

View file

@ -6,7 +6,6 @@ import net.osmand.PlatformUtil;
import net.osmand.data.LatLon;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.NavigationService;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
@ -14,7 +13,6 @@ import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.MonitoringInfoControl;
import net.osmand.plus.views.MonitoringInfoControl.MonitoringInfoControlServices;
import net.osmand.plus.views.MonitoringInfoControl.ValueHolder;
import net.osmand.plus.views.OsmandMapTileView;
import org.apache.commons.logging.Log;
@ -22,7 +20,6 @@ import org.apache.commons.logging.Log;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;

View file

@ -171,7 +171,7 @@ public class ParkingPositionPlugin extends OsmandPlugin {
activity.getMapView().removeLayer(parkingLayer);
}
parkingLayer = new ParkingPositionLayer(activity, this);
activity.getMapView().addLayer(parkingLayer, 4.5f);
activity.getMapView().addLayer(parkingLayer, 5.5f);
registerWidget(activity);
}

View file

@ -70,6 +70,12 @@ public class MapVectorLayer extends BaseMapLayer {
@Override
public void onDraw(Canvas canvas, RotatedTileBox tilesRect, DrawSettings drawSettings) {
}
@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tilesRect,
DrawSettings drawSettings) {
if (!visible) {
return;
}

View file

@ -1,11 +1,33 @@
package net.osmand.plus.views;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import net.osmand.IndexConstants;
import net.osmand.binary.BinaryMapDataObject;
import net.osmand.data.RotatedTileBox;
import net.osmand.map.OsmandRegions;
import net.osmand.plus.R;
import net.osmand.plus.activities.DownloadIndexActivity;
import net.osmand.plus.activities.OsmandIntents;
import net.osmand.plus.resources.ResourceManager;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
import android.content.Context;
import android.content.Intent;
import android.graphics.*;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Cap;
import android.graphics.Paint.Join;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.PointF;
import android.os.AsyncTask;
import android.text.TextPaint;
import android.util.DisplayMetrics;
@ -15,39 +37,23 @@ import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;
import net.osmand.IndexConstants;
import net.osmand.binary.BinaryMapDataObject;
import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox;
import net.osmand.map.OsmandRegions;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.DownloadIndexActivity;
import net.osmand.plus.activities.OsmandIntents;
import net.osmand.plus.resources.ResourceManager;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
import java.io.IOException;
import java.util.*;
public class DownloadedRegionsLayer extends OsmandMapLayer {
private static final int ZOOM_THRESHOLD = 2;
private OsmandMapTileView view;
private Paint paint;
private Path path;
private OsmandSettings settings;
private OsmandRegions osmandRegions;
private List<BinaryMapDataObject> objectsToDraw = new ArrayList<BinaryMapDataObject>();
private QuadRect queriedBBox = new QuadRect();
private int queriedZoom = 0;
private RotatedTileBox queriedBox;
private boolean basemapExists = true;
private boolean noMapsPresent = false;
private TextPaint textPaint;
@ -60,7 +66,6 @@ public class DownloadedRegionsLayer extends OsmandMapLayer {
@Override
public void initLayer(final OsmandMapTileView view) {
this.view = view;
settings = view.getSettings();
rm = view.getApplication().getResourceManager();
osmandRegions = rm.getOsmandRegions();
@ -107,106 +112,119 @@ public class DownloadedRegionsLayer extends OsmandMapLayer {
private static int ZOOM_TO_SHOW_BORDERS_ST = 5;
private static int ZOOM_TO_SHOW_BORDERS = 7;
private static int ZOOM_TO_SHOW_MAP_NAMES = 12;
@Override
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings nightMode) {
final int zoom = tb.getZoom();
if(downloadBtn.getVisibility() == View.VISIBLE) {
downloadBtn.setVisibility(View.GONE);
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
final int zoom = tileBox.getZoom();
if(zoom < ZOOM_TO_SHOW_BORDERS_ST) {
return;
}
if (zoom >= ZOOM_TO_SHOW_BORDERS_ST && (zoom < ZOOM_TO_SHOW_BORDERS || zoom >= ZOOM_TO_SHOW_MAP_NAMES) &&
osmandRegions.isInitialized()) {
final QuadRect latLonBox = tb.getLatLonBounds();
if (!queriedBBox.contains(latLonBox) || Math.abs(queriedZoom - zoom) > 2) {
float w = Math.abs(latLonBox.width() / 2);
float h = Math.abs(latLonBox.height() / 2);
final QuadRect rf = new QuadRect(latLonBox.left - w, latLonBox.top + h, latLonBox.right + w, latLonBox.bottom - h);
AsyncTask<Object, Object, List<BinaryMapDataObject>> task = createNewTask(zoom, rf);
if (currentTask == null) {
task.execute();
} else {
pendingTask = task;
// draw objects
if (zoom >= ZOOM_TO_SHOW_BORDERS_ST && zoom < ZOOM_TO_SHOW_BORDERS && osmandRegions.isInitialized()) {
final List<BinaryMapDataObject> currentObjects = objectsToDraw;
path.reset();
for (BinaryMapDataObject o : currentObjects) {
final String key = Algorithms.capitalizeFirstLetterAndLowercase(osmandRegions.getDownloadName(o))
+ IndexConstants.BINARY_MAP_INDEX_EXT;
if (!rm.getIndexFileNames().containsKey(key)) {
continue;
}
double lat = MapUtils.get31LatitudeY(o.getPoint31YTile(0));
double lon = MapUtils.get31LongitudeX(o.getPoint31XTile(0));
path.moveTo(tileBox.getPixXFromLonNoRot(lon), tileBox.getPixYFromLatNoRot(lat));
for (int j = 1; j < o.getPointsLength(); j++) {
lat = MapUtils.get31LatitudeY(o.getPoint31YTile(j));
lon = MapUtils.get31LongitudeX(o.getPoint31XTile(j));
path.lineTo(tileBox.getPixXFromLonNoRot(lon), tileBox.getPixYFromLatNoRot(lat));
}
}
final List<BinaryMapDataObject> currentObjects = objectsToDraw;
if ((currentObjects != null && currentObjects.size() > 0) || noMapsPresent) {
if (zoom >= ZOOM_TO_SHOW_MAP_NAMES) {
StringBuilder s = new StringBuilder(view.getResources().getString(R.string.download_files));
filter.setLength(0);
Set<String> set = new TreeSet<String>();
if ((currentObjects != null && currentObjects.size() > 0)) {
for (int i = 0; i < currentObjects.size(); i++) {
final BinaryMapDataObject o = currentObjects.get(i);
String name = Algorithms.capitalizeFirstLetterAndLowercase(o.getName());
if(!set.add(name)) {
continue;
}
if (set.size() > 1) {
s.append(" & ");
filter.append(", ");
} else {
s.append(" ");
}
filter.append(name);
if (osmandRegions.getPrefix(o) != null) {
name = Algorithms.capitalizeFirstLetterAndLowercase(osmandRegions.getPrefix(o)) + " " + name;
}
s.append(name);
}
}
downloadBtn.setVisibility(View.VISIBLE);
downloadBtn.setText(s.toString());
} else {
if(!basemapExists) {
filter.setLength(0);
filter.append("basemap");
downloadBtn.setVisibility(View.VISIBLE);
downloadBtn.setText(view.getResources().getString(R.string.download_files) + " " +
view.getResources().getString(R.string.base_world_map));
}
path.reset();
for (BinaryMapDataObject o : currentObjects) {
final String key = Algorithms.capitalizeFirstLetterAndLowercase(osmandRegions.getDownloadName(o)) +
IndexConstants.BINARY_MAP_INDEX_EXT;
if (!rm.getIndexFileNames().containsKey(key)) {
canvas.drawPath(path, paint);
}
}
private RotatedTileBox queryNewData(RotatedTileBox tileBox) {
if (queriedBox == null || queriedBox.containsTileBox(tileBox) || Math.abs(queriedBox.getZoom() - tileBox.getZoom()) > ZOOM_THRESHOLD ) {
tileBox = tileBox.copy();
tileBox.increasePixelDimensions(tileBox.getPixWidth() / 2, tileBox.getPixHeight() / 2);
AsyncTask<Object, Object, List<BinaryMapDataObject>> task = createNewTask(tileBox);
if (currentTask == null) {
task.execute();
} else {
pendingTask = task;
}
}
return tileBox;
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) {
final int zoom = tileBox.getZoom();
if(view.getMainLayer() instanceof MapTileLayer) {
return;
}
// query from UI thread because of Android AsyncTask bug (Handler init)
queryNewData(tileBox);
if (downloadBtn.getVisibility() == View.VISIBLE) {
downloadBtn.setVisibility(View.GONE);
}
if (osmandRegions.isInitialized() && queriedBox != null) {
if (zoom < ZOOM_TO_SHOW_MAP_NAMES && !basemapExists) {
filter.setLength(0);
filter.append("basemap");
downloadBtn.setVisibility(View.VISIBLE);
downloadBtn.setText(view.getResources().getString(R.string.download_files) + " "
+ view.getResources().getString(R.string.base_world_map));
} else if(zoom >= ZOOM_TO_SHOW_MAP_NAMES && noMapsPresent && Math.abs(queriedBox.getZoom() - zoom) <= ZOOM_THRESHOLD){
final List<BinaryMapDataObject> currentObjects = objectsToDraw;
StringBuilder s = new StringBuilder(view.getResources().getString(R.string.download_files));
filter.setLength(0);
Set<String> set = new TreeSet<String>();
if ((currentObjects != null && currentObjects.size() > 0)) {
for (int i = 0; i < currentObjects.size(); i++) {
final BinaryMapDataObject o = currentObjects.get(i);
String name = Algorithms.capitalizeFirstLetterAndLowercase(o.getName());
if (!set.add(name)) {
continue;
}
double lat = MapUtils.get31LatitudeY(o.getPoint31YTile(0));
double lon = MapUtils.get31LongitudeX(o.getPoint31XTile(0));
path.moveTo(tb.getPixXFromLonNoRot(lon), tb.getPixYFromLatNoRot(lat));
for(int j = 1 ; j < o.getPointsLength(); j++) {
lat = MapUtils.get31LatitudeY(o.getPoint31YTile(j));
lon = MapUtils.get31LongitudeX(o.getPoint31XTile(j));
path.lineTo(tb.getPixXFromLonNoRot(lon),
tb.getPixYFromLatNoRot(lat));
if (set.size() > 1) {
s.append(" & ");
filter.append(", ");
} else {
s.append(" ");
}
filter.append(name);
if (osmandRegions.getPrefix(o) != null) {
name = Algorithms.capitalizeFirstLetterAndLowercase(osmandRegions.getPrefix(o)) + " "
+ name;
}
s.append(name);
}
canvas.drawPath(path, paint);
}
downloadBtn.setVisibility(View.VISIBLE);
downloadBtn.setText(s.toString());
}
}
}
private AsyncTask<Object, Object, List<BinaryMapDataObject>> createNewTask(final int zoom, final QuadRect rf) {
private AsyncTask<Object, Object, List<BinaryMapDataObject>> createNewTask(final RotatedTileBox tileBox) {
return new AsyncTask<Object, Object, List<BinaryMapDataObject>>() {
@Override
protected List<BinaryMapDataObject> doInBackground(Object... params) {
if (queriedBBox.contains(rf)) {
if (queriedBox != null && !queriedBox.containsTileBox(tileBox) && Math.abs(queriedBox.getZoom() - tileBox.getZoom()) <= ZOOM_THRESHOLD ) {
return null;
}
if (zoom < ZOOM_TO_SHOW_MAP_NAMES) {
if (tileBox.getZoom() < ZOOM_TO_SHOW_MAP_NAMES) {
basemapExists = rm.getRenderer().basemapExists();
}
List<BinaryMapDataObject> result = null;
int left = MapUtils.get31TileNumberX(rf.left);
int right = MapUtils.get31TileNumberX(rf.right);
int top = MapUtils.get31TileNumberY(rf.top);
int bottom = MapUtils.get31TileNumberY(rf.bottom);
final boolean empty = rm.getRenderer().checkIfMapIsEmpty(left, right, top, bottom, zoom);
int left = MapUtils.get31TileNumberX(tileBox.getLeftTopLatLon().getLongitude());
int right = MapUtils.get31TileNumberX(tileBox.getRightBottomLatLon().getLongitude());
int top = MapUtils.get31TileNumberY(tileBox.getLeftTopLatLon().getLatitude());
int bottom = MapUtils.get31TileNumberY(tileBox.getRightBottomLatLon().getLatitude());
final boolean empty = rm.getRenderer().checkIfMapIsEmpty(left, right, top, bottom, tileBox.getZoom());
noMapsPresent = empty;
if (!empty && zoom >= ZOOM_TO_SHOW_MAP_NAMES) {
if (!empty && tileBox.getZoom() >= ZOOM_TO_SHOW_MAP_NAMES) {
return Collections.emptyList();
}
try {
@ -217,7 +235,7 @@ public class DownloadedRegionsLayer extends OsmandMapLayer {
Iterator<BinaryMapDataObject> it = result.iterator();
while (it.hasNext()) {
BinaryMapDataObject o = it.next();
if (zoom < ZOOM_TO_SHOW_BORDERS) {
if (tileBox.getZoom() < ZOOM_TO_SHOW_BORDERS) {
//
} else {
if (!osmandRegions.contain(o, left / 2 + right / 2, top / 2 + bottom / 2)) {
@ -236,9 +254,8 @@ public class DownloadedRegionsLayer extends OsmandMapLayer {
@Override
protected void onPostExecute(List<BinaryMapDataObject> result) {
if (result != null) {
queriedBBox = rf;
queriedBox = tileBox;
objectsToDraw = result;
queriedZoom = zoom;
}
currentTask = null;
if (pendingTask != null) {

View file

@ -71,15 +71,19 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.I
@Override
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings nightMode) {
if (tb.getZoom() >= startZoom) {
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
}
@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
if (tileBox.getZoom() >= startZoom) {
// request to load
final QuadRect latLonBounds = tb.getLatLonBounds();
final QuadRect latLonBounds = tileBox.getLatLonBounds();
for (FavouritePoint o : favorites.getFavouritePoints()) {
if (o.getLatitude() >= latLonBounds.bottom && o.getLatitude() <= latLonBounds.top && o.getLongitude() >= latLonBounds.left
&& o.getLongitude() <= latLonBounds.right ) {
int x = tb.getPixXFromLatLon(o.getLatitude(), o.getLongitude());
int y = tb.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
int x = tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude());
int y = tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
canvas.drawBitmap(favoriteIcon, x - favoriteIcon.getWidth() / 2,
y - favoriteIcon.getHeight(), paint);
}

View file

@ -70,18 +70,17 @@ public class GPXLayer extends OsmandMapLayer {
return cachedColor;
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings nightMode) {
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
GPXFile gpxFile = view.getApplication().getGpxFileToDisplay();
if(gpxFile == null){
return;
}
List<List<WptPt>> points = gpxFile.processedPointsToDisplay;
paint.setColor(getColor(nightMode));
paint.setColor(getColor(settings));
final QuadRect latLonBounds = tb.getLatLonBounds();
final QuadRect latLonBounds = tileBox.getLatLonBounds();
for (List<WptPt> l : points) {
path.rewind();
int startIndex = -1;
@ -95,16 +94,19 @@ public class GPXLayer extends OsmandMapLayer {
}
} else if (!(latLonBounds.left <= ls.lon + 0.1 && ls.lon - 0.1 <= latLonBounds.right
&& latLonBounds.bottom <= ls.lat + 0.1 && ls.lat - 0.1 <= latLonBounds.top)) {
drawSegment(canvas, tb, l, startIndex, i);
drawSegment(canvas, tileBox, l, startIndex, i);
startIndex = -1;
}
}
if (startIndex != -1) {
drawSegment(canvas, tb, l, startIndex, l.size() - 1);
drawSegment(canvas, tileBox, l, startIndex, l.size() - 1);
continue;
}
}
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
}

View file

@ -1,8 +1,7 @@
package net.osmand.plus.views;
import android.graphics.Canvas;
import android.graphics.RectF;
import net.osmand.data.RotatedTileBox;
import android.graphics.Canvas;
/**
* This class is designed to represent adapter for specific map sources

View file

@ -108,9 +108,9 @@ public class MapTileLayer extends BaseMapLayer {
return mapTileAdapter;
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings drawSettings) {
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox,
DrawSettings drawSettings) {
if ((map == null && mapTileAdapter == null) || !visible) {
return;
}
@ -120,6 +120,11 @@ public class MapTileLayer extends BaseMapLayer {
drawTileMap(canvas, tileBox);
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings drawSettings) {
}
public void drawTileMap(Canvas canvas, RotatedTileBox tileBox) {
if(map == null){
return;

View file

@ -27,12 +27,16 @@ import net.osmand.util.MapUtils;
import org.apache.commons.logging.Log;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.PointF;
import android.graphics.RectF;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.os.SystemClock;
import android.util.AttributeSet;
@ -50,6 +54,8 @@ import android.widget.Toast;
public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCallback, Callback {
private static final int MAP_REFRESH_MESSAGE = 1;
private static final int BASE_REFRESH_MESSAGE = 2;
protected final static int LOWEST_ZOOM_TO_ROTATE = 9;
private boolean MEASURE_FPS = false;
private FPSMeasurement main = new FPSMeasurement();
@ -89,8 +95,10 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
}
protected static final Log log = PlatformUtil.getLog(OsmandMapTileView.class);
private RotatedTileBox currentViewport;
private float rotate; // accumulate
private int mapPosition;
@ -115,7 +123,8 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
// UI Part
// handler to refresh map (in ui thread - ui thread is not necessary, but msg queue is required).
protected Handler handler = new Handler();
protected Handler handler ;
private Handler baseHandler;
private AnimateDraggingMapThread animatedDraggingThread;
@ -131,6 +140,15 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
private DisplayMetrics dm;
private final OsmandApplication application;
protected OsmandSettings settings = null;
private Bitmap bufferBitmap;
private RotatedTileBox bufferImgLoc;
private Bitmap bufferBitmapTmp;
private Paint paintImg;
public OsmandMapTileView(Context context, AttributeSet attrs) {
super(context, attrs);
@ -170,13 +188,21 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
paintCenter.setColor(Color.rgb(60, 60, 60));
paintCenter.setStrokeWidth(2);
paintCenter.setAntiAlias(true);
paintImg = new Paint();
// paintImg.setFilterBitmap(true);
// paintImg.setDither(true);
setClickable(true);
setLongClickable(true);
setFocusable(true);
getHolder().addCallback(this);
handler = new Handler();
HandlerThread ht = new HandlerThread("RenderingBaseImage");
ht.start();
baseHandler = new Handler(ht.getLooper());
getHolder().addCallback(this);
animatedDraggingThread = new AnimateDraggingMapThread(this);
gestureDetector = new GestureDetector(getContext(), new MapExplorer(this, new MapTileViewOnGestureListener()));
multiTouchSupport = new MultiTouchSupport(getContext(), new MapTileViewMultiTouchZoomListener());
@ -355,7 +381,6 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
this.mapPosition = type;
}
protected OsmandSettings settings = null;
public OsmandSettings getSettings(){
if(settings == null){
settings = getApplication().getSettings();
@ -363,13 +388,64 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
return settings;
}
private void drawBasemap(Canvas canvas) {
if(bufferImgLoc != null) {
float rot = - bufferImgLoc.getRotate();
final LatLon lt = bufferImgLoc.getLeftTopLatLon();
final LatLon rb = bufferImgLoc.getRightBottomLatLon();
canvas.rotate(rot, currentViewport.getCenterPixelX(), currentViewport.getCenterPixelY());
final RotatedTileBox calc = currentViewport.copy();
calc.setRotate(bufferImgLoc.getRotate());
final int x1 = calc.getPixXFromLatLon(lt.getLatitude(), lt.getLongitude());
final int x2 = calc.getPixXFromLatLon(rb.getLatitude(), rb.getLongitude());
final int y1 = calc.getPixYFromLatLon(lt.getLatitude(), lt.getLongitude());
final int y2 = calc.getPixYFromLatLon(rb.getLatitude(), rb.getLongitude());
if(!bufferBitmap.isRecycled()){
canvas.drawBitmap(bufferBitmap, null, new RectF(x1, y1, x2, y2), paintImg);
}
canvas.rotate(-rot, currentViewport.getCenterPixelX(), currentViewport.getCenterPixelY());
}
}
private void refreshBaseMapInternal(RotatedTileBox tileBox, DrawSettings drawSettings) {
// bmp = Bitmap.createBitmap(currentRenderingContext.width, currentRenderingContext.height, Config.ARGB_8888);
if(tileBox.getPixHeight() == 0 || tileBox.getPixWidth() == 0){
return;
}
baseHandler.removeMessages(BASE_REFRESH_MESSAGE);
if(bufferBitmapTmp == null || tileBox.getPixHeight() != bufferBitmapTmp.getHeight()
|| tileBox.getPixWidth() != bufferBitmapTmp.getWidth()) {
bufferBitmapTmp = Bitmap.createBitmap(tileBox.getPixWidth(), tileBox.getPixHeight(), Config.RGB_565);
}
long start = SystemClock.elapsedRealtime();
final QuadPoint c = tileBox.getCenterPixelPoint();
Canvas canvas = new Canvas(bufferBitmapTmp);
fillCanvas(canvas, drawSettings);
for (int i = 0; i < layers.size(); i++) {
try {
OsmandMapLayer layer = layers.get(i);
canvas.save();
// rotate if needed
if (!layer.drawInScreenPixels()) {
canvas.rotate(tileBox.getRotate(), c.x, c.y);
}
layer.onPrepareBufferImage(canvas, tileBox, drawSettings);
canvas.restore();
} catch (IndexOutOfBoundsException e) {
// skip it
}
}
Bitmap t = bufferBitmap;
synchronized (this) {
bufferImgLoc = tileBox;
bufferBitmap = bufferBitmapTmp;
bufferBitmapTmp = t;
}
long end = SystemClock.elapsedRealtime();
additional.calculateFPS(start, end);
}
private void refreshMapInternal(boolean updateVectorRendering) {
handler.removeMessages(1);
private void refreshMapInternal(DrawSettings drawSettings) {
handler.removeMessages(MAP_REFRESH_MESSAGE);
SurfaceHolder holder = getHolder();
long ms = SystemClock.elapsedRealtime();
synchronized (holder) {
@ -383,15 +459,9 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
currentViewport.setPixelDimensions(getWidth(), getHeight(), 0.5f, ratioy);
}
// make copy to avoid concurrency
boolean nightMode = application.getDaynightHelper().isNightMode();
RotatedTileBox viewportToDraw = currentViewport.copy();
DrawSettings drawSettings = new DrawSettings(nightMode, updateVectorRendering);
if (nightMode) {
canvas.drawARGB(255, 100, 100, 100);
} else {
canvas.drawARGB(255, 225, 225, 225);
}
drawOverMap(canvas, viewportToDraw, drawSettings, false);
fillCanvas(canvas, drawSettings);
drawOverMap(canvas, viewportToDraw, drawSettings);
} finally {
holder.unlockCanvasAndPost(canvas);
}
@ -402,6 +472,15 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
}
}
private void fillCanvas(Canvas canvas, DrawSettings drawSettings) {
if (drawSettings.isNightMode()) {
canvas.drawARGB(255, 100, 100, 100);
} else {
canvas.drawARGB(255, 225, 225, 225);
}
}
public boolean isMeasureFPS() {
return MEASURE_FPS;
}
@ -417,39 +496,61 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
return additional.fps;
}
private void drawOverMap(Canvas canvas, RotatedTileBox tileBox, DrawSettings drawSettings, boolean
onPrepareImage) {
private void drawOverMap(Canvas canvas, RotatedTileBox tileBox, DrawSettings drawSettings) {
final QuadPoint c = tileBox.getCenterPixelPoint();
// long prev = System.currentTimeMillis();
synchronized (this) {
if (bufferBitmap != null && !bufferBitmap.isRecycled()) {
canvas.save();
canvas.rotate(tileBox.getRotate(), c.x, c.y);
drawBasemap(canvas);
canvas.restore();
}
}
for (int i = 0; i < layers.size(); i++) {
try {
OsmandMapLayer layer = layers.get(i);
canvas.save();
// rotate if needed
if (!layer.drawInScreenPixels()) {
canvas.rotate(tileBox.getRotate(), c.x, c.y);
}
if(onPrepareImage) {
layer.onPrepareBufferImage(canvas, tileBox, drawSettings);
} else {
layer.onDraw(canvas, tileBox, drawSettings);
}
layer.onDraw(canvas, tileBox, drawSettings);
canvas.restore();
} catch (IndexOutOfBoundsException e) {
// skip it
}
}
if (showMapPosition && !onPrepareImage) {
if (showMapPosition) {
canvas.drawCircle(c.x, c.y, 3 * dm.density, paintCenter);
canvas.drawCircle(c.x, c.y, 7 * dm.density, paintCenter);
}
}
public boolean mapIsRefreshing() {
return handler.hasMessages(1);
return handler.hasMessages(MAP_REFRESH_MESSAGE);
}
private void refreshBufferImage(final DrawSettings drawSettings) {
if (!baseHandler.hasMessages(BASE_REFRESH_MESSAGE) || drawSettings.isUpdateVectorRendering()) {
Message msg = Message.obtain(handler, new Runnable() {
@Override
public void run() {
if(bufferBitmap == null) {
System.out.println("St " + System.currentTimeMillis());
}
baseHandler.removeMessages(BASE_REFRESH_MESSAGE);
refreshBaseMapInternal(currentViewport.copy(), drawSettings);
sendRefreshMapMsg(drawSettings, 0);
if(bufferBitmapTmp == null) {
System.out.println("End " + System.currentTimeMillis());
}
}
});
msg.what = BASE_REFRESH_MESSAGE;
// baseHandler.sendMessageDelayed(msg, 0);
baseHandler.sendMessage(msg);
}
}
// this method could be called in non UI thread
@ -459,16 +560,27 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
// this method could be called in non UI thread
public void refreshMap(final boolean updateVectorRendering) {
if (!handler.hasMessages(1) || updateVectorRendering) {
handler.removeMessages(1);
boolean nightMode = application.getDaynightHelper().isNightMode();
DrawSettings drawSettings = new DrawSettings(nightMode, updateVectorRendering);
sendRefreshMapMsg(drawSettings, 20);
refreshBufferImage(drawSettings);
}
private void sendRefreshMapMsg(final DrawSettings drawSettings, int delay) {
if (!handler.hasMessages(MAP_REFRESH_MESSAGE) || drawSettings.isUpdateVectorRendering()) {
Message msg = Message.obtain(handler, new Runnable() {
@Override
public void run() {
refreshMapInternal(updateVectorRendering);
handler.removeMessages(MAP_REFRESH_MESSAGE);
refreshMapInternal(drawSettings);
}
});
msg.what = 1;
handler.sendMessageDelayed(msg, 20);
msg.what = MAP_REFRESH_MESSAGE;
if (delay > 0) {
handler.sendMessageDelayed(msg, delay);
} else {
handler.sendMessage(msg);
}
}
}

View file

@ -7,16 +7,22 @@ import java.util.List;
import net.osmand.PlatformUtil;
import net.osmand.access.AccessibleToast;
import net.osmand.data.*;
import net.osmand.data.Amenity;
import net.osmand.data.AmenityType;
import net.osmand.data.LatLon;
import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox;
import net.osmand.osm.MapRenderingTypes;
import net.osmand.plus.*;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.PoiFilter;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.render.RenderingIcons;
import net.osmand.plus.resources.ResourceManager;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
@ -27,8 +33,6 @@ import android.graphics.Paint.Align;
import android.graphics.Paint.Style;
import android.graphics.PointF;
import android.net.Uri;
import android.util.DisplayMetrics;
import android.view.WindowManager;
import android.widget.Toast;
public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider {
@ -159,18 +163,18 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
return (int) (r * tb.getDensity());
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings nightMode) {
if (tb.getZoom() >= startZoom) {
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
if (tileBox.getZoom() >= startZoom) {
objects.clear();
final QuadRect latLonBounds = tb.getLatLonBounds();
final QuadRect latLonBounds = tileBox.getLatLonBounds();
resourceManager.searchAmenitiesAsync(latLonBounds.top, latLonBounds.left, latLonBounds.bottom,
latLonBounds.right, tb.getZoom(), filter, objects);
int r = getRadiusPoi(tb);
latLonBounds.right, tileBox.getZoom(), filter, objects);
int r = getRadiusPoi(tileBox);
for (Amenity o : objects) {
int x = tb.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
int y = tb.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
int x = tileBox.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
int y = tileBox.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
canvas.drawCircle(x, y, r, pointAltUI);
canvas.drawCircle(x, y, r, point);
String id = null;
@ -193,10 +197,10 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
if (view.getSettings().SHOW_POI_LABEL.get()) {
TIntHashSet set = new TIntHashSet();
for (Amenity o : objects) {
int x = tb.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
int y = tb.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
int tx = tb.getPixXFromLonNoRot(o.getLocation().getLongitude());
int ty = tb.getPixYFromLatNoRot(o.getLocation().getLatitude());
int x = tileBox.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
int y = tileBox.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
int tx = tileBox.getPixXFromLonNoRot(o.getLocation().getLongitude());
int ty = tileBox.getPixYFromLatNoRot(o.getLocation().getLatitude());
String name = o.getName(view.getSettings().USE_ENGLISH_NAMES.get());
if (name != null && name.length() > 0) {
int lines = 0;
@ -224,8 +228,13 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
}
}
}
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {}
private int division(int x, int y, int sx, int sy) {
// make numbers positive
return ((((x + 10000) >> 4) + sx) << 16) | (((y + 10000) >> 4) + sy);

View file

@ -17,8 +17,6 @@ import android.graphics.Paint.Join;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.RectF;
public class RouteLayer extends OsmandMapLayer {
@ -77,20 +75,20 @@ public class RouteLayer extends OsmandMapLayer {
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings nightMode) {
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
path.reset();
if (helper.getFinalLocation() != null && helper.getRoute().isCalculated()) {
paint.setColor(getColor(nightMode));
int w = tb.getPixWidth();
int h = tb.getPixHeight();
paint.setColor(getColor(settings));
int w = tileBox.getPixWidth();
int h = tileBox.getPixHeight();
Location lastProjection = helper.getLastProjection();
final RotatedTileBox cp ;
if(lastProjection != null &&
tb.containsLatLon(lastProjection.getLatitude(), lastProjection.getLongitude())){
cp = tb.copy();
tileBox.containsLatLon(lastProjection.getLatitude(), lastProjection.getLongitude())){
cp = tileBox.copy();
cp.increasePixelDimensions(w /2, h);
} else {
cp = tb;
cp = tileBox;
}
final QuadRect latlonRect = cp.getLatLonBounds();
@ -100,9 +98,13 @@ public class RouteLayer extends OsmandMapLayer {
double rightLongitude = latlonRect.right;
double lat = topLatitude - bottomLatitude + 0.1;
double lon = rightLongitude - leftLongitude + 0.1;
drawLocations(tb, canvas, topLatitude + lat, leftLongitude - lon, bottomLatitude - lat, rightLongitude + lon);
drawLocations(tileBox, canvas, topLatitude + lat, leftLongitude - lon, bottomLatitude - lat, rightLongitude + lon);
}
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {}
private void drawSegment(RotatedTileBox tb, Canvas canvas) {

View file

@ -10,12 +10,9 @@ import net.osmand.data.TransportStop;
import net.osmand.plus.R;
import net.osmand.plus.activities.TransportRouteHelper;
import net.osmand.plus.resources.TransportIndexRepository.RouteInfoLocation;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PointF;
import android.util.DisplayMetrics;
import android.view.WindowManager;
import android.widget.Toast;
public class TransportInfoLayer extends OsmandMapLayer {
@ -58,11 +55,14 @@ public class TransportInfoLayer extends OsmandMapLayer {
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox t, DrawSettings nightMode) {
if(routeHelper.routeIsCalculated() && visible){
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {}
@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
if (routeHelper.routeIsCalculated() && visible) {
List<RouteInfoLocation> list = routeHelper.getRoute();
for(RouteInfoLocation l : list){
if(l == null){
for (RouteInfoLocation l : list) {
if (l == null) {
// once l is null in list
continue;
}
@ -70,30 +70,31 @@ public class TransportInfoLayer extends OsmandMapLayer {
boolean start = false;
boolean end = false;
List<TransportStop> stops = l.getDirection() ? route.getForwardStops() : route.getBackwardStops();
for(int i=0; i<stops.size() && !end; i++){
for (int i = 0; i < stops.size() && !end; i++) {
Paint toShow = paintInt;
TransportStop st = stops.get(i);
if(!start){
if(st == l.getStart()){
if (!start) {
if (st == l.getStart()) {
start = true;
toShow = paintEnd;
}
} else {
if(st == l.getStop()){
if (st == l.getStop()) {
end = true;
toShow = paintEnd;
}
}
if(start){
if (start) {
LatLon location = st.getLocation();
if (t.containsLatLon(location.getLatitude(), location.getLongitude())) {
int x = t.getPixXFromLatLon(location.getLatitude(), location.getLongitude());
int y = t.getPixYFromLatLon(location.getLatitude(), location.getLongitude());
canvas.drawRect(x - getRadius(t), y - getRadius(t), x + getRadius(t), y + getRadius(t), toShow);
if (tileBox.containsLatLon(location.getLatitude(), location.getLongitude())) {
int x = tileBox.getPixXFromLatLon(location.getLatitude(), location.getLongitude());
int y = tileBox.getPixYFromLatLon(location.getLatitude(), location.getLongitude());
canvas.drawRect(x - getRadius(tileBox), y - getRadius(tileBox), x + getRadius(tileBox), y
+ getRadius(tileBox), toShow);
}
}
}
}
}
}

View file

@ -137,7 +137,8 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
@Override
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings nightMode) {
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tb,
DrawSettings settings) {
if (tb.getZoom() >= startZoom) {
objects.clear();
final QuadRect latLonBounds = tb.getLatLonBounds();
@ -149,9 +150,12 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
int y = tb.getPixYFromLatNoRot(o.getLocation().getLatitude());
canvas.drawRect(x - r, y - r, x + r, y + r, pointAltUI);
}
}
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings settings) {
}
@Override
public void destroyLayer() {