Search in sources :

Example 11 with MapMarker

use of net.osmand.plus.mapmarkers.MapMarker in project Osmand by osmandapp.

the class QuickSearchListItem method getTypeName.

public static String getTypeName(OsmandApplication app, SearchResult searchResult) {
    switch(searchResult.objectType) {
        case CITY:
            City city = (City) searchResult.object;
            return getCityTypeStr(app, city.getType());
        case POSTCODE:
            return app.getString(R.string.postcode);
        case VILLAGE:
            city = (City) searchResult.object;
            if (!Algorithms.isEmpty(searchResult.localeRelatedObjectName)) {
                if (searchResult.distRelatedObjectName > 0) {
                    return getCityTypeStr(app, city.getType()) + " • " + OsmAndFormatter.getFormattedDistance((float) searchResult.distRelatedObjectName, app) + " " + app.getString(R.string.shared_string_from) + " " + searchResult.localeRelatedObjectName;
                } else {
                    return getCityTypeStr(app, city.getType()) + ", " + searchResult.localeRelatedObjectName;
                }
            } else {
                return getCityTypeStr(app, city.getType());
            }
        case STREET:
            StringBuilder streetBuilder = new StringBuilder();
            if (searchResult.localeName.endsWith(")")) {
                int i = searchResult.localeName.indexOf('(');
                if (i > 0) {
                    streetBuilder.append(searchResult.localeName.substring(i + 1, searchResult.localeName.length() - 1));
                }
            }
            if (!Algorithms.isEmpty(searchResult.localeRelatedObjectName)) {
                if (streetBuilder.length() > 0) {
                    streetBuilder.append(", ");
                }
                streetBuilder.append(searchResult.localeRelatedObjectName);
            }
            return streetBuilder.toString();
        case HOUSE:
            if (searchResult.relatedObject != null) {
                Street relatedStreet = (Street) searchResult.relatedObject;
                if (relatedStreet.getCity() != null) {
                    return searchResult.localeRelatedObjectName + ", " + relatedStreet.getCity().getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
                } else {
                    return searchResult.localeRelatedObjectName;
                }
            }
            return "";
        case STREET_INTERSECTION:
            Street street = (Street) searchResult.object;
            if (street.getCity() != null) {
                return street.getCity().getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
            }
            return "";
        case POI_TYPE:
            String res = "";
            if (searchResult.object instanceof AbstractPoiType) {
                AbstractPoiType abstractPoiType = (AbstractPoiType) searchResult.object;
                if (abstractPoiType instanceof PoiCategory) {
                    res = "";
                } else if (abstractPoiType instanceof PoiFilter) {
                    PoiFilter poiFilter = (PoiFilter) abstractPoiType;
                    res = poiFilter.getPoiCategory() != null ? poiFilter.getPoiCategory().getTranslation() : "";
                } else if (abstractPoiType instanceof PoiType) {
                    PoiType poiType = (PoiType) abstractPoiType;
                    res = poiType.getParentType() != null ? poiType.getParentType().getTranslation() : null;
                    if (res == null) {
                        res = poiType.getCategory() != null ? poiType.getCategory().getTranslation() : null;
                    }
                    if (res == null) {
                        res = "";
                    }
                } else {
                    res = "";
                }
            } else if (searchResult.object instanceof CustomSearchPoiFilter) {
                res = ((CustomSearchPoiFilter) searchResult.object).getName();
            }
            return res;
        case POI:
            Amenity amenity = (Amenity) searchResult.object;
            PoiCategory pc = amenity.getType();
            PoiType pt = pc.getPoiTypeByKeyName(amenity.getSubType());
            String typeStr = amenity.getSubType();
            if (pt != null) {
                typeStr = pt.getTranslation();
            } else if (typeStr != null) {
                typeStr = Algorithms.capitalizeFirstLetterAndLowercase(typeStr.replace('_', ' '));
            }
            return typeStr;
        case LOCATION:
            LatLon latLon = searchResult.location;
            if (latLon != null && searchResult.localeRelatedObjectName == null) {
                String locationCountry = app.getRegions().getCountryName(latLon);
                searchResult.localeRelatedObjectName = locationCountry == null ? "" : locationCountry;
            }
            return searchResult.localeRelatedObjectName;
        case FAVORITE:
            FavouritePoint fav = (FavouritePoint) searchResult.object;
            return fav.getCategory().length() == 0 ? app.getString(R.string.shared_string_favorites) : fav.getCategoryDisplayName(app);
        case FAVORITE_GROUP:
            return app.getString(R.string.shared_string_my_favorites);
        case REGION:
            BinaryMapIndexReader binaryMapIndexReader = (BinaryMapIndexReader) searchResult.object;
            System.out.println(binaryMapIndexReader.getFile().getAbsolutePath() + " " + binaryMapIndexReader.getCountryName());
            break;
        case RECENT_OBJ:
            HistoryEntry entry = (HistoryEntry) searchResult.object;
            boolean hasTypeInDescription = !Algorithms.isEmpty(entry.getName().getTypeName());
            if (hasTypeInDescription) {
                return entry.getName().getTypeName();
            } else {
                return "";
            }
        case WPT:
            StringBuilder sb = new StringBuilder();
            GPXFile gpx = (GPXFile) searchResult.relatedObject;
            if (!Algorithms.isEmpty(searchResult.localeRelatedObjectName)) {
                sb.append(searchResult.localeRelatedObjectName);
            }
            if (gpx != null && !Algorithms.isEmpty(gpx.path)) {
                if (sb.length() > 0) {
                    sb.append(", ");
                }
                sb.append(new File(gpx.path).getName());
            }
            return sb.toString();
        case MAP_MARKER:
            MapMarker marker = (MapMarker) searchResult.object;
            String desc = OsmAndFormatter.getFormattedDate(app, marker.creationDate);
            String markerGroupName = marker.groupName;
            if (markerGroupName != null) {
                if (markerGroupName.isEmpty()) {
                    markerGroupName = app.getString(R.string.shared_string_favorites);
                }
                desc += " • " + markerGroupName;
            }
            return desc;
        case ROUTE:
            return "";
        case UNKNOWN_NAME_FILTER:
            break;
    }
    return searchResult.objectType.name();
}
Also used : Amenity(net.osmand.data.Amenity) PoiFilter(net.osmand.osm.PoiFilter) CustomSearchPoiFilter(net.osmand.search.core.CustomSearchPoiFilter) FavouritePoint(net.osmand.data.FavouritePoint) MapMarker(net.osmand.plus.mapmarkers.MapMarker) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) City(net.osmand.data.City) AbstractPoiType(net.osmand.osm.AbstractPoiType) WptLocationPoint(net.osmand.data.WptLocationPoint) FavouritePoint(net.osmand.data.FavouritePoint) LatLon(net.osmand.data.LatLon) PoiCategory(net.osmand.osm.PoiCategory) Street(net.osmand.data.Street) HistoryEntry(net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry) CustomSearchPoiFilter(net.osmand.search.core.CustomSearchPoiFilter) GPXFile(net.osmand.GPXUtilities.GPXFile) GPXFile(net.osmand.GPXUtilities.GPXFile) File(java.io.File)

