use of net.osmand.data.TransportStop in project Osmand by osmandapp.
the class BinaryMapIndexReader method searchTransportIndex.
public List<TransportStop> searchTransportIndex(SearchRequest<TransportStop> req) throws IOException {
for (TransportIndex index : transportIndexes) {
if (index.stopsFileLength == 0 || index.right < req.left || index.left > req.right || index.top > req.bottom || index.bottom < req.top) {
continue;
}
codedIS.seek(index.stopsFileOffset);
int oldLimit = codedIS.pushLimit(index.stopsFileLength);
int offset = req.searchResults.size();
transportAdapter.searchTransportTreeBounds(0, 0, 0, 0, req);
codedIS.popLimit(oldLimit);
if (req.stringTable != null) {
transportAdapter.initializeStringTable(index, req.stringTable);
for (int i = offset; i < req.searchResults.size(); i++) {
TransportStop st = req.searchResults.get(i);
transportAdapter.initializeNames(req.stringTable, st);
}
}
}
if (req.numberOfVisitedObjects > 0) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
log.debug("Search is done. Visit " + req.numberOfVisitedObjects + " objects. Read " + req.numberOfAcceptedObjects + " objects.");
// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
log.debug("Read " + req.numberOfReadSubtrees + " subtrees. Go through " + req.numberOfAcceptedSubtrees + " subtrees.");
}
return req.getSearchResults();
}
use of net.osmand.data.TransportStop in project Osmand by osmandapp.
the class TransportStopsLayer method onPrepareBufferImage.
@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tb, DrawSettings settings) {
List<TransportStop> objects = null;
if (tb.getZoom() >= startZoomRoute) {
if (stopRoute != null) {
objects = stopRoute.route.getForwardStops();
int color = stopRoute.getColor(mapActivity.getMyApplication(), settings.isNightMode());
attrs.paint.setColor(color);
attrs.updatePaints(view, settings, tb);
try {
path.reset();
List<Way> ws = stopRoute.route.getForwardWays();
if (ws != null) {
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);
} catch (Exception e) {
// ignore
}
}
}
if (showTransportStops && tb.getZoom() >= startZoom && objects == null) {
data.queryNewData(tb);
objects = data.getResults();
}
if (objects != null) {
float iconSize = stopBus.getWidth() * 3 / 2.5f;
QuadTree<QuadRect> boundIntersections = initBoundIntersections(tb);
List<TransportStop> fullObjects = new ArrayList<>();
for (TransportStop o : objects) {
float x = tb.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
float y = tb.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
if (intersects(boundIntersections, x, y, iconSize, iconSize)) {
canvas.drawBitmap(stopSmall, x - stopSmall.getWidth() / 2, y - stopSmall.getHeight() / 2, paintIcon);
} else {
fullObjects.add(o);
}
}
for (TransportStop o : fullObjects) {
float x = tb.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
float y = tb.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
if (stopRoute != null) {
TransportStopType type = TransportStopType.findType(stopRoute.route.getType());
if (type != null) {
Bitmap foregroundIcon = RenderingIcons.getIcon(mapActivity, type.getResName(), false);
canvas.drawBitmap(backgroundIcon, x - backgroundIconHalfWidth, y - backgroundIconHalfHeight, paintIcon);
canvas.drawBitmap(foregroundIcon, x - foregroundIcon.getWidth() / 2, y - foregroundIcon.getHeight() / 2, paintWhiteIcon);
}
} else {
Bitmap b = stopBus;
canvas.drawBitmap(b, x - b.getWidth() / 2, y - b.getHeight() / 2, paintIcon);
}
}
}
}
use of net.osmand.data.TransportStop in project Osmand by osmandapp.
the class TransportStopsLayer method initLayer.
@SuppressWarnings("deprecation")
@Override
public void initLayer(final OsmandMapTileView view) {
backgroundIcon = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_transport_stop_bg);
backgroundIconHalfWidth = backgroundIcon.getWidth() / 2;
backgroundIconHalfHeight = backgroundIcon.getWidth() / 2;
this.view = view;
DisplayMetrics dm = new DisplayMetrics();
WindowManager wmgr = (WindowManager) view.getContext().getSystemService(Context.WINDOW_SERVICE);
wmgr.getDefaultDisplay().getMetrics(dm);
paintIcon = new Paint();
paintWhiteIcon = new Paint();
paintWhiteIcon.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(mapActivity, R.color.primary_text_dark), PorterDuff.Mode.SRC_IN));
path = new Path();
stopBus = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_transport_stop_bus);
stopSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_transport_stop_small);
attrs = new RenderingLineAttributes("transport_route");
attrs.defaultWidth = (int) (6 * view.getDensity());
data = new OsmandMapLayer.MapLayerData<List<TransportStop>>() {
{
ZOOM_THRESHOLD = 0;
}
@Override
public boolean isInterrupted() {
return super.isInterrupted();
}
@Override
public void layerOnPostExecute() {
view.refreshMap();
}
@Override
protected List<TransportStop> calculateResult(RotatedTileBox tileBox) {
QuadRect latLonBounds = tileBox.getLatLonBounds();
if (latLonBounds == null) {
return new ArrayList<>();
}
List<TransportStop> res = view.getApplication().getResourceManager().searchTransportSync(latLonBounds.top, latLonBounds.left, latLonBounds.bottom, latLonBounds.right, new ResultMatcher<TransportStop>() {
@Override
public boolean publish(TransportStop object) {
return true;
}
@Override
public boolean isCancelled() {
return isInterrupted();
}
});
Collections.sort(res, new Comparator<TransportStop>() {
@Override
public int compare(TransportStop lhs, TransportStop rhs) {
return lhs.getId() < rhs.getId() ? -1 : (lhs.getId().longValue() == rhs.getId().longValue() ? 0 : 1);
}
});
return res;
}
};
}
use of net.osmand.data.TransportStop in project Osmand by osmandapp.
the class MenuController method getMenuController.
public static MenuController getMenuController(MapActivity mapActivity, LatLon latLon, PointDescription pointDescription, Object object, MenuType menuType) {
MenuController menuController = null;
if (object != null) {
if (object instanceof Amenity) {
menuController = new AmenityMenuController(mapActivity, pointDescription, (Amenity) object);
} else if (object instanceof FavouritePoint) {
menuController = new FavouritePointMenuController(mapActivity, pointDescription, (FavouritePoint) object);
} else if (object instanceof SearchHistoryHelper.HistoryEntry) {
menuController = new HistoryMenuController(mapActivity, pointDescription, (SearchHistoryHelper.HistoryEntry) object);
} else if (object instanceof TargetPoint) {
menuController = new TargetPointMenuController(mapActivity, pointDescription, (TargetPoint) object);
} else if (object instanceof Recording) {
menuController = new AudioVideoNoteMenuController(mapActivity, pointDescription, (Recording) object);
} else if (object instanceof OsmPoint) {
menuController = new EditPOIMenuController(mapActivity, pointDescription, (OsmPoint) object);
} else if (object instanceof WptPt) {
menuController = new WptPtMenuController(mapActivity, pointDescription, (WptPt) object);
} else if (object instanceof DownloadMapObject) {
menuController = new MapDataMenuController(mapActivity, pointDescription, (DownloadMapObject) object);
} else if (object instanceof OpenStreetNote) {
menuController = new OsmBugMenuController(mapActivity, pointDescription, (OpenStreetNote) object);
} else if (object instanceof GpxDisplayItem) {
menuController = new GpxItemMenuController(mapActivity, pointDescription, (GpxDisplayItem) object);
} else if (object instanceof MapMarker) {
menuController = new MapMarkerMenuController(mapActivity, pointDescription, (MapMarker) object);
} else if (object instanceof TransportStopRoute) {
menuController = new TransportRouteController(mapActivity, pointDescription, (TransportStopRoute) object);
} else if (object instanceof TransportStop) {
menuController = new TransportStopController(mapActivity, pointDescription, (TransportStop) object);
} else if (object instanceof AMapPoint) {
menuController = new AMapPointMenuController(mapActivity, pointDescription, (AMapPoint) object);
} else if (object instanceof LatLon) {
if (pointDescription.isParking()) {
menuController = new ParkingPositionMenuController(mapActivity, pointDescription);
} else if (pointDescription.isMyLocation()) {
menuController = new MyLocationMenuController(mapActivity, pointDescription);
}
} else if (object instanceof RouteDataObject) {
menuController = new ImpassibleRoadsMenuController(mapActivity, pointDescription, (RouteDataObject) object);
} else if (object instanceof RenderedObject) {
menuController = new RenderedObjectMenuController(mapActivity, pointDescription, (RenderedObject) object);
} else if (object instanceof MapillaryImage) {
menuController = new MapillaryMenuController(mapActivity, pointDescription, (MapillaryImage) object);
}
}
if (menuController == null) {
menuController = new PointDescriptionMenuController(mapActivity, pointDescription);
}
menuController.menuType = menuType;
menuController.setLatLon(latLon);
menuController.onCreated();
return menuController;
}
use of net.osmand.data.TransportStop in project Osmand by osmandapp.
the class FavouritePointMenuBuilder method findTransportStop.
private TransportStop findTransportStop(String nameStringEn, double lat, double lon) {
QuadRect rect = MapUtils.calculateLatLonBbox(lat, lon, 15);
List<TransportStop> res = app.getResourceManager().searchTransportSync(rect.top, rect.left, rect.bottom, rect.right, new ResultMatcher<TransportStop>() {
@Override
public boolean publish(TransportStop object) {
return true;
}
@Override
public boolean isCancelled() {
return false;
}
});
for (TransportStop stop : res) {
String stringEn = stop.toStringEn();
if (stringEn.equals(nameStringEn)) {
return stop;
}
}
return null;
}
Aggregations