Search in sources :

Example 1 with RenderedObject

use of net.osmand.NativeLibrary.RenderedObject in project Osmand by osmandapp.

the class ContextMenuLayer method showContextMenu.

private boolean showContextMenu(PointF point, RotatedTileBox tileBox, boolean showUnknownLocation) {
    LatLon objectLatLon = null;
    Map<Object, IContextMenuProvider> selectedObjects = selectObjectsForContextMenu(tileBox, point, false, showUnknownLocation);
    NativeOsmandLibrary nativeLib = NativeOsmandLibrary.getLoadedLibrary();
    if (nativeLib != null) {
        MapRenderRepositories maps = activity.getMyApplication().getResourceManager().getRenderer();
        RenderingContext rc = maps.getVisibleRenderingContext();
        RenderedObject[] renderedObjects = null;
        if (rc != null && rc.zoom == tileBox.getZoom()) {
            double lat = MapUtils.get31LatitudeY((int) (rc.topY * rc.tileDivisor));
            double lon = MapUtils.get31LongitudeX((int) (rc.leftX * rc.tileDivisor));
            float x = tileBox.getPixXFromLatLon(lat, lon);
            float y = tileBox.getPixYFromLatLon(lat, lon);
            renderedObjects = nativeLib.searchRenderedObjectsFromContext(rc, (int) (point.x - x), (int) (point.y - y));
        }
        if (renderedObjects != null) {
            int TILE_SIZE = 256;
            double cosRotateTileSize = Math.cos(Math.toRadians(rc.rotate)) * TILE_SIZE;
            double sinRotateTileSize = Math.sin(Math.toRadians(rc.rotate)) * TILE_SIZE;
            for (RenderedObject r : renderedObjects) {
                double cx = r.getBbox().centerX();
                double cy = r.getBbox().centerY();
                double dTileX = (cx * cosRotateTileSize + cy * sinRotateTileSize) / (TILE_SIZE * TILE_SIZE);
                double dTileY = (cy * cosRotateTileSize - cx * sinRotateTileSize) / (TILE_SIZE * TILE_SIZE);
                int x31 = (int) ((dTileX + rc.leftX) * rc.tileDivisor);
                int y31 = (int) ((dTileY + rc.topY) * rc.tileDivisor);
                double lat = MapUtils.get31LatitudeY(y31);
                double lon = MapUtils.get31LongitudeX(x31);
                r.setLabelLatLon(new LatLon(lat, lon));
            }
            IContextMenuProvider poiMenuProvider = activity.getMapLayers().getPoiMapLayer();
            for (RenderedObject renderedObject : renderedObjects) {
                if (renderedObject.getX() != null && renderedObject.getX().size() == 1 && renderedObject.getY() != null && renderedObject.getY().size() == 1) {
                    objectLatLon = new LatLon(MapUtils.get31LatitudeY(renderedObject.getY().get(0)), MapUtils.get31LongitudeX(renderedObject.getX().get(0)));
                } else if (renderedObject.getLabelLatLon() != null) {
                    objectLatLon = renderedObject.getLabelLatLon();
                }
                if (renderedObject.getId() != null) {
                    List<String> names = new ArrayList<>();
                    if (!Algorithms.isEmpty(renderedObject.getName())) {
                        names.add(renderedObject.getName());
                    }
                    for (Entry<String, String> entry : renderedObject.getTags().entrySet()) {
                        if (entry.getKey().startsWith("name:") && !entry.getValue().equals("")) {
                            names.add(entry.getValue());
                        }
                        if (entry.getKey().equals("name") && !entry.getValue().equals("")) {
                            names.add(entry.getValue());
                        }
                    }
                    LatLon searchLatLon = objectLatLon;
                    if (searchLatLon == null) {
                        searchLatLon = tileBox.getLatLonFromPixel(point.x, point.y);
                    }
                    Amenity amenity = findAmenity(activity.getMyApplication(), renderedObject.getId() >> 7, names, searchLatLon, 50);
                    if (amenity != null) {
                        if (renderedObject.getX() != null && renderedObject.getX().size() > 1 && renderedObject.getY() != null && renderedObject.getY().size() > 1) {
                            amenity.getX().addAll(renderedObject.getX());
                            amenity.getY().addAll(renderedObject.getY());
                        }
                        boolean exists = false;
                        for (Object o : selectedObjects.keySet()) {
                            if (o instanceof Amenity && ((Amenity) o).compareTo(amenity) == 0) {
                                exists = true;
                                break;
                            }
                        }
                        if (!exists) {
                            selectedObjects.put(amenity, poiMenuProvider);
                        }
                        continue;
                    }
                    selectedObjects.put(renderedObject, null);
                }
            }
        }
    }
    for (Map.Entry<Object, IContextMenuProvider> entry : selectedObjects.entrySet()) {
        IContextMenuProvider provider = entry.getValue();
        if (provider != null && provider.runExclusiveAction(entry.getKey(), showUnknownLocation)) {
            return true;
        }
    }
    if (selectedObjects.size() == 1) {
        Object selectedObj = selectedObjects.keySet().iterator().next();
        LatLon latLon = objectLatLon;
        PointDescription pointDescription = null;
        final IContextMenuProvider provider = selectedObjects.get(selectedObj);
        if (provider != null) {
            if (latLon == null) {
                latLon = provider.getObjectLocation(selectedObj);
            }
            pointDescription = provider.getObjectName(selectedObj);
        }
        if (latLon == null) {
            latLon = getLatLon(point, tileBox);
        }
        if (mInAddGpxPointMode) {
            String title = pointDescription == null ? "" : pointDescription.getName();
            mAddGpxPointBottomSheetHelper.setTitle(title);
            view.getAnimatedDraggingThread().startMoving(latLon.getLatitude(), latLon.getLongitude(), view.getZoom(), true);
        } else {
            showContextMenu(latLon, pointDescription, selectedObj, provider);
        }
        return true;
    } else if (selectedObjects.size() > 1) {
        selectedObjectContextMenuProvider = null;
        showContextMenuForSelectedObjects(getLatLon(point, tileBox), selectedObjects);
        return true;
    } else if (showUnknownLocation) {
        hideVisibleMenues();
        selectedObjectContextMenuProvider = null;
        LatLon latLon = getLatLon(point, tileBox);
        activity.getMapViewTrackingUtilities().setMapLinkedToLocation(false);
        if (mInAddGpxPointMode) {
            mAddGpxPointBottomSheetHelper.setTitle("");
            view.getAnimatedDraggingThread().startMoving(latLon.getLatitude(), latLon.getLongitude(), view.getZoom(), true);
        } else {
            menu.show(latLon, null, null);
        }
        return true;
    }
    return false;
}
Also used : RenderingContext(net.osmand.RenderingContext) Amenity(net.osmand.data.Amenity) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) NewGpxPoint(net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint) Paint(android.graphics.Paint) LatLon(net.osmand.data.LatLon) RenderedObject(net.osmand.NativeLibrary.RenderedObject) PointDescription(net.osmand.data.PointDescription) NativeOsmandLibrary(net.osmand.plus.render.NativeOsmandLibrary) MapRenderRepositories(net.osmand.plus.render.MapRenderRepositories) CallbackWithObject(net.osmand.CallbackWithObject) RenderedObject(net.osmand.NativeLibrary.RenderedObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with RenderedObject

use of net.osmand.NativeLibrary.RenderedObject in project Osmand by osmandapp.

the class ContextMenuLayer method onDraw.

@Override
public void onDraw(Canvas canvas, RotatedTileBox box, DrawSettings nightMode) {
    if (selectedObject != null) {
        TIntArrayList x = null;
        TIntArrayList y = null;
        if (selectedObject instanceof Amenity) {
            Amenity a = (Amenity) selectedObject;
            x = a.getX();
            y = a.getY();
        } else if (selectedObject instanceof RenderedObject) {
            RenderedObject r = (RenderedObject) selectedObject;
            x = r.getX();
            y = r.getY();
        }
        if (x != null && y != null && x.size() > 2) {
            double lat = MapUtils.get31LatitudeY(y.get(0));
            double lon = MapUtils.get31LongitudeX(x.get(0));
            int px, py, prevX, prevY;
            prevX = (int) box.getPixXFromLatLon(lat, lon);
            prevY = (int) box.getPixYFromLatLon(lat, lon);
            for (int i = 1; i < x.size(); i++) {
                lat = MapUtils.get31LatitudeY(y.get(i));
                lon = MapUtils.get31LongitudeX(x.get(i));
                px = (int) box.getPixXFromLatLon(lat, lon);
                py = (int) box.getPixYFromLatLon(lat, lon);
                canvas.drawLine(prevX, prevY, px, py, outlinePaint);
                prevX = px;
                prevY = py;
            }
        }
    }
    for (LatLon latLon : pressedLatLonSmall) {
        int x = (int) box.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
        int y = (int) box.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
        canvas.drawBitmap(pressedBitmapSmall, x - pressedBitmapSmall.getWidth() / 2, y - pressedBitmapSmall.getHeight() / 2, paint);
    }
    for (LatLon latLon : pressedLatLonFull) {
        int x = (int) box.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
        int y = (int) box.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
        canvas.drawBitmap(pressedBitmap, x - pressedBitmap.getWidth() / 2, y - pressedBitmap.getHeight() / 2, paint);
    }
    if (mapQuickActionLayer != null && mapQuickActionLayer.isInMovingMarkerMode())
        return;
    if (mInChangeMarkerPositionMode) {
        if (menu.getObject() == null) {
            canvas.translate(box.getPixWidth() / 2 - contextMarker.getWidth() / 2, box.getPixHeight() / 2 - contextMarker.getHeight());
            contextMarker.draw(canvas);
        }
        mMoveMarkerBottomSheetHelper.onDraw(box);
    } else if (mInAddGpxPointMode) {
        canvas.translate(box.getPixWidth() / 2 - contextMarker.getWidth() / 2, box.getPixHeight() / 2 - contextMarker.getHeight());
        contextMarker.draw(canvas);
        mAddGpxPointBottomSheetHelper.onDraw(box);
    } else if (menu.isActive()) {
        LatLon latLon = menu.getLatLon();
        int x = (int) box.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
        int y = (int) box.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
        canvas.translate(x - contextMarker.getWidth() / 2, y - contextMarker.getHeight());
        contextMarker.draw(canvas);
    }
}
Also used : Amenity(net.osmand.data.Amenity) RenderedObject(net.osmand.NativeLibrary.RenderedObject) LatLon(net.osmand.data.LatLon) TIntArrayList(gnu.trove.list.array.TIntArrayList) NewGpxPoint(net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint) Paint(android.graphics.Paint)

Example 3 with RenderedObject

use of net.osmand.NativeLibrary.RenderedObject 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)

Aggregations

RenderedObject (net.osmand.NativeLibrary.RenderedObject)3 Amenity (net.osmand.data.Amenity)3 LatLon (net.osmand.data.LatLon)3 Paint (android.graphics.Paint)2 TIntArrayList (gnu.trove.list.array.TIntArrayList)2 NewGpxPoint (net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CallbackWithObject (net.osmand.CallbackWithObject)1 RenderingContext (net.osmand.RenderingContext)1 AMapPoint (net.osmand.aidl.maplayer.point.AMapPoint)1 RouteDataObject (net.osmand.binary.RouteDataObject)1 FavouritePoint (net.osmand.data.FavouritePoint)1 PointDescription (net.osmand.data.PointDescription)1 TransportStop (net.osmand.data.TransportStop)1 WptPt (net.osmand.plus.GPXUtilities.WptPt)1 GpxDisplayItem (net.osmand.plus.GpxSelectionHelper.GpxDisplayItem)1 MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)1 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)1