Example 12 with MapMarker

use of net.osmand.plus.mapmarkers.MapMarker in project Osmand by osmandapp.

the class FavouritesLayer method onDraw.

@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
    if (contextMenuLayer.getMoveableObject() instanceof FavouritePoint) {
        FavouritePoint objectInMotion = (FavouritePoint) contextMenuLayer.getMoveableObject();
        PointF pf = contextMenuLayer.getMovableCenterPoint(tileBox);
        MapMarker mapMarker = mapMarkersHelper.getMapMarker(objectInMotion);
        float textScale = getTextScale();
        drawBigPoint(canvas, objectInMotion, pf.x, pf.y, mapMarker, textScale);
    }
}
Also used : FavouritePoint(net.osmand.data.FavouritePoint) MapMarker(net.osmand.plus.mapmarkers.MapMarker) PointF(android.graphics.PointF)

Example 13 with MapMarker

use of net.osmand.plus.mapmarkers.MapMarker in project Osmand by osmandapp.

the class FavouritesLayer method onPrepareBufferImage.

@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
    cache.clear();
    if (this.settings.SHOW_FAVORITES.get() && favouritesHelper.isFavoritesLoaded()) {
        if (tileBox.getZoom() >= START_ZOOM) {
            float textScale = getTextScale();
            float iconSize = getIconSize(view.getApplication());
            QuadTree<QuadRect> boundIntersections = initBoundIntersections(tileBox);
            // request to load
            final QuadRect latLonBounds = tileBox.getLatLonBounds();
            List<LatLon> fullObjectsLatLon = new ArrayList<>();
            List<LatLon> smallObjectsLatLon = new ArrayList<>();
            for (FavoriteGroup group : favouritesHelper.getFavoriteGroups()) {
                List<Pair<FavouritePoint, MapMarker>> fullObjects = new ArrayList<>();
                boolean synced = isSynced(group);
                for (FavouritePoint favoritePoint : group.getPoints()) {
                    double lat = favoritePoint.getLatitude();
                    double lon = favoritePoint.getLongitude();
                    if (favoritePoint.isVisible() && favoritePoint != contextMenuLayer.getMoveableObject() && lat >= latLonBounds.bottom && lat <= latLonBounds.top && lon >= latLonBounds.left && lon <= latLonBounds.right) {
                        MapMarker marker = null;
                        if (synced) {
                            marker = mapMarkersHelper.getMapMarker(favoritePoint);
                            if (marker == null || marker.history && !view.getSettings().KEEP_PASSED_MARKERS_ON_MAP.get()) {
                                continue;
                            }
                        }
                        cache.add(favoritePoint);
                        float x = tileBox.getPixXFromLatLon(lat, lon);
                        float y = tileBox.getPixYFromLatLon(lat, lon);
                        if (intersects(boundIntersections, x, y, iconSize, iconSize)) {
                            @ColorInt int color;
                            if (marker != null && marker.history) {
                                color = grayColor;
                            } else {
                                color = favouritesHelper.getColorWithCategory(favoritePoint, defaultColor);
                            }
                            PointImageDrawable pointImageDrawable = PointImageDrawable.getFromFavorite(view.getContext(), color, true, favoritePoint);
                            pointImageDrawable.drawSmallPoint(canvas, x, y, textScale);
                            smallObjectsLatLon.add(new LatLon(lat, lon));
                        } else {
                            fullObjects.add(new Pair<>(favoritePoint, marker));
                            fullObjectsLatLon.add(new LatLon(lat, lon));
                        }
                    }
                }
                for (Pair<FavouritePoint, MapMarker> pair : fullObjects) {
                    FavouritePoint favoritePoint = pair.first;
                    float x = tileBox.getPixXFromLatLon(favoritePoint.getLatitude(), favoritePoint.getLongitude());
                    float y = tileBox.getPixYFromLatLon(favoritePoint.getLatitude(), favoritePoint.getLongitude());
                    drawBigPoint(canvas, favoritePoint, x, y, pair.second, textScale);
                }
            }
            this.fullObjectsLatLon = fullObjectsLatLon;
            this.smallObjectsLatLon = smallObjectsLatLon;
        }
    }
    if (isTextVisible()) {
        textLayer.putData(this, cache);
    }
}
Also used : FavouritePoint(net.osmand.data.FavouritePoint) MapMarker(net.osmand.plus.mapmarkers.MapMarker) FavoriteGroup(net.osmand.plus.myplaces.FavoriteGroup) ArrayList(java.util.ArrayList) QuadRect(net.osmand.data.QuadRect) PointImageDrawable(net.osmand.plus.views.PointImageDrawable) FavouritePoint(net.osmand.data.FavouritePoint) LatLon(net.osmand.data.LatLon) ColorInt(androidx.annotation.ColorInt) Pair(android.util.Pair)

