Add transport route

This commit is contained in:
Victor Shcherb 2016-07-29 18:05:40 +02:00
parent edab731bed
commit 99c3d9ca18
4 changed files with 62 additions and 11 deletions

View file

@ -174,6 +174,8 @@
<color name="nav_track">#CCaa0088</color> <color name="nav_track">#CCaa0088</color>
<color name="nav_track_fluorescent">#CC00ddff</color> <color name="nav_track_fluorescent">#CC00ddff</color>
<color name="transport_route_line">#CCaa0088</color>
<color name="nav_arrow_distant">#C0C0C0</color> <color name="nav_arrow_distant">#C0C0C0</color>
<color name="nav_arrow">#FADE23</color> <color name="nav_arrow">#FADE23</color>

View file

@ -11,6 +11,7 @@ import net.osmand.plus.mapcontextmenu.MapContextMenu;
import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.mapcontextmenu.MenuBuilder;
import net.osmand.plus.mapcontextmenu.MenuController; import net.osmand.plus.mapcontextmenu.MenuController;
import net.osmand.plus.resources.TransportIndexRepository; import net.osmand.plus.resources.TransportIndexRepository;
import net.osmand.plus.views.TransportInfoLayer;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import java.util.ArrayList; import java.util.ArrayList;
@ -122,6 +123,8 @@ public class TransportStopController extends MenuController {
public void onClick(View arg0) { public void onClick(View arg0) {
MapContextMenu mm = getMapActivity().getContextMenu(); MapContextMenu mm = getMapActivity().getContextMenu();
PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_TRANSPORT_ROUTE, r.desc); PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_TRANSPORT_ROUTE, r.desc);
TransportInfoLayer tif = getMapActivity().getMapLayers().getTransportInfoLayer();
tif.
mm.show(latLon, pd, r); mm.show(latLon, pd, r);
} }
}; };

View file

