Draw coloured transport route on map
This commit is contained in:
parent
5b136fdcdf
commit
729101faf2
10 changed files with 111 additions and 103 deletions
81
OsmAnd/src/net/osmand/plus/TransportStopRoute.java
Normal file
81
OsmAnd/src/net/osmand/plus/TransportStopRoute.java
Normal file
|
@ -0,0 +1,81 @@
|
|||
package net.osmand.plus;
|
||||
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.data.TransportRoute;
|
||||
import net.osmand.data.TransportStop;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.TransportStopController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TransportStopRoute {
|
||||
public TransportStop refStop;
|
||||
public TransportStopController.TransportStopType type;
|
||||
public String desc;
|
||||
public TransportRoute route;
|
||||
public TransportStop stop;
|
||||
public int distance;
|
||||
public boolean showWholeRoute;
|
||||
|
||||
public String getDescription(OsmandApplication ctx, boolean useDistance) {
|
||||
if (useDistance && distance > 0) {
|
||||
String nm = OsmAndFormatter.getFormattedDistance(distance, ctx);
|
||||
if (refStop != null && !refStop.getName().equals(stop.getName())) {
|
||||
nm = refStop.getName() + ", " + nm;
|
||||
}
|
||||
return desc + " (" + nm + ")";
|
||||
}
|
||||
return desc;
|
||||
}
|
||||
|
||||
public int calculateZoom(int startPosition, RotatedTileBox currentRotatedTileBox) {
|
||||
RotatedTileBox cp = currentRotatedTileBox.copy();
|
||||
boolean notContains = true;
|
||||
while (cp.getZoom() > 12 && notContains) {
|
||||
notContains = false;
|
||||
List<TransportStop> sts = route.getForwardStops();
|
||||
for (int i = startPosition; i < sts.size(); i++) {
|
||||
TransportStop st = sts.get(startPosition);
|
||||
if (!cp.containsLatLon(st.getLocation())) {
|
||||
notContains = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
cp.setZoom(cp.getZoom() - 1);
|
||||
}
|
||||
return cp.getZoom();
|
||||
}
|
||||
|
||||
public int getColor(boolean nightMode) {
|
||||
int color;
|
||||
switch (type) {
|
||||
case BUS:
|
||||
color = R.color.route_bus_color;
|
||||
break;
|
||||
case SHARE_TAXI:
|
||||
color = R.color.route_share_taxi_color;
|
||||
break;
|
||||
case TROLLEYBUS:
|
||||
color = R.color.route_trolleybus_color;
|
||||
break;
|
||||
case TRAM:
|
||||
color = R.color.route_tram_color;
|
||||
break;
|
||||
case TRAIN:
|
||||
color = nightMode ? R.color.route_train_color_dark : R.color.route_train_color_light;
|
||||
break;
|
||||
case LIGHT_RAIL:
|
||||
color = R.color.route_lightrail_color;
|
||||
break;
|
||||
case FUNICULAR:
|
||||
color = R.color.route_funicular_color;
|
||||
break;
|
||||
case FERRY:
|
||||
color = nightMode ? R.color.route_ferry_color_dark : R.color.route_ferry_color_light;
|
||||
break;
|
||||
default:
|
||||
color = R.color.nav_track;
|
||||
break;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
}
|
|
@ -37,7 +37,7 @@ import net.osmand.plus.mapcontextmenu.MenuController.MenuType;
|
|||
import net.osmand.plus.mapcontextmenu.MenuController.TitleButtonController;
|
||||
import net.osmand.plus.mapcontextmenu.MenuController.TitleProgressController;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.MapDataMenuController;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.TransportStopController.TransportStopRoute;
|
||||
import net.osmand.plus.TransportStopRoute;
|
||||
import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditor;
|
||||
import net.osmand.plus.mapcontextmenu.editors.PointEditor;
|
||||
import net.osmand.plus.mapcontextmenu.editors.RtePtEditor;
|
||||
|
|
|
@ -46,7 +46,7 @@ import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
|
|||
import net.osmand.plus.mapcontextmenu.MenuController.MenuState;
|
||||
import net.osmand.plus.mapcontextmenu.MenuController.TitleButtonController;
|
||||
import net.osmand.plus.mapcontextmenu.MenuController.TitleProgressController;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.TransportStopController.TransportStopRoute;
|
||||
import net.osmand.plus.TransportStopRoute;
|
||||
import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu;
|
||||
import net.osmand.plus.views.AnimateDraggingMapThread;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
|
@ -399,7 +399,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
route.getDescription(getMapActivity().getMyApplication(), false));
|
||||
menu.show(menu.getLatLon(), pd, route);
|
||||
TransportStopsLayer stopsLayer = getMapActivity().getMapLayers().getTransportStopsLayer();
|
||||
stopsLayer.setRoute(route.route);
|
||||
stopsLayer.setRoute(route);
|
||||
int cz = route.calculateZoom(0, getMapActivity().getMapView().getCurrentRotatedTileBox());
|
||||
getMapActivity().changeZoom(cz - getMapActivity().getMapView().getZoom());
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ import net.osmand.plus.mapcontextmenu.builders.cards.CardsRowBuilder;
|
|||
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard;
|
||||
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask;
|
||||
import net.osmand.plus.mapcontextmenu.builders.cards.NoImagesCard;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.TransportStopController.TransportStopRoute;
|
||||
import net.osmand.plus.TransportStopRoute;
|
||||
import net.osmand.plus.myplaces.FavoritesActivity;
|
||||
import net.osmand.plus.render.RenderingIcons;
|
||||
import net.osmand.plus.views.TransportStopsLayer;
|
||||
|
@ -790,7 +790,7 @@ public class MenuBuilder {
|
|||
r.getDescription(getMapActivity().getMyApplication(), false));
|
||||
mm.show(latLon, pd, r);
|
||||
TransportStopsLayer stopsLayer = getMapActivity().getMapLayers().getTransportStopsLayer();
|
||||
stopsLayer.setRoute(r.route);
|
||||
stopsLayer.setRoute(r);
|
||||
int cz = r.calculateZoom(0, getMapActivity().getMapView().getCurrentRotatedTileBox());
|
||||
getMapActivity().changeZoom(cz - getMapActivity().getMapView().getZoom());
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ import net.osmand.plus.mapcontextmenu.controllers.RenderedObjectMenuController;
|
|||
import net.osmand.plus.mapcontextmenu.controllers.TargetPointMenuController;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.TransportRouteController;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.TransportStopController;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.TransportStopController.TransportStopRoute;
|
||||
import net.osmand.plus.TransportStopRoute;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.WptPtMenuController;
|
||||
import net.osmand.plus.mapcontextmenu.other.ShareMenu;
|
||||
import net.osmand.plus.mapillary.MapillaryImage;
|
||||
|
|
|
@ -12,7 +12,7 @@ import android.widget.ArrayAdapter;
|
|||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.TransportStopController.TransportStopRoute;
|
||||
import net.osmand.plus.TransportStopRoute;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package net.osmand.plus.mapcontextmenu.controllers;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
|
@ -14,16 +12,14 @@ import net.osmand.osm.PoiType;
|
|||
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.mapcontextmenu.MapContextMenu;
|
||||
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
||||
import net.osmand.plus.mapcontextmenu.MenuController;
|
||||
import net.osmand.plus.mapcontextmenu.OpeningHoursInfo;
|
||||
import net.osmand.plus.mapcontextmenu.builders.AmenityMenuBuilder;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.TransportStopController.TransportStopRoute;
|
||||
import net.osmand.plus.TransportStopRoute;
|
||||
import net.osmand.plus.render.RenderingIcons;
|
||||
import net.osmand.plus.resources.TransportIndexRepository;
|
||||
import net.osmand.plus.views.POIMapLayer;
|
||||
import net.osmand.plus.views.TransportStopsLayer;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.MapUtils;
|
||||
import net.osmand.util.OpeningHoursParser;
|
||||
|
|
|
@ -12,7 +12,7 @@ import net.osmand.plus.activities.MapActivity;
|
|||
import net.osmand.plus.mapcontextmenu.MapContextMenu;
|
||||
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
||||
import net.osmand.plus.mapcontextmenu.MenuController;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.TransportStopController.TransportStopRoute;
|
||||
import net.osmand.plus.TransportStopRoute;
|
||||
import net.osmand.plus.views.TransportStopsLayer;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -202,7 +202,7 @@ public class TransportRouteController extends MenuController {
|
|||
TransportStopsLayer stopsLayer = getMapActivity().getMapLayers().getTransportStopsLayer();
|
||||
int cz = transportRoute.calculateZoom(0, getMapActivity().getMapView().getCurrentRotatedTileBox());
|
||||
getMapActivity().changeZoom(cz - getMapActivity().getMapView().getZoom());
|
||||
stopsLayer.setRoute(transportRoute.route);
|
||||
stopsLayer.setRoute(transportRoute);
|
||||
}
|
||||
|
||||
private void resetRoute() {
|
||||
|
|
|
@ -6,12 +6,10 @@ import android.view.View.OnClickListener;
|
|||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.data.QuadRect;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.data.TransportRoute;
|
||||
import net.osmand.data.TransportStop;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.TransportStopRoute;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.mapcontextmenu.MapContextMenu;
|
||||
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
||||
|
@ -137,7 +135,7 @@ public class TransportStopController extends MenuController {
|
|||
r.getDescription(getMapActivity().getMyApplication(), false));
|
||||
mm.show(latLon, pd, r);
|
||||
TransportStopsLayer stopsLayer = getMapActivity().getMapLayers().getTransportStopsLayer();
|
||||
stopsLayer.setRoute(r.route);
|
||||
stopsLayer.setRoute(r);
|
||||
int cz = r.calculateZoom(0, getMapActivity().getMapView().getCurrentRotatedTileBox());
|
||||
getMapActivity().changeZoom(cz - getMapActivity().getMapView().getZoom());
|
||||
}
|
||||
|
@ -227,76 +225,4 @@ public class TransportStopController extends MenuController {
|
|||
return false;
|
||||
}
|
||||
|
||||
public static class TransportStopRoute {
|
||||
public TransportStop refStop;
|
||||
public TransportStopType type;
|
||||
public String desc;
|
||||
public TransportRoute route;
|
||||
public TransportStop stop;
|
||||
public int distance;
|
||||
public boolean showWholeRoute;
|
||||
|
||||
public String getDescription(OsmandApplication ctx, boolean useDistance) {
|
||||
if (useDistance && distance > 0) {
|
||||
String nm = OsmAndFormatter.getFormattedDistance(distance, ctx);
|
||||
if (refStop != null && !refStop.getName().equals(stop.getName())) {
|
||||
nm = refStop.getName() + ", " + nm;
|
||||
}
|
||||
return desc + " (" + nm + ")";
|
||||
}
|
||||
return desc;
|
||||
}
|
||||
|
||||
public int calculateZoom(int startPosition, RotatedTileBox currentRotatedTileBox) {
|
||||
RotatedTileBox cp = currentRotatedTileBox.copy();
|
||||
boolean notContains = true;
|
||||
while (cp.getZoom() > 12 && notContains) {
|
||||
notContains = false;
|
||||
List<TransportStop> sts = route.getForwardStops();
|
||||
for(int i = startPosition; i < sts.size(); i++) {
|
||||
TransportStop st = sts.get(startPosition);
|
||||
if (!cp.containsLatLon(st.getLocation())) {
|
||||
notContains = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
cp.setZoom(cp.getZoom() - 1);
|
||||
}
|
||||
return cp.getZoom();
|
||||
}
|
||||
|
||||
public int getColor(boolean nightMode) {
|
||||
int color;
|
||||
switch (type) {
|
||||
case BUS:
|
||||
color = R.color.route_bus_color;
|
||||
break;
|
||||
case SHARE_TAXI:
|
||||
color = R.color.route_share_taxi_color;
|
||||
break;
|
||||
case TROLLEYBUS:
|
||||
color = R.color.route_trolleybus_color;
|
||||
break;
|
||||
case TRAM:
|
||||
color = R.color.route_tram_color;
|
||||
break;
|
||||
case TRAIN:
|
||||
color = nightMode ? R.color.route_train_color_dark : R.color.route_train_color_light;
|
||||
break;
|
||||
case LIGHT_RAIL:
|
||||
color = R.color.route_lightrail_color;
|
||||
break;
|
||||
case FUNICULAR:
|
||||
color = R.color.route_funicular_color;
|
||||
break;
|
||||
case FERRY:
|
||||
color = nightMode ? R.color.route_ferry_color_dark : R.color.route_ferry_color_light;
|
||||
break;
|
||||
default:
|
||||
color = R.color.nav_track;
|
||||
break;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.graphics.Canvas;
|
|||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.PointF;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.WindowManager;
|
||||
|
||||
|
@ -16,11 +17,11 @@ import net.osmand.data.PointDescription;
|
|||
import net.osmand.data.QuadRect;
|
||||
import net.osmand.data.QuadTree;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.data.TransportRoute;
|
||||
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.TransportStopRoute;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -38,13 +39,14 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
|
|||
private final MapActivity mapActivity;
|
||||
private OsmandMapTileView view;
|
||||
|
||||
private int cachedColor;
|
||||
private Paint paintIcon;
|
||||
private Bitmap stopBus;
|
||||
private Bitmap stopSmall;
|
||||
private RenderingLineAttributes attrs;
|
||||
|
||||
private MapLayerData<List<TransportStop>> data;
|
||||
private TransportRoute route = null;
|
||||
private TransportStopRoute stopRoute = null;
|
||||
|
||||
private boolean showTransportStops;
|
||||
private Path path;
|
||||
|
@ -67,7 +69,6 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
|
|||
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>>() {
|
||||
{
|
||||
ZOOM_THRESHOLD = 0;
|
||||
|
@ -143,12 +144,12 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
|
|||
}
|
||||
}
|
||||
|
||||
public TransportRoute getRoute() {
|
||||
return route;
|
||||
public TransportStopRoute getRoute() {
|
||||
return stopRoute;
|
||||
}
|
||||
|
||||
public void setRoute(TransportRoute route) {
|
||||
this.route = route;
|
||||
public void setRoute(TransportStopRoute route) {
|
||||
this.stopRoute = route;
|
||||
}
|
||||
|
||||
public boolean isShowTransportStops() {
|
||||
|
@ -176,17 +177,21 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
|
|||
return (int) (r * tb.getDensity());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tb, DrawSettings settings) {
|
||||
List<TransportStop> objects = null;
|
||||
if (tb.getZoom() >= startZoomRoute) {
|
||||
if (route != null) {
|
||||
objects = route.getForwardStops();
|
||||
if (stopRoute != null) {
|
||||
objects = stopRoute.route.getForwardStops();
|
||||
int color = stopRoute.getColor(settings.isNightMode());
|
||||
if (cachedColor != color) {
|
||||
cachedColor = color;
|
||||
attrs.paint.setColor(ContextCompat.getColor(mapActivity, cachedColor));
|
||||
}
|
||||
attrs.updatePaints(view, settings, tb);
|
||||
try {
|
||||
path.reset();
|
||||
List<Way> ws = route.getForwardWays();
|
||||
List<Way> ws = stopRoute.route.getForwardWays();
|
||||
if (ws != null) {
|
||||
for (Way w : ws) {
|
||||
TIntArrayList tx = new TIntArrayList();
|
||||
|
@ -286,8 +291,8 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
|
|||
|
||||
@Override
|
||||
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> res, boolean unknownLocation) {
|
||||
if(tileBox.getZoom() >= startZoomRoute && route != null) {
|
||||
getFromPoint(tileBox, point, res, route.getForwardStops());
|
||||
if(tileBox.getZoom() >= startZoomRoute && stopRoute != null) {
|
||||
getFromPoint(tileBox, point, res, stopRoute.route.getForwardStops());
|
||||
} else if (tileBox.getZoom() >= startZoom && data.getResults() != null) {
|
||||
getFromPoint(tileBox, point, res, data.getResults());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue