Search in sources :

Example 51 with MapMarker

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

the class MapContextMenu method getMapMarker.

@Nullable
private MapMarker getMapMarker() {
    MenuController menuController = getMenuController();
    Object correspondingObj = menuController != null ? menuController.getCorrespondingMapObject() : null;
    if (correspondingObj instanceof MapMarker) {
        return (MapMarker) correspondingObj;
    }
    Object object = getObject();
    if (object instanceof MapMarker) {
        return (MapMarker) object;
    }
    return null;
}
Also used : MapMarker(net.osmand.plus.mapmarkers.MapMarker) MapDataMenuController(net.osmand.plus.mapcontextmenu.controllers.MapDataMenuController) CallbackWithObject(net.osmand.CallbackWithObject) Nullable(androidx.annotation.Nullable)

Example 52 with MapMarker

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

the class QuickSearchListItem method getIcon.

@Nullable
public static Drawable getIcon(OsmandApplication app, SearchResult searchResult) {
    if (searchResult == null || searchResult.objectType == null) {
        return null;
    }
    int iconId = -1;
    switch(searchResult.objectType) {
        case CITY:
            return getIcon(app, R.drawable.ic_action_building2);
        case VILLAGE:
            return getIcon(app, R.drawable.ic_action_village);
        case POSTCODE:
        case STREET:
            return getIcon(app, R.drawable.ic_action_street_name);
        case HOUSE:
            return getIcon(app, R.drawable.ic_action_building);
        case STREET_INTERSECTION:
            return getIcon(app, R.drawable.ic_action_intersection);
        case POI_TYPE:
            if (searchResult.object instanceof AbstractPoiType) {
                String iconName = PoiUIFilter.getPoiTypeIconName((AbstractPoiType) searchResult.object);
                if (!Algorithms.isEmpty(iconName)) {
                    iconId = RenderingIcons.getBigIconResourceId(iconName);
                }
            } else if (searchResult.object instanceof CustomSearchPoiFilter) {
                CustomSearchPoiFilter searchPoiFilter = (CustomSearchPoiFilter) searchResult.object;
                PoiUIFilter filter = app.getPoiFilters().getFilterById(searchPoiFilter.getFilterId());
                if (filter != null) {
                    iconId = getCustomFilterIconRes(filter);
                }
            }
            if (iconId > 0) {
                return getIcon(app, iconId);
            } else {
                return getIcon(app, R.drawable.ic_action_search_dark);
            }
        case POI:
            Amenity amenity = (Amenity) searchResult.object;
            String id = getAmenityIconName(amenity);
            Drawable icon = null;
            if (id != null) {
                iconId = RenderingIcons.getBigIconResourceId(id);
                if (iconId > 0) {
                    icon = getIcon(app, iconId);
                }
            }
            if (icon == null) {
                return getIcon(app, R.drawable.ic_action_search_dark);
            } else {
                return icon;
            }
        case GPX_TRACK:
            return getIcon(app, R.drawable.ic_action_polygom_dark);
        case LOCATION:
            return getIcon(app, R.drawable.ic_action_world_globe);
        case FAVORITE:
            FavouritePoint fav = (FavouritePoint) searchResult.object;
            int color = app.getFavoritesHelper().getColorWithCategory(fav, ContextCompat.getColor(app, R.color.color_favorite));
            return PointImageDrawable.getFromFavorite(app, color, false, fav);
        case FAVORITE_GROUP:
            FavoriteGroup group = (FavoriteGroup) searchResult.object;
            color = group.getColor() == 0 ? ContextCompat.getColor(app, R.color.color_favorite) : group.getColor();
            return app.getUIUtilities().getPaintedIcon(R.drawable.ic_action_favorite, color | 0xff000000);
        case REGION:
            return getIcon(app, R.drawable.ic_world_globe_dark);
        case RECENT_OBJ:
            HistoryEntry entry = (HistoryEntry) searchResult.object;
            iconId = getHistoryIconId(app, entry);
            try {
                return getIcon(app, iconId);
            } catch (Exception e) {
                return getIcon(app, SearchHistoryFragment.getItemIcon(entry.getName()));
            }
        case WPT:
            WptPt wpt = (WptPt) searchResult.object;
            return PointImageDrawable.getFromWpt(app, wpt.getColor(), false, wpt);
        case MAP_MARKER:
            MapMarker marker = (MapMarker) searchResult.object;
            if (!marker.history) {
                return MapMarkerDialogHelper.getMapMarkerIcon(app, marker.colorIndex);
            } else {
                return getIcon(app, R.drawable.ic_action_flag);
            }
        case ROUTE:
            return getIcon(app, R.drawable.ic_action_previous_route);
        case UNKNOWN_NAME_FILTER:
            break;
    }
    return null;
}
Also used : Amenity(net.osmand.data.Amenity) WptPt(net.osmand.GPXUtilities.WptPt) FavouritePoint(net.osmand.data.FavouritePoint) MapMarker(net.osmand.plus.mapmarkers.MapMarker) FavoriteGroup(net.osmand.plus.myplaces.FavoriteGroup) Drawable(android.graphics.drawable.Drawable) PointImageDrawable(net.osmand.plus.views.PointImageDrawable) AbstractPoiType(net.osmand.osm.AbstractPoiType) WptLocationPoint(net.osmand.data.WptLocationPoint) FavouritePoint(net.osmand.data.FavouritePoint) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter) HistoryEntry(net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry) CustomSearchPoiFilter(net.osmand.search.core.CustomSearchPoiFilter) Nullable(androidx.annotation.Nullable)