Example 14 with MapMarker

use of net.osmand.plus.mapmarkers.MapMarker in project Osmand by osmandapp.

the class MapContextMenu method init.

public boolean init(@NonNull LatLon latLon, @Nullable PointDescription pointDescription, @Nullable Object object, boolean update, boolean restorePrevious) {
    MapActivity mapActivity = getMapActivity();
    if (mapActivity == null) {
        return false;
    }
    OsmandApplication app = mapActivity.getMyApplication();
    Object thisObject = getObject();
    if (!update && isVisible()) {
        if (thisObject == null || !thisObject.equals(object)) {
            hide();
        } else {
            return false;
        }
    }
    setSelectedObject(object);
    if (pointDescription == null) {
        this.pointDescription = new PointDescription(latLon.getLatitude(), latLon.getLongitude());
    } else {
        this.pointDescription = pointDescription;
    }
    MenuController menuController = getMenuController();
    boolean needAcquireMenuController = menuController == null || appModeChanged || !update || thisObject == null && object != null || thisObject != null && object == null || (thisObject != null && !thisObject.getClass().equals(object.getClass()));
    this.latLon = latLon;
    this.object = object;
    active = true;
    appModeChanged = false;
    if (needAcquireMenuController) {
        if (menuController != null) {
            menuController.setMapContextMenu(null);
        }
        if (!acquireMenuController(restorePrevious)) {
            active = false;
            clearSelectedObject(object);
            return false;
        }
        menuController = getMenuController();
    } else {
        menuController.update(pointDescription, object);
    }
    initTitle();
    if (menuController != null) {
        menuController.clearPlainMenuItems();
        menuController.addPlainMenuItems(typeStr, getPointDescription(), getLatLon());
    }
    if (mapPosition != 0) {
        mapActivity.getMapView().setMapPosition(0);
    }
    mapActivity.refreshMap();
    if (object instanceof MapMarker) {
        app.getMapMarkersHelper().addListener(this);
    } else if (object instanceof TargetPoint) {
        app.getTargetPointsHelper().addPointListener(this);
    }
    return true;
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) MapMarker(net.osmand.plus.mapmarkers.MapMarker) PointDescription(net.osmand.data.PointDescription) MapDataMenuController(net.osmand.plus.mapcontextmenu.controllers.MapDataMenuController) CallbackWithObject(net.osmand.CallbackWithObject) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) MapActivity(net.osmand.plus.activities.MapActivity)

