Search in sources :

Example 1 with TransportStop

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();
}
Also used : TransportIndex(net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex) TransportStop(net.osmand.data.TransportStop)

Example 2 with TransportStop

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);
            }
        }
    }
}
Also used : TransportStopType(net.osmand.plus.transport.TransportStopType) Node(net.osmand.osm.edit.Node) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) QuadRect(net.osmand.data.QuadRect) Paint(android.graphics.Paint) Way(net.osmand.osm.edit.Way) TIntArrayList(gnu.trove.list.array.TIntArrayList) Bitmap(android.graphics.Bitmap) TransportStop(net.osmand.data.TransportStop)

Example 3 with TransportStop

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;
        }
    };
}
Also used : Path(android.graphics.Path) RotatedTileBox(net.osmand.data.RotatedTileBox) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Paint(android.graphics.Paint) ResultMatcher(net.osmand.ResultMatcher) DisplayMetrics(android.util.DisplayMetrics) QuadRect(net.osmand.data.QuadRect) WindowManager(android.view.WindowManager) Comparator(java.util.Comparator) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TransportStop(net.osmand.data.TransportStop)

Example 4 with TransportStop

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;
}
Also used : TargetPointMenuController(net.osmand.plus.mapcontextmenu.controllers.TargetPointMenuController) WptPt(net.osmand.plus.GPXUtilities.WptPt) HistoryMenuController(net.osmand.plus.mapcontextmenu.controllers.HistoryMenuController) TransportStopController(net.osmand.plus.mapcontextmenu.controllers.TransportStopController) FavouritePoint(net.osmand.data.FavouritePoint) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) MapillaryImage(net.osmand.plus.mapillary.MapillaryImage) ParkingPositionMenuController(net.osmand.plus.parkingpoint.ParkingPositionMenuController) GpxDisplayItem(net.osmand.plus.GpxSelectionHelper.GpxDisplayItem) GpxItemMenuController(net.osmand.plus.mapcontextmenu.controllers.GpxItemMenuController) MapDataMenuController(net.osmand.plus.mapcontextmenu.controllers.MapDataMenuController) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) RenderedObjectMenuController(net.osmand.plus.mapcontextmenu.controllers.RenderedObjectMenuController) ImpassibleRoadsMenuController(net.osmand.plus.mapcontextmenu.controllers.ImpassibleRoadsMenuController) EditPOIMenuController(net.osmand.plus.osmedit.EditPOIMenuController) TransportStopRoute(net.osmand.plus.transport.TransportStopRoute) MapMarkerMenuController(net.osmand.plus.mapcontextmenu.controllers.MapMarkerMenuController) PointDescriptionMenuController(net.osmand.plus.mapcontextmenu.controllers.PointDescriptionMenuController) AMapPointMenuController(net.osmand.plus.mapcontextmenu.controllers.AMapPointMenuController) TransportStop(net.osmand.data.TransportStop) Amenity(net.osmand.data.Amenity) FavouritePointMenuController(net.osmand.plus.mapcontextmenu.controllers.FavouritePointMenuController) AudioVideoNoteMenuController(net.osmand.plus.audionotes.AudioVideoNoteMenuController) OsmBugMenuController(net.osmand.plus.osmedit.OsmBugMenuController) OsmPoint(net.osmand.plus.osmedit.OsmPoint) TransportRouteController(net.osmand.plus.mapcontextmenu.controllers.TransportRouteController) AMapPoint(net.osmand.aidl.maplayer.point.AMapPoint) AmenityMenuController(net.osmand.plus.mapcontextmenu.controllers.AmenityMenuController) DownloadMapObject(net.osmand.plus.views.DownloadedRegionsLayer.DownloadMapObject) MyLocationMenuController(net.osmand.plus.mapcontextmenu.controllers.MyLocationMenuController) RenderedObjectMenuController(net.osmand.plus.mapcontextmenu.controllers.RenderedObjectMenuController) PointDescriptionMenuController(net.osmand.plus.mapcontextmenu.controllers.PointDescriptionMenuController) MapMarkerMenuController(net.osmand.plus.mapcontextmenu.controllers.MapMarkerMenuController) AMapPointMenuController(net.osmand.plus.mapcontextmenu.controllers.AMapPointMenuController) OsmBugMenuController(net.osmand.plus.osmedit.OsmBugMenuController) WptPtMenuController(net.osmand.plus.mapcontextmenu.controllers.WptPtMenuController) MapillaryMenuController(net.osmand.plus.mapillary.MapillaryMenuController) GpxItemMenuController(net.osmand.plus.mapcontextmenu.controllers.GpxItemMenuController) HistoryMenuController(net.osmand.plus.mapcontextmenu.controllers.HistoryMenuController) ParkingPositionMenuController(net.osmand.plus.parkingpoint.ParkingPositionMenuController) MapDataMenuController(net.osmand.plus.mapcontextmenu.controllers.MapDataMenuController) TargetPointMenuController(net.osmand.plus.mapcontextmenu.controllers.TargetPointMenuController) AudioVideoNoteMenuController(net.osmand.plus.audionotes.AudioVideoNoteMenuController) AmenityMenuController(net.osmand.plus.mapcontextmenu.controllers.AmenityMenuController) ImpassibleRoadsMenuController(net.osmand.plus.mapcontextmenu.controllers.ImpassibleRoadsMenuController) EditPOIMenuController(net.osmand.plus.osmedit.EditPOIMenuController) FavouritePointMenuController(net.osmand.plus.mapcontextmenu.controllers.FavouritePointMenuController) MyLocationMenuController(net.osmand.plus.mapcontextmenu.controllers.MyLocationMenuController) LatLon(net.osmand.data.LatLon) RenderedObject(net.osmand.NativeLibrary.RenderedObject) OpenStreetNote(net.osmand.plus.osmedit.OsmBugsLayer.OpenStreetNote) RouteDataObject(net.osmand.binary.RouteDataObject) Recording(net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording) WptPtMenuController(net.osmand.plus.mapcontextmenu.controllers.WptPtMenuController) MapillaryMenuController(net.osmand.plus.mapillary.MapillaryMenuController)

Example 5 with TransportStop

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;
}
Also used : TransportStop(net.osmand.data.TransportStop) QuadRect(net.osmand.data.QuadRect)

Aggregations

TransportStop (net.osmand.data.TransportStop)22 ArrayList (java.util.ArrayList)8 QuadRect (net.osmand.data.QuadRect)5 Way (net.osmand.osm.edit.Way)5 LinkedHashMap (java.util.LinkedHashMap)4 Paint (android.graphics.Paint)3 TIntArrayList (gnu.trove.list.array.TIntArrayList)3 Node (net.osmand.osm.edit.Node)3 TransportStopRoute (net.osmand.plus.transport.TransportStopRoute)3 TransportIndex (net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex)2 RotatedTileBox (net.osmand.data.RotatedTileBox)2 TransportRoute (net.osmand.data.TransportRoute)2 Relation (net.osmand.osm.edit.Relation)2 RelationMember (net.osmand.osm.edit.Relation.RelationMember)2 Rect (rtree.Rect)2 Bitmap (android.graphics.Bitmap)1 Path (android.graphics.Path)1 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)1 DisplayMetrics (android.util.DisplayMetrics)1 View (android.view.View)1