Search in sources :

Example 6 with PointDescription

use of net.osmand.data.PointDescription 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 7 with PointDescription

use of net.osmand.data.PointDescription in project Osmand by osmandapp.

the class ContextMenuLayer method createGpxPoint.

public void createGpxPoint() {
    if (!mInAddGpxPointMode) {
        throw new IllegalStateException("Not in add gpx point mode");
    }
    RotatedTileBox tileBox = activity.getMapView().getCurrentRotatedTileBox();
    PointF newMarkerPosition = getMovableCenterPoint(tileBox);
    final LatLon ll = tileBox.getLatLonFromPixel(newMarkerPosition.x, newMarkerPosition.y);
    applyingMarkerLatLon = ll;
    Object obj = getMoveableObject();
    cancelApplyingNewMarkerPosition = false;
    mAddGpxPointBottomSheetHelper.enterApplyPositionMode();
    applyMovedObject(obj, ll, new ApplyMovedObjectCallback() {

        @Override
        public void onApplyMovedObject(boolean success, @Nullable Object newObject) {
            mAddGpxPointBottomSheetHelper.exitApplyPositionMode();
            if (success && !cancelApplyingNewMarkerPosition) {
                mAddGpxPointBottomSheetHelper.hide();
                quitAddGpxPoint();
                PointDescription pointDescription = null;
                if (selectedObjectContextMenuProvider != null) {
                    pointDescription = selectedObjectContextMenuProvider.getObjectName(newObject);
                }
                menu.show(ll, pointDescription, newObject);
                view.refreshMap();
            }
            selectedObjectContextMenuProvider = null;
            applyingMarkerLatLon = null;
        }

        @Override
        public boolean isCancelled() {
            return cancelApplyingNewMarkerPosition;
        }
    });
}
Also used : LatLon(net.osmand.data.LatLon) RotatedTileBox(net.osmand.data.RotatedTileBox) PointF(android.graphics.PointF) PointDescription(net.osmand.data.PointDescription) CallbackWithObject(net.osmand.CallbackWithObject) RenderedObject(net.osmand.NativeLibrary.RenderedObject)

Example 8 with PointDescription

use of net.osmand.data.PointDescription in project Osmand by osmandapp.

the class MapActivityActions method setFirstMapMarkerAsTarget.

public void setFirstMapMarkerAsTarget() {
    if (getMyApplication().getMapMarkersHelper().getMapMarkers().size() > 0) {
        MapMarkersHelper.MapMarker marker = getMyApplication().getMapMarkersHelper().getMapMarkers().get(0);
        PointDescription pointDescription = marker.getOriginalPointDescription();
        if (pointDescription.isLocation() && pointDescription.getName().equals(PointDescription.getAddressNotFoundStr(mapActivity))) {
            pointDescription = new PointDescription(PointDescription.POINT_TYPE_LOCATION, "");
        }
        TargetPointsHelper targets = getMyApplication().getTargetPointsHelper();
        targets.navigateToPoint(new LatLon(marker.getLatitude(), marker.getLongitude()), true, targets.getIntermediatePoints().size() + 1, pointDescription);
    }
}
Also used : LatLon(net.osmand.data.LatLon) MapMarkersHelper(net.osmand.plus.MapMarkersHelper) PointDescription(net.osmand.data.PointDescription) TargetPointsHelper(net.osmand.plus.TargetPointsHelper)

Example 9 with PointDescription

use of net.osmand.data.PointDescription in project Osmand by osmandapp.

the class MapActivityActions method onPrepareDialog.

@Override
public void onPrepareDialog(int id, Dialog dialog) {
    Bundle args = dialogBundle;
    switch(id) {
        case DIALOG_ADD_FAVORITE:
            FavoriteDialogs.prepareAddFavouriteDialog(mapActivity, dialog, args, args.getDouble(KEY_LATITUDE), args.getDouble(KEY_LONGITUDE), new PointDescription(PointDescription.POINT_TYPE_FAVORITE, args.getString(KEY_NAME)));
            break;
        case DIALOG_ADD_WAYPOINT:
            EditText v = (EditText) dialog.getWindow().findViewById(android.R.id.edit);
            v.setPadding(5, 0, 5, 0);
            if (args.getString(KEY_NAME) != null) {
                v.setText(args.getString(KEY_NAME));
                v.selectAll();
            } else {
                v.setText("");
            }
            break;
    }
}
Also used : EditText(android.widget.EditText) Bundle(android.os.Bundle) PointDescription(net.osmand.data.PointDescription)

Example 10 with PointDescription

use of net.osmand.data.PointDescription in project Osmand by osmandapp.

the class FavoritesSearchFragment method showOnMap.

public void showOnMap(final FavouritePoint point) {
    getMyApplication().getSettings().FAVORITES_TAB.set(FavoritesActivity.FAV_TAB);
    final OsmandSettings settings = getMyApplication().getSettings();
    LatLon location = new LatLon(point.getLatitude(), point.getLongitude());
    settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), settings.getLastKnownMapZoom(), new PointDescription(PointDescription.POINT_TYPE_FAVORITE, point.getName()), true, // $NON-NLS-1$
    point);
    MapActivity.launchMapActivityMoveToTop(getActivity());
}
Also used : LatLon(net.osmand.data.LatLon) PointDescription(net.osmand.data.PointDescription) OsmandSettings(net.osmand.plus.OsmandSettings)

Aggregations

PointDescription (net.osmand.data.PointDescription)72 LatLon (net.osmand.data.LatLon)44 View (android.view.View)16 ImageView (android.widget.ImageView)13 TextView (android.widget.TextView)13 ArrayList (java.util.ArrayList)13 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)13 FavouritePoint (net.osmand.data.FavouritePoint)12 TargetPointsHelper (net.osmand.plus.TargetPointsHelper)11 OsmandApplication (net.osmand.plus.OsmandApplication)10 OsmandSettings (net.osmand.plus.OsmandSettings)10 MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)8 Amenity (net.osmand.data.Amenity)7 WptPt (net.osmand.plus.GPXUtilities.WptPt)7 RoutingHelper (net.osmand.plus.routing.RoutingHelper)7 Intent (android.content.Intent)6 Paint (android.graphics.Paint)6 LinearLayout (android.widget.LinearLayout)6 Location (net.osmand.Location)6 DialogInterface (android.content.DialogInterface)5