Example 15 with MapMarker

use of net.osmand.plus.mapmarkers.MapMarker in project Osmand by osmandapp.

the class MapContextMenu method buttonWaypointPressed.

public void buttonWaypointPressed() {
    MapActivity mapActivity = getMapActivity();
    if (mapActivity != null) {
        MapMarker marker = getMapMarker();
        if (marker != null) {
            MapMarkerEditor mapMarkerEditor = getMapMarkerEditor();
            if (mapMarkerEditor != null) {
                mapMarkerEditor.edit(marker);
            }
        } else {
            String mapObjectName = null;
            Object object = getObject();
            if (object instanceof Amenity) {
                Amenity amenity = (Amenity) object;
                mapObjectName = amenity.getName() + "_" + amenity.getType().getKeyName();
            }
            LatLon latLon = getLatLon();
            mapActivity.getMapActions().addMapMarker(latLon.getLatitude(), latLon.getLongitude(), getPointDescriptionForMarker(), mapObjectName);
            close();
        }
    }
}
Also used : Amenity(net.osmand.data.Amenity) LatLon(net.osmand.data.LatLon) MapMarker(net.osmand.plus.mapmarkers.MapMarker) CallbackWithObject(net.osmand.CallbackWithObject) MapMarkerEditor(net.osmand.plus.mapcontextmenu.editors.MapMarkerEditor) MapActivity(net.osmand.plus.activities.MapActivity)

Aggregations

MapMarker (net.osmand.plus.mapmarkers.MapMarker)106 LatLon (net.osmand.data.LatLon)42 ArrayList (java.util.ArrayList)30 OsmandApplication (net.osmand.plus.OsmandApplication)26 TargetPoint (net.osmand.plus.helpers.TargetPointsHelper.TargetPoint)24 MapMarkersHelper (net.osmand.plus.mapmarkers.MapMarkersHelper)20 GPXFile (net.osmand.GPXUtilities.GPXFile)18 PointDescription (net.osmand.data.PointDescription)18 File (java.io.File)16 FavouritePoint (net.osmand.data.FavouritePoint)16 MapMarkersGroup (net.osmand.plus.mapmarkers.MapMarkersGroup)16 View (android.view.View)14 MapActivity (net.osmand.plus.activities.MapActivity)14 Paint (android.graphics.Paint)12 NonNull (androidx.annotation.NonNull)12 Nullable (androidx.annotation.Nullable)12 RecyclerView (androidx.recyclerview.widget.RecyclerView)12 WptPt (net.osmand.GPXUtilities.WptPt)12 Location (net.osmand.Location)12 Amenity (net.osmand.data.Amenity)12