Merge pull request #10568 from osmandapp/fix_open_on_map
Fix open on map
This commit is contained in:
commit
253d1d5edd
1 changed files with 8 additions and 7 deletions
|
@ -13,7 +13,6 @@ import androidx.fragment.app.FragmentActivity;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.GPXUtilities;
|
|
||||||
import net.osmand.GPXUtilities.GPXFile;
|
import net.osmand.GPXUtilities.GPXFile;
|
||||||
import net.osmand.GPXUtilities.WptPt;
|
import net.osmand.GPXUtilities.WptPt;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
|
@ -26,6 +25,7 @@ import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment;
|
||||||
import net.osmand.plus.wikivoyage.data.TravelArticle;
|
import net.osmand.plus.wikivoyage.data.TravelArticle;
|
||||||
import net.osmand.plus.wikivoyage.data.TravelArticle.TravelArticleIdentifier;
|
import net.osmand.plus.wikivoyage.data.TravelArticle.TravelArticleIdentifier;
|
||||||
import net.osmand.plus.wikivoyage.explore.WikivoyageExploreActivity;
|
import net.osmand.plus.wikivoyage.explore.WikivoyageExploreActivity;
|
||||||
|
import net.osmand.util.MapUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -41,6 +41,7 @@ import static net.osmand.plus.wikipedia.WikiArticleHelper.WIKI_DOMAIN;
|
||||||
public class WikivoyageWebViewClient extends WebViewClient {
|
public class WikivoyageWebViewClient extends WebViewClient {
|
||||||
|
|
||||||
private static final String TAG = WikivoyageWebViewClient.class.getSimpleName();
|
private static final String TAG = WikivoyageWebViewClient.class.getSimpleName();
|
||||||
|
public static final int ROUNDING_ERROR = 3;
|
||||||
|
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
private FragmentManager fragmentManager;
|
private FragmentManager fragmentManager;
|
||||||
|
@ -85,29 +86,29 @@ public class WikivoyageWebViewClient extends WebViewClient {
|
||||||
} else if (isWebPage) {
|
} else if (isWebPage) {
|
||||||
WikiArticleHelper.warnAboutExternalLoad(url, activity, nightMode);
|
WikiArticleHelper.warnAboutExternalLoad(url, activity, nightMode);
|
||||||
} else if (url.startsWith(PREFIX_GEO)) {
|
} else if (url.startsWith(PREFIX_GEO)) {
|
||||||
if (article != null) {
|
if (article != null && article.getGpxFile() != null) {
|
||||||
List<WptPt> points = article.getGpxFile().getPoints();
|
List<WptPt> points = article.getGpxFile().getPoints();
|
||||||
WptPt gpxPoint = null;
|
WptPt gpxPoint = null;
|
||||||
String coordinates = url.replace(PREFIX_GEO, "");
|
String coordinates = url.replace(PREFIX_GEO, "");
|
||||||
double lat;
|
double lat;
|
||||||
double lon;
|
double lon;
|
||||||
try {
|
try {
|
||||||
lat = Double.valueOf(coordinates.substring(0, coordinates.indexOf(",")));
|
lat = Double.parseDouble(coordinates.substring(0, coordinates.indexOf(",")));
|
||||||
lon = Double.valueOf(coordinates.substring(coordinates.indexOf(",") + 1,
|
lon = Double.parseDouble(coordinates.substring(coordinates.indexOf(",") + 1));
|
||||||
coordinates.length()));
|
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
Log.w(TAG, e.getMessage(), e);
|
Log.w(TAG, e.getMessage(), e);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
for (WptPt point : points) {
|
for (WptPt point : points) {
|
||||||
if (point.getLatitude() == lat && point.getLongitude() == lon) {
|
if (MapUtils.getDistance(point.getLatitude(), point.getLongitude(), lat, lon) < ROUNDING_ERROR) {
|
||||||
gpxPoint = point;
|
gpxPoint = point;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (gpxPoint != null) {
|
if (gpxPoint != null) {
|
||||||
final OsmandSettings settings = app.getSettings();
|
final OsmandSettings settings = app.getSettings();
|
||||||
settings.setMapLocationToShow(lat, lon, settings.getLastKnownMapZoom(),
|
settings.setMapLocationToShow(gpxPoint.getLatitude(), gpxPoint.getLongitude(),
|
||||||
|
settings.getLastKnownMapZoom(),
|
||||||
new PointDescription(PointDescription.POINT_TYPE_WPT, gpxPoint.name),
|
new PointDescription(PointDescription.POINT_TYPE_WPT, gpxPoint.name),
|
||||||
false,
|
false,
|
||||||
gpxPoint);
|
gpxPoint);
|
||||||
|
|
Loading…
Reference in a new issue