Skip to content

Commit

Permalink
#16632: Implemented map pisitioning to show all selected items
Browse files Browse the repository at this point in the history
  • Loading branch information
Corwin-Kh committed Jun 23, 2023
1 parent 2c267e6 commit 2cf37c9
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
24 changes: 24 additions & 0 deletions OsmAnd/src/net/osmand/plus/auto/FavoritesScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@

import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.R;
import net.osmand.plus.myplaces.favorites.FavoriteGroup;
import net.osmand.plus.utils.AndroidUtils;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.PointImageDrawable;
import net.osmand.search.core.ObjectType;
import net.osmand.search.core.SearchResult;
Expand Down Expand Up @@ -67,6 +70,7 @@ public FavoritesScreen(
public void onDestroy(@NonNull LifecycleOwner owner) {
DefaultLifecycleObserver.super.onDestroy(owner);
getApp().getOsmandMap().getMapLayers().getFavouritesLayer().setCustomMapObjects(null);
getApp().getOsmandMap().getMapView().backToLocation();
}
});
}
Expand Down Expand Up @@ -95,7 +99,22 @@ private void setupFavorites(ItemList.Builder listBuilder) {
int favoritesPointsSize = favoritesPoints.size();
List<FavouritePoint> limitedFavoritesPoints = favoritesPoints.subList(0, Math.min(favoritesPointsSize, getContentLimit() - 1));
getApp().getOsmandMap().getMapLayers().getFavouritesLayer().setCustomMapObjects(limitedFavoritesPoints);
QuadRect mapRect = new QuadRect();
for (FavouritePoint point : limitedFavoritesPoints) {
double longitude = point.getLongitude();
double latitude = point.getLatitude();
if (mapRect.left == 0.0) {
mapRect.left = longitude;
} else {
mapRect.left = Math.min(mapRect.left, longitude);
}
mapRect.right = Math.max(mapRect.right, longitude);
if (mapRect.bottom == 0.0) {
mapRect.bottom = latitude;
} else {
mapRect.bottom = Math.min(mapRect.bottom, latitude);
}
mapRect.top = Math.max(mapRect.top, latitude);
String title = point.getDisplayName(getApp());
int color = getApp().getFavoritesHelper().getColorWithCategory(point, ContextCompat.getColor(getApp(), R.color.color_favorite));
CarIcon icon = new CarIcon.Builder(IconCompat.createWithBitmap(
Expand All @@ -115,6 +134,11 @@ private void setupFavorites(ItemList.Builder listBuilder) {
CarLocation.create(point.getLatitude(), point.getLongitude())).build()).build())
.build());
}
if (mapRect.left != 0.0 && mapRect.right != 0.0 && mapRect.top != 0.0 && mapRect.bottom != 0.0) {
OsmandMapTileView mapView = getApp().getOsmandMap().getMapView();
RotatedTileBox tileBox =mapView.getCurrentRotatedTileBox().copy();
mapView.fitRectToMap(mapRect.left, mapRect.right, mapRect.top, mapRect.bottom, tileBox.getPixHeight(), tileBox.getPixHeight(), 0);
}
}