Example 53 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 54 with MapMarker

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

the class SearchScreen method reloadHistoryInternal.

private void reloadHistoryInternal() {
    if (!destroyed) {
        OsmandApplication app = getApp();
        try {
            List<SearchResult> recentResults = new ArrayList<>();
            // Home / work
            /* Disable since points exists at favorites screen
				FavouritesDbHelper favorites = app.getFavorites();
				FavouritePoint homePoint = favorites.getSpecialPoint(FavouritePoint.SpecialPointType.HOME);
				FavouritePoint workPoint = favorites.getSpecialPoint(FavouritePoint.SpecialPointType.WORK);
				if (homePoint != null) {
					SearchResult result = new SearchResult();
					result.location = new LatLon(homePoint.getLatitude(), homePoint.getLongitude());
					result.objectType = ObjectType.FAVORITE;
					result.object = homePoint;
					result.localeName = homePoint.getAddress();
					recentResults.add(result);
				}
				if (workPoint != null) {
					SearchResult result = new SearchResult();
					result.location = new LatLon(workPoint.getLatitude(), workPoint.getLongitude());
					result.objectType = ObjectType.FAVORITE;
					result.object = workPoint;
					result.localeName = workPoint.getAddress();
					recentResults.add(result);
				}
				*/
            // Previous route card
            TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
            TargetPoint startPoint = targetPointsHelper.getPointToStartBackup();
            boolean myLocation = false;
            if (startPoint == null) {
                myLocation = true;
                startPoint = targetPointsHelper.getMyLocationToStart();
            }
            TargetPoint destinationPoint = targetPointsHelper.getPointToNavigateBackup();
            if (startPoint != null && destinationPoint != null) {
                StringBuilder startText = new StringBuilder(myLocation ? app.getText(R.string.my_location) : "");
                String startDescr = getPointName(startPoint);
                if (!Algorithms.isEmpty(startDescr)) {
                    if (startText.length() > 0) {
                        startText.append(" — ");
                    }
                    startText.append(startDescr);
                }
                String destDescr = getPointName(destinationPoint);
                SearchResult result = new SearchResult();
                result.location = new LatLon(destinationPoint.getLatitude(), destinationPoint.getLongitude());
                result.objectType = ObjectType.ROUTE;
                result.object = destinationPoint;
                result.localeName = destDescr;
                result.relatedObject = startPoint;
                result.localeRelatedObjectName = startText.toString();
                recentResults.add(result);
            }
            // Map markers
            List<MapMarker> mapMarkers = app.getMapMarkersHelper().getMapMarkers();
            int mapMarkersCount = 0;
            for (MapMarker marker : mapMarkers) {
                SearchResult result = new SearchResult();
                result.location = new LatLon(marker.getLatitude(), marker.getLongitude());
                result.objectType = ObjectType.MAP_MARKER;
                result.object = marker;
                result.localeName = marker.getName(app);
                recentResults.add(result);
                mapMarkersCount++;
                if (mapMarkersCount >= MAP_MARKERS_LIMIT) {
                    break;
                }
            }
            // History
            SearchResultCollection res = getSearchUICore().shallowSearch(SearchHistoryAPI.class, "", null, false, false);
            if (res != null) {
                recentResults.addAll(res.getCurrentSearchResults());
            }
            this.recentResults = recentResults;
            if (!searchHelper.isSearching() && Algorithms.isEmpty(searchHelper.getSearchQuery())) {
                showRecents();
                invalidate();
            }
        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
            app.showToastMessage(e.getMessage());
        }
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) MapMarker(net.osmand.plus.mapmarkers.MapMarker) ArrayList(java.util.ArrayList) SearchResult(net.osmand.search.core.SearchResult) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) LatLon(net.osmand.data.LatLon) SearchResultCollection(net.osmand.search.SearchUICore.SearchResultCollection) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper)

Example 55 with MapMarker

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

the class MapMarkerEditorFragment method save.

private void save(boolean needDismiss) {
    String name = nameEdit.getText().toString().trim();
    if (Algorithms.isBlank(name)) {
        nameEdit.setError(getString(R.string.wrong_input));
    } else {
        OsmandApplication app = getMyApplication();
        if (editor != null && app != null) {
            MapMarker marker = editor.getMarker();
            marker.setOriginalPointDescription(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, name));
            app.getMapMarkersHelper().updateMapMarker(marker, true);
        }
        if (needDismiss) {
            dismiss(true);
        }
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) MapMarker(net.osmand.plus.mapmarkers.MapMarker) PointDescription(net.osmand.data.PointDescription)

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