Search in sources :

Example 1 with AdditionalBillboardSymbolInstanceParameters

use of net.osmand.core.jni.MapSymbolsGroup.AdditionalBillboardSymbolInstanceParameters in project Osmand by osmandapp.

the class ContextMenuLayer method showContextMenu.

private boolean showContextMenu(PointF point, RotatedTileBox tileBox, boolean showUnknownLocation) {
    if (menu == null || mAddGpxPointBottomSheetHelper == null) {
        return false;
    }
    LatLon objectLatLon = null;
    Map<Object, IContextMenuProvider> selectedObjects = selectObjectsForContextMenu(tileBox, point, false, showUnknownLocation);
    NativeOsmandLibrary nativeLib = NativeOsmandLibrary.getLoadedLibrary();
    LatLon pointLatLon = tileBox.getLatLonFromPixel(point.x, point.y);
    OsmandApplication app = getApplication();
    IContextMenuProvider poiMenuProvider = app.getOsmandMap().getMapLayers().getPoiMapLayer();
    IContextMenuProvider gpxMenuProvider = app.getOsmandMap().getMapLayers().getGpxLayer();
    if (app.getSettings().USE_OPENGL_RENDER.get() && NativeCoreContext.isInit()) {
        MapRendererView rendererView = view.getMapRenderer();
        if (rendererView != null) {
            int delta = 20;
            PointI tl = new PointI((int) point.x - delta, (int) point.y - delta);
            PointI br = new PointI((int) point.x + delta, (int) point.y + delta);
            MapSymbolInformationList symbols = rendererView.getSymbolsIn(new AreaI(tl, br), false);
            for (int i = 0; i < symbols.size(); i++) {
                MapSymbolInformation symbolInfo = symbols.get(i);
                IBillboardMapSymbol billboardMapSymbol;
                try {
                    billboardMapSymbol = IBillboardMapSymbol.dynamic_pointer_cast(symbolInfo.getMapSymbol());
                } catch (Exception eBillboard) {
                    billboardMapSymbol = null;
                }
                if (billboardMapSymbol != null) {
                    double lat = Utilities.get31LatitudeY(billboardMapSymbol.getPosition31().getY());
                    double lon = Utilities.get31LongitudeX(billboardMapSymbol.getPosition31().getX());
                    objectLatLon = new LatLon(lat, lon);
                    AdditionalBillboardSymbolInstanceParameters billboardAdditionalParams;
                    try {
                        billboardAdditionalParams = AdditionalBillboardSymbolInstanceParameters.dynamic_pointer_cast(symbolInfo.getInstanceParameters());
                    } catch (Exception eBillboardParams) {
                        billboardAdditionalParams = null;
                    }
                    if (billboardAdditionalParams != null && billboardAdditionalParams.getOverridesPosition31()) {
                        lat = Utilities.get31LatitudeY(billboardAdditionalParams.getPosition31().getY());
                        lon = Utilities.get31LongitudeX(billboardAdditionalParams.getPosition31().getX());
                        objectLatLon = new LatLon(lat, lon);
                    }
                    Amenity amenity = null;
                    net.osmand.core.jni.Amenity jniAmenity;
                    try {
                        jniAmenity = AmenitySymbolsGroup.dynamic_cast(symbolInfo.getMapSymbol().getGroupPtr()).getAmenity();
                    } catch (Exception eAmenity) {
                        jniAmenity = null;
                    }
                    if (jniAmenity != null) {
                        List<String> names = getValues(jniAmenity.getLocalizedNames());
                        names.add(jniAmenity.getNativeName());
                        long id = jniAmenity.getId().getId().longValue() >> 7;
                        amenity = findAmenity(app, id, names, objectLatLon, AMENITY_SEARCH_RADIUS);
                    } else {
                        MapObject mapObject;
                        try {
                            mapObject = MapObjectSymbolsGroup.dynamic_cast(symbolInfo.getMapSymbol().getGroupPtr()).getMapObject();
                        } catch (Exception eMapObject) {
                            mapObject = null;
                        }
                        if (mapObject != null) {
                            ObfMapObject obfMapObject;
                            try {
                                obfMapObject = ObfMapObject.dynamic_pointer_cast(mapObject);
                            } catch (Exception eObfMapObject) {
                                obfMapObject = null;
                            }
                            if (obfMapObject != null) {
                                List<String> names = getValues(obfMapObject.getCaptionsInAllLanguages());
                                names.add(obfMapObject.getCaptionInNativeLanguage());
                                long id = obfMapObject.getId().getId().longValue() >> 7;
                                amenity = findAmenity(app, id, names, objectLatLon, AMENITY_SEARCH_RADIUS);
                            }
                        }
                    }
                    if (amenity != null && isUniqueAmenity(selectedObjects.keySet(), amenity)) {
                        selectedObjects.put(amenity, poiMenuProvider);
                    }
                }
            }
        }
    } else if (nativeLib != null) {
        MapRenderRepositories maps = app.getResourceManager().getRenderer();
        RenderingContext rc = maps.getVisibleRenderingContext();
        RenderedObject[] renderedObjects = null;
        if (rc != null && rc.zoom == tileBox.getZoom()) {
            double sinRotate = Math.sin(Math.toRadians(rc.rotate - tileBox.getRotate()));
            double cosRotate = Math.cos(Math.toRadians(rc.rotate - tileBox.getRotate()));
            float x = tileBox.getPixXFrom31((int) (rc.leftX * rc.tileDivisor), (int) (rc.topY * rc.tileDivisor));
            float y = tileBox.getPixYFrom31((int) (rc.leftX * rc.tileDivisor), (int) (rc.topY * rc.tileDivisor));
            float dx = point.x - x;
            float dy = point.y - y;
            int coordX = (int) (dx * cosRotate - dy * sinRotate);
            int coordY = (int) (dy * cosRotate + dx * sinRotate);
            renderedObjects = nativeLib.searchRenderedObjectsFromContext(rc, coordX, coordY, true);
        }
        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 renderedObject : renderedObjects) {
                String routeID = renderedObject.getRouteID();
                String fileName = renderedObject.getGpxFileName();
                String filter = routeID != null ? routeID : fileName;
                boolean isGpx = !Algorithms.isEmpty(filter);
                if (!isGpx && (renderedObject.getId() == null || !renderedObject.isVisible() || renderedObject.isDrawOnPath())) {
                    continue;
                }
                if (renderedObject.getLabelX() != 0 && renderedObject.getLabelY() != 0) {
                    double lat = MapUtils.get31LatitudeY(renderedObject.getLabelY());
                    double lon = MapUtils.get31LongitudeX(renderedObject.getLabelX());
                    renderedObject.setLabelLatLon(new LatLon(lat, lon));
                } else {
                    double cx = renderedObject.getBbox().centerX();
                    double cy = renderedObject.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);
                    renderedObject.setLabelLatLon(new LatLon(lat, lon));
                }
                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();
                }
                LatLon searchLatLon = objectLatLon != null ? objectLatLon : pointLatLon;
                if (isGpx) {
                    TravelGpx travelGpx = app.getTravelHelper().searchGpx(pointLatLon, filter, renderedObject.getTagValue("ref"));
                    if (travelGpx != null && isUniqueGpx(selectedObjects, travelGpx)) {
                        WptPt selectedPoint = new WptPt();
                        selectedPoint.lat = pointLatLon.getLatitude();
                        selectedPoint.lon = pointLatLon.getLongitude();
                        SelectedGpxPoint selectedGpxPoint = new SelectedGpxPoint(null, selectedPoint);
                        selectedObjects.put(new Pair<>(travelGpx, selectedGpxPoint), gpxMenuProvider);
                    }
                } else {
                    Amenity amenity = findAmenity(app, renderedObject.getId() >> 7, renderedObject.getOriginalNames(), searchLatLon, AMENITY_SEARCH_RADIUS);
                    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());
                        }
                        if (isUniqueAmenity(selectedObjects.keySet(), amenity)) {
                            selectedObjects.put(amenity, poiMenuProvider);
                        }
                    } else {
                        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;
        }
    }
    processTransportStops(selectedObjects);
    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 = pointLatLon;
        }
        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) {
        showContextMenuForSelectedObjects(pointLatLon, selectedObjects);
        return true;
    } else if (showUnknownLocation) {
        hideVisibleMenues();
        selectedObjectContextMenuProvider = null;
        getApplication().getMapViewTrackingUtilities().setMapLinkedToLocation(false);
        if (mInAddGpxPointMode) {
            mAddGpxPointBottomSheetHelper.setTitle("");
            view.getAnimatedDraggingThread().startMoving(pointLatLon.getLatitude(), pointLatLon.getLongitude(), view.getZoom(), true);
        } else {
            menu.show(pointLatLon, null, null);
        }
        return true;
    }
    return false;
}
Also used : ObfMapObject(net.osmand.core.jni.ObfMapObject) TravelGpx(net.osmand.plus.wikivoyage.data.TravelGpx) WptPt(net.osmand.GPXUtilities.WptPt) OsmandApplication(net.osmand.plus.OsmandApplication) MapRendererView(net.osmand.core.android.MapRendererView) PointI(net.osmand.core.jni.PointI) SelectedGpxPoint(net.osmand.plus.mapcontextmenu.controllers.SelectedGpxMenuController.SelectedGpxPoint) IBillboardMapSymbol(net.osmand.core.jni.IBillboardMapSymbol) MapRenderRepositories(net.osmand.plus.render.MapRenderRepositories) ObfMapObject(net.osmand.core.jni.ObfMapObject) MapObject(net.osmand.core.jni.MapObject) Pair(android.util.Pair) Amenity(net.osmand.data.Amenity) RenderingContext(net.osmand.RenderingContext) AdditionalBillboardSymbolInstanceParameters(net.osmand.core.jni.MapSymbolsGroup.AdditionalBillboardSymbolInstanceParameters) Paint(android.graphics.Paint) NewGpxPoint(net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint) FavouritePoint(net.osmand.data.FavouritePoint) SelectedGpxPoint(net.osmand.plus.mapcontextmenu.controllers.SelectedGpxMenuController.SelectedGpxPoint) MapSymbolInformationList(net.osmand.core.jni.MapSymbolInformationList) LatLon(net.osmand.data.LatLon) MapSymbolInformation(net.osmand.core.jni.IMapRenderer.MapSymbolInformation) RenderedObject(net.osmand.NativeLibrary.RenderedObject) AreaI(net.osmand.core.jni.AreaI) PointDescription(net.osmand.data.PointDescription) NativeOsmandLibrary(net.osmand.plus.render.NativeOsmandLibrary) ObfMapObject(net.osmand.core.jni.ObfMapObject) CallbackWithObject(net.osmand.CallbackWithObject) RenderedObject(net.osmand.NativeLibrary.RenderedObject) MapObject(net.osmand.core.jni.MapObject) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

Paint (android.graphics.Paint)1 Pair (android.util.Pair)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CallbackWithObject (net.osmand.CallbackWithObject)1 WptPt (net.osmand.GPXUtilities.WptPt)1 RenderedObject (net.osmand.NativeLibrary.RenderedObject)1 RenderingContext (net.osmand.RenderingContext)1 MapRendererView (net.osmand.core.android.MapRendererView)1 AreaI (net.osmand.core.jni.AreaI)1 IBillboardMapSymbol (net.osmand.core.jni.IBillboardMapSymbol)1 MapSymbolInformation (net.osmand.core.jni.IMapRenderer.MapSymbolInformation)1 MapObject (net.osmand.core.jni.MapObject)1 MapSymbolInformationList (net.osmand.core.jni.MapSymbolInformationList)1 AdditionalBillboardSymbolInstanceParameters (net.osmand.core.jni.MapSymbolsGroup.AdditionalBillboardSymbolInstanceParameters)1 ObfMapObject (net.osmand.core.jni.ObfMapObject)1 PointI (net.osmand.core.jni.PointI)1 Amenity (net.osmand.data.Amenity)1 FavouritePoint (net.osmand.data.FavouritePoint)1 LatLon (net.osmand.data.LatLon)1