Fix transport stops

This commit is contained in:
Victor Shcherb 2016-08-02 09:56:07 +02:00
parent 453a9650d0
commit 8c8f2f2201
5 changed files with 110 additions and 48 deletions

View file

@ -401,7 +401,7 @@ public class BinaryMapTransportReaderAdapter {
int filePointer) throws IOException {
TransportStop dataObject = new TransportStop();
dataObject.setFileOffset(codedIS.getTotalBytesRead());
dataObject.setReferencesToRoutes(new int[] {filePointer});
// dataObject.setReferencesToRoutes(new int[] {filePointer});
boolean end = false;
while(!end){
int t = codedIS.readTag();

View file

@ -5,9 +5,11 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import net.osmand.binary.BinaryMapIndexReader.SearchRequest;
import net.osmand.data.LatLon;
import net.osmand.data.MapObject;
import net.osmand.data.QuadPoint;
import net.osmand.data.QuadRect;
import net.osmand.util.GeoPointParserUtil.GeoParsedPoint;
@ -534,6 +536,25 @@ public class MapUtils {
}
return x;
}
public static QuadRect calculateLatLonBbox(double latitude, double longitude, int radiusMeters) {
int zoom = 16;
float coeff = (float) (radiusMeters / MapUtils.getTileDistanceWidth(zoom));
double tx = MapUtils.getTileNumberX(zoom, longitude);
double ty = MapUtils.getTileNumberY(zoom, latitude);
double topLeftX = Math.max(0, tx - coeff);
double topLeftY = Math.max(0, ty - coeff);
int max = (1 << zoom) - 1;
double bottomRightX = Math.min(max, tx + coeff);
double bottomRightY = Math.min(max, ty + coeff);
double pw = MapUtils.getPowZoom(31 - zoom);
QuadRect rect = new QuadRect(topLeftX * pw, topLeftY * pw, bottomRightX * pw, bottomRightY * pw);
rect.left = MapUtils.get31LongitudeX((int) rect.left);
rect.top = MapUtils.get31LatitudeY((int) rect.top);
rect.right = MapUtils.get31LongitudeX((int) rect.right);
rect.bottom = MapUtils.get31LatitudeY((int) rect.bottom);
return rect;
}

View file

@ -595,6 +595,7 @@ public class ConfigureMapMenu {
for (int i = 0; i < prefs.size(); i++) {
prefs.get(i).set(false);
}
adapter.getItem(pos).setColorRes(ContextMenuItem.INVALID_ID);
a.notifyDataSetInvalidated();
refreshMapComplete(activity);
activity.getMapLayers().updateLayers(activity.getMapView());
@ -636,6 +637,7 @@ public class ConfigureMapMenu {
break;
}
}
builder.setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
builder.setSelected(selected);
}
return builder.createItem();
@ -686,7 +688,18 @@ public class ConfigureMapMenu {
bld.setTitle(category);
bld.setNegativeButton(R.string.shared_string_cancel, null);
bld.setNegativeButton(R.string.shared_string_cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
boolean selected = false;
for (int i = 0; i < prefs.size(); i++) {
prefs.get(i).set(tempPrefs[i]);
selected |= tempPrefs[i];
}
adapter.getItem(pos).setSelected(selected);
adapter.getItem(pos).setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
a.notifyDataSetInvalidated();
}
});
bld.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
@ -700,6 +713,7 @@ public class ConfigureMapMenu {
adapter.getItem(pos).setDescription(getDescription(prefs));
} else{
adapter.getItem(pos).setSelected(selected);
adapter.getItem(pos).setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
}
}
a.notifyDataSetInvalidated();

View file

