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;
}
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);
}
}
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;
}
Aggregations