@ -377,11 +377,11 @@ public abstract class OsmandMapLayer {
} }
public boolean updatePaints(OsmandMapTileView view, DrawSettings settigns, RotatedTileBox tileBox) { public boolean updatePaints(OsmandMapTileView view, DrawSettings settings, RotatedTileBox tileBox) {
OsmandApplication app = view.getApplication(); OsmandApplication app = view.getApplication();
OsmandRenderer renderer = app.getResourceManager().getRenderer().getRenderer(); OsmandRenderer renderer = app.getResourceManager().getRenderer().getRenderer();
RenderingRulesStorage rrs = app.getRendererRegistry().getCurrentSelectedRenderer(); RenderingRulesStorage rrs = app.getRendererRegistry().getCurrentSelectedRenderer();
final boolean isNight = settigns != null && settigns.isNightMode(); final boolean isNight = settings != null && settings.isNightMode();
int hsh = calculateHash(rrs, isNight, tileBox.getMapDensity()); int hsh = calculateHash(rrs, isNight, tileBox.getMapDensity());
if (hsh != cachedHash) { if (hsh != cachedHash) {
cachedHash = hsh; cachedHash = hsh;

View file

@ -5,9 +5,11 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PointF; import android.graphics.PointF;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.view.WindowManager; import android.view.WindowManager;
import net.osmand.Location;
import net.osmand.ResultMatcher; import net.osmand.ResultMatcher;
import net.osmand.data.Amenity; import net.osmand.data.Amenity;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
@ -15,9 +17,13 @@ import net.osmand.data.PointDescription;
import net.osmand.data.QuadRect; import net.osmand.data.QuadRect;
import net.osmand.data.QuadTree; import net.osmand.data.QuadTree;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.data.TransportRoute;
import net.osmand.data.TransportStop; import net.osmand.data.TransportStop;
import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.Way;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.poi.PoiUIFilter;
import gnu.trove.list.array.TIntArrayList;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -32,9 +38,14 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
private Paint paintIcon; private Paint paintIcon;
private Bitmap stopBus; private Bitmap stopBus;
private Bitmap stopSmall; private Bitmap stopSmall;
private RenderingLineAttributes attrs;
private MapLayerData<List<TransportStop>> data; private MapLayerData<List<TransportStop>> data;
private TransportRoute route = null;
private Path path;
@SuppressWarnings("deprecation")
@Override @Override
public void initLayer(final OsmandMapTileView view) { public void initLayer(final OsmandMapTileView view) {
this.view = view; this.view = view;
@ -43,9 +54,12 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
wmgr.getDefaultDisplay().getMetrics(dm); wmgr.getDefaultDisplay().getMetrics(dm);
paintIcon = new Paint(); paintIcon = new Paint();
path = new Path();
stopBus = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_transport_stop_bus); stopBus = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_transport_stop_bus);
stopSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_transport_stop_small); stopSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_transport_stop_small);
attrs = new RenderingLineAttributes("transport_route");
attrs.defaultWidth = (int) (12 * view.getDensity());
attrs.defaultColor = view.getResources().getColor(R.color.transport_route_line);
data = new OsmandMapLayer.MapLayerData<List<TransportStop>>() { data = new OsmandMapLayer.MapLayerData<List<TransportStop>>() {
{ {
ZOOM_THRESHOLD = 0; ZOOM_THRESHOLD = 0;
@ -118,6 +132,14 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
} }
} }
public TransportRoute getRoute() {
return route;
}
public void setRoute(TransportRoute route) {
this.route = route;
}
public int getRadiusPoi(RotatedTileBox tb){ public int getRadiusPoi(RotatedTileBox tb){
@ -139,16 +161,16 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
@Override @Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tb,
DrawSettings settings) { DrawSettings settings) {
if (tileBox.getZoom() >= startZoom) { if (tb.getZoom() >= startZoom) {
data.queryNewData(tileBox);; data.queryNewData(tb);;
float iconSize = stopBus.getWidth() * 3 / 2.5f; float iconSize = stopBus.getWidth() * 3 / 2.5f;
QuadTree<QuadRect> boundIntersections = initBoundIntersections(tileBox); QuadTree<QuadRect> boundIntersections = initBoundIntersections(tb);
List<TransportStop> fullObjects = new ArrayList<>(); List<TransportStop> fullObjects = new ArrayList<>();
for (TransportStop o : data.getResults()) { for (TransportStop o : data.getResults()) {
float x = tileBox.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude()); float x = tb.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
float y = tileBox.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude()); float y = tb.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
if (intersects(boundIntersections, x, y, iconSize, iconSize)) { if (intersects(boundIntersections, x, y, iconSize, iconSize)) {
canvas.drawBitmap(stopSmall, x - stopSmall.getWidth() / 2, y - stopSmall.getHeight() / 2, paintIcon); canvas.drawBitmap(stopSmall, x - stopSmall.getWidth() / 2, y - stopSmall.getHeight() / 2, paintIcon);
@ -157,11 +179,35 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
} }
} }
for (TransportStop o : fullObjects) { for (TransportStop o : fullObjects) {
float x = tileBox.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude()); float x = tb.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
float y = tileBox.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude()); float y = tb.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
Bitmap b = stopBus; Bitmap b = stopBus;
canvas.drawBitmap(b, x - b.getWidth() / 2, y - b.getHeight() / 2, paintIcon); canvas.drawBitmap(b, x - b.getWidth() / 2, y - b.getHeight() / 2, paintIcon);
} }
if(route != null) {
attrs.updatePaints(view, settings, tb);
canvas.rotate(-tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY());
try {
path.reset();
List<Way> ws = route.getAggregateForwardWays();
for (Way w : ws) {
TIntArrayList tx = new TIntArrayList();
TIntArrayList ty = new TIntArrayList();
for (int i = 0; i < w.getNodes().size(); i++) {
Node o = w.getNodes().get(i);
int x = (int) tb.getPixXFromLatLon(o.getLatitude(), o.getLongitude());
int y = (int) tb.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
tx.add(x);
ty.add(y);
}
calculatePath(tb, tx, ty, path);
}
attrs.drawPath(canvas, path);
} finally {
canvas.rotate(tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY());
}
}
} }
} }