implement transport layer info

git-svn-id: https://osmand.googlecode.com/svn/trunk@388 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-07-22 20:40:28 +00:00
parent 292166001a
commit dc2312ad57
3 changed files with 171 additions and 20 deletions

View file

@ -8,25 +8,10 @@ package com.osmand;
*/
public class ToDoConstants {
// TODO ANDROID 0.3
// Improvements
// 1. Show layers (?) (+)
// 0) map + 1) transport (+) 2) Poi (choose filter) (+) 3) osm bugs (+) 3) Favorites(+)
// 4) Route (gmaps) + 5) Transport route -
// and remove from settings (+)
// 1.4 show detailed route on the map with turns and show route information directly (like in gmaps) (+)
// 2. Using NameFinder to search online (+)
// 3. Show route info after route calc (+)
// 4. show vehicle for calculating route (+)
// 5. Add zorders list to OsmandMapView (+)
// BUGS
// ISSUE 21. (+, +, +)
// ISSUE 23.
// TODO
// Improvements
// 5. Download with wget
// 6. progress while map is loading
@ -35,7 +20,6 @@ public class ToDoConstants {
// 69. Add phone information to POI
// 70. Show building numbers over map (require changin address index - index 2 more columns lat/lon for fast search)
// Unscheduled (complex)
// 66. Transport routing (show next stop, total distance, show stop get out, voice) (?).
// 64. Traffic information (?) - rmaps (http://jgo.maps.yandex.net/tiles?l=trf)?
@ -58,6 +42,9 @@ public class ToDoConstants {
// 68. Implement service to app work with screen offline
// (audio guidance & add new item to status bar & introduce error interval for gps in buildings)
// 71. Implement different mechanism for tiles (big sqlite planet see rmaps)
// 72. Implement layers menu in map view (select/unselect vector layers to show)
// 73. Implement addition POI filter to search online without sd indexes
// 74. Implement preview route : show next turn & description (in "show only" route mode) & preview transport route.
// DONE SWING

View file

@ -93,6 +93,7 @@ import com.osmand.views.PointLocationLayer;
import com.osmand.views.PointNavigationLayer;
import com.osmand.views.RouteInfoLayer;
import com.osmand.views.RouteLayer;
import com.osmand.views.TransportInfoLayer;
import com.osmand.views.TransportStopsLayer;
public class MapActivity extends Activity implements IMapLocationListener, SensorEventListener {
@ -121,6 +122,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
private POIMapLayer poiMapLayer;
private FavoritesLayer favoritesLayer;
private TransportStopsLayer transportStopsLayer;
private TransportInfoLayer transportInfoLayer;
private PointLocationLayer locationLayer;
private PointNavigationLayer navigationLayer;
private MapInfoLayer mapInfoLayer;
@ -210,6 +212,9 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
favoritesLayer = new FavoritesLayer(this);
// 5. transport layer
transportStopsLayer = new TransportStopsLayer();
// 5.5 transport info layer
transportInfoLayer = new TransportInfoLayer(TransportRouteHelper.getInstance());
mapView.addLayer(transportInfoLayer, 5.5f);
// 6. point navigation layer
navigationLayer = new PointNavigationLayer();
mapView.addLayer(navigationLayer, 6);
@ -1110,8 +1115,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
selected[routeInfoInd] = routeInfoLayer.isUserDefinedVisible();
}
if(transportRouteInfoInd != -1){
// TODO
selected[transportRouteInfoInd] = true;
selected[transportRouteInfoInd] = transportInfoLayer.isVisible();
}
Builder builder = new AlertDialog.Builder(this);
@ -1136,7 +1140,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
} else if(item == routeInfoInd){
routeInfoLayer.setVisible(isChecked);
} else if(item == transportRouteInfoInd){
// TODO
transportInfoLayer.setVisible(isChecked);
}
updateLayers();
mapView.refreshMap();

View file

@ -0,0 +1,160 @@
package com.osmand.views;
import java.util.List;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.RectF;
import android.widget.Toast;
import com.osmand.OsmandSettings;
import com.osmand.TransportIndexRepository.RouteInfoLocation;
import com.osmand.activities.TransportRouteHelper;
import com.osmand.data.TransportRoute;
import com.osmand.data.TransportStop;
import com.osmand.osm.LatLon;
import com.osmand.osm.MapUtils;
public class TransportInfoLayer implements OsmandMapLayer {
private final TransportRouteHelper routeHelper;
private Rect pixRect;
private OsmandMapTileView view;
private RectF tileRect;
private Paint paintInt;
private Paint paintEnd;
private boolean visible = true;
public TransportInfoLayer(TransportRouteHelper routeHelper){
this.routeHelper = routeHelper;
}
public void initLayer(OsmandMapTileView view) {
this.view = view;
pixRect = new Rect();
tileRect = new RectF();
paintInt = new Paint();
paintInt.setColor(Color.rgb(50, 200, 50));
paintInt.setAlpha(150);
paintInt.setAntiAlias(true);
paintEnd = new Paint();
paintEnd.setColor(Color.rgb(255, 0, 0));
paintEnd.setAlpha(150);
paintEnd.setAntiAlias(true);
}
public boolean isVisible() {
return visible;
}
public void setVisible(boolean visible) {
this.visible = visible;
}
@Override
public void onDraw(Canvas canvas) {
List<RouteInfoLocation> list = routeHelper.getRoute();
if(!list.isEmpty() && visible){
pixRect.set(0, 0, view.getWidth(), view.getHeight());
view.calculateTileRectangle(pixRect, view.getCenterPointX(),
view.getCenterPointY(), view.getXTile(), view.getYTile(), tileRect);
double topLatitude = MapUtils.getLatitudeFromTile(view.getZoom(), tileRect.top);
double leftLongitude = MapUtils.getLongitudeFromTile(view.getZoom(), tileRect.left);
double bottomLatitude = MapUtils.getLatitudeFromTile(view.getZoom(), tileRect.bottom);
double rightLongitude = MapUtils.getLongitudeFromTile(view.getZoom(), tileRect.right);
for(RouteInfoLocation l : list){
TransportRoute route = l.getRoute();
boolean start = false;
boolean end = false;
List<TransportStop> stops = l.getDirection() ? route.getForwardStops() : route.getBackwardStops();
for(int i=0; i<stops.size() && !end; i++){
Paint toShow = paintInt;
TransportStop st = stops.get(i);
if(!start){
if(st == l.getStart()){
start = true;
toShow = paintEnd;
}
} else {
if(st == l.getStop()){
end = true;
toShow = paintEnd;
}
}
if(start){
LatLon location = st.getLocation();
if(location.getLatitude() <= topLatitude && location.getLatitude() >= bottomLatitude &&
location.getLongitude() >= leftLongitude && location.getLongitude() <= rightLongitude){
int x = view.getRotatedMapXForPoint(location.getLatitude(), location.getLongitude());
int y = view.getRotatedMapYForPoint(location.getLatitude(), location.getLongitude());
canvas.drawRect(x - 8, y - 8, x + 8, y + 8, toShow);
}
}
}
}
}
}
@Override
public void destroyLayer() {
}
@Override
public boolean drawInScreenPixels() {
return false;
}
@Override
public boolean onLongPressEvent(PointF point) {
return false;
}
@Override
public boolean onTouchEvent(PointF point) {
int ex = (int) point.x;
int ey = (int) point.y;
if (visible && !routeHelper.getRoute().isEmpty()) {
for (RouteInfoLocation l : routeHelper.getRoute()) {
TransportRoute route = l.getRoute();
boolean start = false;
boolean end = false;
List<TransportStop> stops = l.getDirection() ? route.getForwardStops() : route.getBackwardStops();
for (int i = 0; i < stops.size() && !end; i++) {
TransportStop st = stops.get(i);
if (!start) {
if (st == l.getStart()) {
start = true;
}
} else {
if (st == l.getStop()) {
end = true;
}
}
if (start) {
LatLon location = st.getLocation();
int x = view.getRotatedMapXForPoint(location.getLatitude(), location.getLongitude());
int y = view.getRotatedMapYForPoint(location.getLatitude(), location.getLongitude());
if (Math.abs(x - ex) < 13 && Math.abs(y - ey) < 13) {
Toast.makeText(view.getContext(), st.getName(OsmandSettings.usingEnglishNames(view.getContext())) + " : " + //$NON-NLS-1$
route.getType() + " " + route.getRef() //$NON-NLS-1$
, Toast.LENGTH_LONG).show();
return true;
}
}
}
}
}
return false;
}
}