Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nearby plases tmp #21955

Merged
merged 17 commits into from
Feb 22, 2025
12 changes: 8 additions & 4 deletions OsmAnd-java/src/main/java/net/osmand/wiki/WikiCoreHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.osmand.data.Amenity;
import net.osmand.data.QuadRect;
import net.osmand.osm.io.NetworkUtils;
import net.osmand.shared.data.KQuadRect;
import net.osmand.util.Algorithms;

import org.apache.commons.logging.Log;
Expand Down Expand Up @@ -46,12 +47,12 @@ public class WikiCoreHelper {
private static final List<String> IMAGE_EXTENSIONS = new ArrayList<>(Arrays.asList(".jpeg", ".jpg", ".png", ".gif"));


public static List<OsmandApiFeatureData> getExploreImageList(QuadRect mapRect, int zoom, String lang) {
public static List<OsmandApiFeatureData> getExploreImageList(KQuadRect mapRect, int zoom, String lang) {
List<OsmandApiFeatureData> wikiImages = new ArrayList<>();
StringBuilder url = new StringBuilder();
String baseApiActionUrl = OSMAND_SEARCH_ENDPOINT + GET_WIKI_DATA_ACTION;
String northWest = String.format(Locale.US, "%f,%f", mapRect.top, mapRect.left);
String southEast = String.format(Locale.US, "%f,%f", mapRect.bottom, mapRect.right);
String northWest = String.format(Locale.US, "%f,%f", mapRect.getTop(), mapRect.getLeft());
String southEast = String.format(Locale.US, "%f,%f", mapRect.getBottom(), mapRect.getRight());
url.append(baseApiActionUrl);
try {
url.append(String.format(Locale.US, "northWest=%s", URLEncoder.encode(northWest, "UTF-8")));
Expand All @@ -62,11 +63,12 @@ public static List<OsmandApiFeatureData> getExploreImageList(QuadRect mapRect, i
url.append("&");
url.append(String.format(Locale.US, "lang=%s", lang));
url.append("&");
url.append(String.format(Locale.US, "filters=%s", "tourism%2Cleisure%2Centertainment"));
url.append(String.format(Locale.US, "filters="));

} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
LOG.debug("Download images " + url.toString());
getNearbyImagesOsmAndAPIRequest(url.toString(), wikiImages);
return wikiImages;
}
Expand Down Expand Up @@ -336,6 +338,8 @@ public static class WikiDataProperties {
private String wikiLang;
public String wikiDesc;
public Long osmid;

public Double elo;
private String osmtype;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ class KQuadRect {
return contains(box.left, box.top, box.right, box.bottom)
}

fun contains(point: KLatLon): Boolean {
return point.longitude in left..right && point.latitude in bottom..top
}

companion object {
fun intersects(a: KQuadRect, b: KQuadRect): Boolean {
return kotlin.math.min(a.left, a.right) <= kotlin.math.max(b.left, b.right)
Expand Down Expand Up @@ -109,6 +113,24 @@ class KQuadRect {
return left == 0.0 && right == 0.0 && top == 0.0 && bottom == 0.0
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is KQuadRect) return false

return left == other.left &&
right == other.right &&
top == other.top &&
bottom == other.bottom
}

override fun hashCode(): Int {
var result = left.hashCode()
result = 31 * result + right.hashCode()
result = 31 * result + top.hashCode()
result = 31 * result + bottom.hashCode()
return result
}

override fun toString(): String {
return "[${left.toFloat()},${top.toFloat()} - ${right.toFloat()},${bottom.toFloat()}]"
}
Expand Down
2 changes: 2 additions & 0 deletions OsmAnd/res/layout/search_nearby_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
android:maxLines="1"
android:ellipsize="end"
tools:text="Monument" />


</LinearLayout>

</LinearLayout>
29 changes: 28 additions & 1 deletion OsmAnd/res/layout/search_nearby_item_vertical.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
android:id="@+id/item_icon"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_gravity="center_vertical|top"
android:layout_gravity="center_vertical"
android:layout_marginEnd="6dp" />

<TextView
Expand All @@ -58,6 +58,33 @@
android:textColor="?android:textColorSecondary"
android:textSize="14sp"
tools:text="Monument" />

<LinearLayout
android:id="@+id/compass_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom|right"
android:orientation="horizontal">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/direction"
android:layout_width="@dimen/directionIconSize"
android:layout_height="@dimen/directionIconSize"
android:layout_marginTop="1sp"
android:layout_gravity="center_vertical"/>

<TextView
android:id="@+id/distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="2dp"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_sub_text_size"
tools:text="100500 km"
android:layout_marginStart="2dp" />

</LinearLayout>
</LinearLayout>

</LinearLayout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
import java.io.Serializable;


public class NearbyPlacePoint implements Serializable, LocationPoint {
public class ExploreTopPlacePoint implements Serializable, LocationPoint {

private static final long serialVersionUID = 829654300829771466L;

public static final BackgroundType DEFAULT_BACKGROUND_TYPE = BackgroundType.CIRCLE;
private static final double DEFAULT_ELO = 900;
private final long id;
private final String photoTitle;
private final String wikiTitle;
Expand All @@ -29,10 +30,12 @@ public class NearbyPlacePoint implements Serializable, LocationPoint {
private final String imageStubUrl;
private final double latitude;
private final double longitude;

private final double elo;
@Nullable
private Bitmap imageBitmap;

public NearbyPlacePoint(OsmandApiFeatureData featureData) {
public ExploreTopPlacePoint(OsmandApiFeatureData featureData) {
this.id = featureData.properties.osmid;
WikiImage wikiIMage = WikiCoreHelper.getImageData(featureData.properties.photoTitle);
this.iconUrl = wikiIMage == null ? "" : wikiIMage.getImageIconUrl();
Expand All @@ -44,6 +47,7 @@ public NearbyPlacePoint(OsmandApiFeatureData featureData) {
this.poitype = featureData.properties.poitype;
this.wikiTitle = featureData.properties.wikiTitle;
this.wikiDesc = featureData.properties.wikiDesc;
this.elo = featureData.properties.elo != null ? featureData.properties.elo : DEFAULT_ELO;
}

public long getId() {
Expand Down Expand Up @@ -85,6 +89,10 @@ public PointDescription getPointDescription(@NonNull Context ctx) {
return new PointDescription(PointDescription.POINT_TYPE_NEARBY_PLACE, wikiDesc);
}

public double getElo() {
return elo;
}

public double getLatitude() {
return latitude;
}
Expand Down Expand Up @@ -136,7 +144,7 @@ public boolean equals(Object o) {
return false;
}

NearbyPlacePoint point = (NearbyPlacePoint) o;
ExploreTopPlacePoint point = (ExploreTopPlacePoint) o;
if (!Algorithms.stringsEqual(photoTitle, point.photoTitle)) {
return false;
}
Expand Down
5 changes: 2 additions & 3 deletions OsmAnd/src/net/osmand/plus/AppInitializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import net.osmand.plus.configmap.tracks.TrackSortModesHelper;
import net.osmand.plus.download.local.LocalIndexHelper;
import net.osmand.plus.download.local.LocalItem;
import net.osmand.plus.exploreplaces.ExplorePlacesProviderJava;
import net.osmand.plus.feedback.AnalyticsHelper;
import net.osmand.plus.feedback.FeedbackHelper;
import net.osmand.plus.helpers.*;
Expand All @@ -48,7 +49,6 @@
import net.osmand.plus.mapmarkers.MapMarkersDbHelper;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.myplaces.favorites.FavouritesHelper;
import net.osmand.plus.nearbyplaces.NearbyPlacesHelper;
import net.osmand.plus.notifications.NotificationHelper;
import net.osmand.plus.onlinerouting.OnlineRoutingHelper;
import net.osmand.plus.plugins.PluginsHelper;
Expand Down Expand Up @@ -337,9 +337,8 @@ public void onCreateApplication() {
app.routeLayersHelper = startupInit(new RouteLayersHelper(app), RouteLayersHelper.class);
app.model3dHelper = startupInit(new Model3dHelper(app), Model3dHelper.class);
app.trackSortModesHelper = startupInit(new TrackSortModesHelper(app), TrackSortModesHelper.class);

app.explorePlacesProvider = startupInit(new ExplorePlacesProviderJava(app), ExplorePlacesProviderJava.class);
initOpeningHoursParser();
NearbyPlacesHelper.INSTANCE.init(app);
}

private void initOpeningHoursParser() {
Expand Down
7 changes: 7 additions & 0 deletions OsmAnd/src/net/osmand/plus/OsmandApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
import net.osmand.plus.download.DownloadIndexesThread;
import net.osmand.plus.download.DownloadService;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.exploreplaces.ExplorePlacesProvider;
import net.osmand.plus.exploreplaces.ExplorePlacesProviderJava;
import net.osmand.plus.feedback.AnalyticsHelper;
import net.osmand.plus.feedback.FeedbackHelper;
import net.osmand.plus.feedback.RateUsHelper;
Expand Down Expand Up @@ -208,6 +210,7 @@ public class OsmandApplication extends MultiDexApplication {
RouteLayersHelper routeLayersHelper;
Model3dHelper model3dHelper;
TrackSortModesHelper trackSortModesHelper;
ExplorePlacesProviderJava explorePlacesProvider;

private final Map<String, Builder> customRoutingConfigs = new ConcurrentHashMap<>();
private File externalStorageDirectory;
Expand Down Expand Up @@ -618,6 +621,10 @@ public AverageSpeedComputer getAverageSpeedComputer() {
return averageSpeedComputer;
}

public ExplorePlacesProvider getExplorePlacesProvider() {
return explorePlacesProvider;
}

@NonNull
public AverageGlideComputer getAverageGlideComputer() {
return averageGlideComputer;
Expand Down
4 changes: 2 additions & 2 deletions OsmAnd/src/net/osmand/plus/activities/MapActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
import net.osmand.plus.measurementtool.GpxData;
import net.osmand.plus.measurementtool.MeasurementEditingContext;
import net.osmand.plus.measurementtool.MeasurementToolFragment;
import net.osmand.plus.nearbyplaces.NearbyPlacesFragment;
import net.osmand.plus.exploreplaces.ExplorePlacesFragment;
import net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine;
import net.osmand.plus.plugins.OsmandPlugin;
import net.osmand.plus.plugins.PluginsHelper;
Expand Down Expand Up @@ -518,7 +518,7 @@ public void onBackPressed() {
if (backStackEntryCount == 0 && launchPrevActivityIntent()) {
return;
}
NearbyPlacesFragment nearbyPlacesFragment = fragmentsHelper.getNearbyPlacesFragment();
ExplorePlacesFragment nearbyPlacesFragment = fragmentsHelper.getNearbyPlacesFragment();
if(nearbyPlacesFragment != null && nearbyPlacesFragment.onBackPress()) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.osmand.plus.nearbyplaces
package net.osmand.plus.exploreplaces

import android.os.Bundle
import android.view.LayoutInflater
Expand All @@ -11,21 +11,21 @@ import androidx.fragment.app.FragmentManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import net.osmand.PlatformUtil
import net.osmand.data.NearbyPlacePoint
import net.osmand.data.ExploreTopPlacePoint
import net.osmand.data.QuadRect
import net.osmand.plus.R
import net.osmand.plus.activities.MapActivity
import net.osmand.plus.base.BaseOsmAndFragment
import net.osmand.plus.helpers.AndroidUiHelper
import net.osmand.plus.nearbyplaces.NearbyPlacesHelper.getDataCollection
import net.osmand.plus.nearbyplaces.NearbyPlacesHelper.showPointInContextMenu
import net.osmand.plus.search.NearbyPlacesAdapter
import net.osmand.plus.utils.AndroidUtils
import net.osmand.plus.utils.ColorUtilities
import org.apache.commons.logging.Log

class NearbyPlacesFragment : BaseOsmAndFragment(), NearbyPlacesAdapter.NearbyItemClickListener {
class ExplorePlacesFragment : BaseOsmAndFragment(), NearbyPlacesAdapter.NearbyItemClickListener {
private lateinit var visiblePlacesRect: QuadRect
private val log: Log = PlatformUtil.getLog(
NearbyPlacesFragment::class.java)
ExplorePlacesFragment::class.java)

private lateinit var verticalNearbyAdapter: NearbyPlacesAdapter

Expand All @@ -44,6 +44,13 @@ class NearbyPlacesFragment : BaseOsmAndFragment(), NearbyPlacesAdapter.NearbyIte
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
AndroidUtils.addStatusBarPadding21v(requireActivity(), view)
arguments?.let {
val left = it.getDouble("left")
val right = it.getDouble("right")
val top = it.getDouble("top")
val bottom = it.getDouble("bottom")
visiblePlacesRect = QuadRect(left, top, right, bottom) // Create QuadRect
}
setupShowAll(view)
setupToolBar(view)
setupVerticalNearbyList(view)
Expand All @@ -57,25 +64,27 @@ class NearbyPlacesFragment : BaseOsmAndFragment(), NearbyPlacesAdapter.NearbyIte
mapActivity?.contextMenu?.hideMenus()
} else {
activity?.supportFragmentManager?.beginTransaction()
?.show(this@NearbyPlacesFragment)
?.show(this@ExplorePlacesFragment)
?.commit()
}
return true
} else {
val quickSearchFragment = mapActivity?.fragmentsHelper?.quickSearchDialogFragment
quickSearchFragment?.show()
activity?.supportFragmentManager?.beginTransaction()
?.remove(this@NearbyPlacesFragment)
?.remove(this@ExplorePlacesFragment)
?.commit()
return true
}
}

private fun setupShowAll(view: View) {

view.findViewById<ImageView>(R.id.location_icon)
.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_marker_dark, nightMode))

view.findViewById<View>(R.id.show_on_map).setOnClickListener {
app.osmandMap.mapLayers.nearbyPlacesLayer.setCustomMapObjects(getDataCollection())
app.osmandMap.mapLayers.explorePlacesLayer.enableLayer(true)
hide()
}
}
Expand Down Expand Up @@ -104,7 +113,7 @@ class NearbyPlacesFragment : BaseOsmAndFragment(), NearbyPlacesAdapter.NearbyIte

private fun setupVerticalNearbyList(view: View) {
val verticalNearbyList = view.findViewById<RecyclerView>(R.id.vertical_nearby_list)
val nearbyData = NearbyPlacesHelper.getDataCollection()
val nearbyData = app.explorePlacesProvider.getDataCollection(visiblePlacesRect)
verticalNearbyAdapter = NearbyPlacesAdapter(app, nearbyData, true, this)
verticalNearbyList.layoutManager = LinearLayoutManager(requireContext())
verticalNearbyList.adapter = verticalNearbyAdapter
Expand All @@ -122,19 +131,27 @@ class NearbyPlacesFragment : BaseOsmAndFragment(), NearbyPlacesAdapter.NearbyIte
}

companion object {
val TAG: String = NearbyPlacesFragment::class.java.simpleName
fun showInstance(manager: FragmentManager) {
val TAG: String = ExplorePlacesFragment::class.java.simpleName
fun showInstance(manager: FragmentManager, visiblePlacesRect: QuadRect) {
if (AndroidUtils.isFragmentCanBeAdded(manager, TAG)) {
val fragment = ExplorePlacesFragment()
val bundle = Bundle()
bundle.putDouble("left", visiblePlacesRect.left)
bundle.putDouble("right", visiblePlacesRect.right)
bundle.putDouble("top", visiblePlacesRect.top)
bundle.putDouble("bottom", visiblePlacesRect.bottom)
fragment.arguments = bundle
manager.beginTransaction()
.replace(R.id.fragmentContainer, NearbyPlacesFragment(), TAG)
.replace(R.id.fragmentContainer, fragment, TAG)
.commitAllowingStateLoss()
}
}

}

override fun onNearbyItemClicked(item: NearbyPlacePoint) {
override fun onNearbyItemClicked(item: ExploreTopPlacePoint) {
mapActivity?.let {
showPointInContextMenu(it, item)
app.explorePlacesProvider.showPointInContextMenu(it, item)
hide()
}
}
Expand Down
Loading
Loading