@ -1,14 +1,17 @@
package net.osmand.plus.mapcontextmenu.controllers;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
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.activities.MapActivity;
@ -18,6 +21,7 @@ import net.osmand.plus.mapcontextmenu.MenuController;
import net.osmand.plus.resources.TransportIndexRepository;
import net.osmand.plus.views.TransportStopsLayer;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
import android.view.View;
import android.view.View.OnClickListener;
@ -123,7 +127,8 @@ public class TransportStopController extends MenuController {
@Override
public void onClick(View arg0) {
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.getDescription(getMapActivity().getMyApplication(), false));
mm.show(latLon, pd, r);
TransportStopsLayer stopsLayer = getMapActivity().getMapLayers().getTransportStopsLayer();
stopsLayer.setRoute(r.route);
@ -132,9 +137,11 @@ public class TransportStopController extends MenuController {
}
};
if (r.type == null) {
addPlainMenuItem(R.drawable.ic_action_polygom_dark, r.desc, false, false, listener );
addPlainMenuItem(R.drawable.ic_action_polygom_dark, r.getDescription(getMapActivity().getMyApplication(), true),
false, false, listener );
} else {
addPlainMenuItem(r.type.getResourceId(), r.desc, false, false, listener);
addPlainMenuItem(r.type.getResourceId(), r.getDescription(getMapActivity().getMyApplication(), true),
false, false, listener);
}
}
super.addPlainMenuItems(typeStr, pointDescription, latLon);
@ -150,32 +157,54 @@ public class TransportStopController extends MenuController {
for (TransportIndexRepository t : reps) {
if (t.acceptTransportStop(transportStop)) {
Collection<TransportRoute> rts = t.getRouteForStop(transportStop);
if (rts != null) {
for (TransportRoute rs : rts) {
TransportStopType type = TransportStopType.findType(rs.getType());
TransportStopRoute r = new TransportStopRoute();
if (topType == null && type != null && type.isTopType()) {
topType = type;
}
r.type = type;
r.desc = rs.getRef() + " " + (useEnglishNames ? rs.getEnName(true) : rs.getName());
r.route = rs;
r.stop = transportStop;
this.routes.add(r);
addRoutes(useEnglishNames, t, transportStop, 0);
ArrayList<TransportStop> ls = new ArrayList<>();
QuadRect ll = MapUtils.calculateLatLonBbox(transportStop.getLocation().getLatitude(), transportStop.getLocation().getLongitude(), 150);
t.searchTransportStops(ll.top, ll.left, ll.bottom, ll.right, -1, ls, null);
for(TransportStop tstop : ls) {
if(tstop.getId() != transportStop.getId() || !Arrays.equals(tstop.getReferencesToRoutes(),
transportStop.getReferencesToRoutes())) {
addRoutes(useEnglishNames, t, tstop, (int) MapUtils.getDistance(tstop.getLocation(), transportStop.getLocation()));
}
}
}
}
}
private void addRoutes(boolean useEnglishNames, TransportIndexRepository t, TransportStop s, int dist) {
Collection<TransportRoute> rts = t.getRouteForStop(s);
if (rts != null) {
for (TransportRoute rs : rts) {
TransportStopType type = TransportStopType.findType(rs.getType());
TransportStopRoute r = new TransportStopRoute();
if (topType == null && type != null && type.isTopType()) {
topType = type;
}
r.type = type;
r.desc = rs.getRef() + " " + (useEnglishNames ? rs.getEnName(true) : rs.getName());
r.route = rs;
r.stop = s;
r.distance = dist;
this.routes.add(r);
}
}
}
public static class TransportStopRoute {
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) {
return desc +" (" + OsmAndFormatter.getFormattedDistance(distance, ctx) +")";
}
return desc;
}
public int calculateZoom(int startPosition, RotatedTileBox currentRotatedTileBox) {
RotatedTileBox cp = currentRotatedTileBox.copy();
boolean notContains = true;

View file

@ -1,5 +1,33 @@
package net.osmand.plus.osmedit;
import java.io.Serializable;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import net.osmand.CallbackWithObject;
import net.osmand.PlatformUtil;
import net.osmand.data.Amenity;
import net.osmand.data.LatLon;
import net.osmand.osm.PoiCategory;
import net.osmand.osm.PoiType;
import net.osmand.osm.edit.EntityInfo;
import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.OSMSettings;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndDialogFragment;
import net.osmand.plus.osmedit.dialogs.PoiSubTypeDialogFragment;
import net.osmand.plus.osmedit.dialogs.PoiTypeDialogFragment;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
@ -46,34 +74,6 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import net.osmand.CallbackWithObject;
import net.osmand.PlatformUtil;
import net.osmand.data.Amenity;
import net.osmand.data.LatLon;
import net.osmand.osm.PoiCategory;
import net.osmand.osm.PoiType;
import net.osmand.osm.edit.EntityInfo;
import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.OSMSettings;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndDialogFragment;
import net.osmand.plus.osmedit.dialogs.PoiSubTypeDialogFragment;
import net.osmand.plus.osmedit.dialogs.PoiTypeDialogFragment;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import java.io.Serializable;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
public static final String TAG = "EditPoiDialogFragment";
private static final Log LOG = PlatformUtil.getLog(EditPoiDialogFragment.class);
@ -192,8 +192,6 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
ViewTreeObserver obs = view.getViewTreeObserver();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
obs.removeOnGlobalLayoutListener(this);
} else {
obs.removeGlobalOnLayoutListener(this);
}