private void onClickFavorite(@NonNull FavouritePoint point) {
Expand Down
16 changes: 16 additions & 0 deletions OsmAnd/src/net/osmand/plus/auto/MapMarkersScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ import androidx.core.graphics.drawable.IconCompat
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import net.osmand.data.LatLon
import net.osmand.data.QuadRect
import net.osmand.data.RotatedTileBox
import net.osmand.plus.R
import net.osmand.plus.mapmarkers.MapMarker
import net.osmand.search.core.ObjectType
import net.osmand.search.core.SearchResult
import net.osmand.util.MapUtils
import kotlin.math.max
import kotlin.math.min

class MapMarkersScreen(
carContext: CarContext,
Expand All @@ -35,6 +39,7 @@ class MapMarkersScreen(
override fun onDestroy(owner: LifecycleOwner) {
super.onDestroy(owner)
app.osmandMap.mapLayers.mapMarkersLayer.setCustomMapObjects(null)
app.osmandMap.mapView.backToLocation()
}
})
}
Expand All @@ -46,7 +51,14 @@ class MapMarkersScreen(
app.mapMarkersHelper.mapMarkers.subList(0, markersSize.coerceAtMost(contentLimit - 1))
val location = app.settings.lastKnownMapLocation
app.osmandMap.mapLayers.mapMarkersLayer.setCustomMapObjects(markers)
val mapRect = QuadRect()
for (marker in markers) {
val longitude = marker.longitude
val latitude = marker.latitude
mapRect.left = if(mapRect.left == 0.0) longitude else min(mapRect.left, longitude)
mapRect.right = max(mapRect.right, longitude)
mapRect.bottom = if(mapRect.bottom == 0.0) latitude else min(mapRect.bottom, latitude)
mapRect.top = max(mapRect.top, latitude)
val title = marker.getName(app)
val markerColor = MapMarker.getColorId(marker.colorIndex)
val icon = CarIcon.Builder(
Expand Down Expand Up @@ -77,6 +89,10 @@ class MapMarkersScreen(
}
listBuilder.addItem(rowBuilder.build())
}
if (mapRect.left != 0.0 && mapRect.right != 0.0 && mapRect.top != 0.0 && mapRect.bottom != 0.0) {
val tb: RotatedTileBox = app.osmandMap.mapView.currentRotatedTileBox.copy()
app.osmandMap.mapView.fitRectToMap(mapRect.left, mapRect.right, mapRect.top, mapRect.bottom, tb.pixWidth, tb.pixHeight, 0)
}
val actionStripBuilder = ActionStrip.Builder()
actionStripBuilder.addAction(
Action.Builder()
Expand Down
18 changes: 17 additions & 1 deletion OsmAnd/src/net/osmand/plus/auto/POIScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.LifecycleOwner
import net.osmand.data.Amenity
import net.osmand.data.LatLon
import net.osmand.data.QuadRect
import net.osmand.data.RotatedTileBox
import net.osmand.plus.R
import net.osmand.plus.poi.PoiUIFilter
import net.osmand.plus.render.RenderingIcons
Expand All @@ -30,6 +32,8 @@ import net.osmand.search.core.SearchPhrase
import net.osmand.search.core.SearchResult
import net.osmand.util.Algorithms
import net.osmand.util.MapUtils
import kotlin.math.max
import kotlin.math.min

class POIScreen(
carContext: CarContext,
Expand All @@ -45,6 +49,7 @@ class POIScreen(
override fun onDestroy(owner: LifecycleOwner) {
super.onDestroy(owner)
app.osmandMap.mapLayers.poiMapLayer.setCustomMapObjects(null)
app.osmandMap.mapView.backToLocation()
}
})
}
Expand Down Expand Up @@ -91,13 +96,20 @@ class POIScreen(
private fun setupPOI(listBuilder: ItemList.Builder, searchResults: List<SearchResult>?) {
val location = app.settings.lastKnownMapLocation
val mapPoint = ArrayList<Amenity>()
val mapRect = QuadRect()
searchResults?.let {
val searchResultsSize = searchResults.size
val limitedSearchResults =
searchResults.subList(0, searchResultsSize.coerceAtMost(contentLimit - 1))
for (point in limitedSearchResults) {
if (point.`object` is Amenity) {
mapPoint.add(point.`object` as Amenity)
val amenity = point.`object` as Amenity
mapPoint.add(amenity)
val amenityLocation = amenity.location
mapRect.left = if(mapRect.left == 0.0) amenityLocation.longitude else min(mapRect.left, amenityLocation.longitude)
mapRect.right = max(mapRect.right, amenityLocation.longitude)
mapRect.bottom = if(mapRect.bottom == 0.0) amenityLocation.latitude else min(mapRect.bottom, amenityLocation.latitude)
mapRect.top = max(mapRect.top, amenityLocation.latitude)
}
val title = point.localeName
var groupIcon = RenderingIcons.getBigIcon(app, group.iconId)
Expand Down Expand Up @@ -129,6 +141,10 @@ class POIScreen(
.build())
}
}
if (mapRect.left != 0.0 && mapRect.right != 0.0 && mapRect.top != 0.0 && mapRect.bottom != 0.0) {
val tb: RotatedTileBox = app.osmandMap.mapView.currentRotatedTileBox.copy()
app.osmandMap.mapView.fitRectToMap(mapRect.left, mapRect.right, mapRect.top, mapRect.bottom, tb.pixWidth, tb.pixHeight, 0)
}
app.osmandMap.mapLayers.poiMapLayer.setCustomMapObjects(mapPoint)
}

Expand Down
15 changes: 15 additions & 0 deletions OsmAnd/src/net/osmand/plus/auto/TracksScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import androidx.car.app.navigation.model.PlaceListNavigationTemplate
import androidx.core.graphics.drawable.IconCompat
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import net.osmand.data.QuadRect
import net.osmand.data.RotatedTileBox
import net.osmand.gpx.GPXUtilities
import net.osmand.plus.R
import net.osmand.plus.configmap.tracks.TrackItem
Expand All @@ -22,6 +24,8 @@ import net.osmand.search.core.ObjectType
import net.osmand.search.core.SearchResult
import net.osmand.util.Algorithms
import net.osmand.util.MapUtils
import kotlin.math.max
import kotlin.math.min

class TracksScreen(
carContext: CarContext,
Expand All @@ -46,6 +50,7 @@ class TracksScreen(
super.onDestroy(owner)
loadGpxFilesThread?.interrupt()
app.osmandMap.mapLayers.gpxLayer.setCustomMapObjects(null)
app.osmandMap.mapView.backToLocation()
}
})
}
Expand Down Expand Up @@ -109,10 +114,16 @@ class TracksScreen(
val selectedGpxFiles = ArrayList<SelectedGpxFile>()
val tracks =
trackTab.trackItems.subList(0, tracksSize.coerceAtMost(contentLimit - 1))
val mapRect = QuadRect()
for (track in tracks) {
val gpxFile = loadedGpxFiles[track]
gpxFile?.let {
selectedGpxFiles.add(it)
val gpxRect: QuadRect = it.gpxFile.rect
mapRect.left = if(mapRect.left == 0.0) gpxRect.left else min(mapRect.left, gpxRect.left)
mapRect.right = max(mapRect.right, gpxRect.right)
mapRect.top = max(mapRect.top, gpxRect.top)
mapRect.bottom = if(mapRect.bottom == 0.0) gpxRect.bottom else min(mapRect.bottom, gpxRect.bottom)
}
val title = track.name
val icon = CarIcon.Builder(
Expand Down Expand Up @@ -143,6 +154,10 @@ class TracksScreen(
.setOnClickListener { onClickTrack(track) }
.build())
}
if (mapRect.left != 0.0 && mapRect.right != 0.0 && mapRect.top != 0.0 && mapRect.bottom != 0.0) {
val tb: RotatedTileBox = app.osmandMap.mapView.currentRotatedTileBox.copy()
app.osmandMap.mapView.fitRectToMap(mapRect.left, mapRect.right, mapRect.top, mapRect.bottom, tb.pixWidth, tb.pixHeight, 0)
}
app.osmandMap.mapLayers.gpxLayer.setCustomMapObjects(selectedGpxFiles)
templateBuilder.setItemList(listBuilder.build())
}
Expand Down

0 comments on commit 2cf37c9

Please sign in to comment.