-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Implementation of ClickableWay for solitary ways (piste / dirtbike / mtb) #21714
Merged
Merged
Changes from 25 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
933bcfc
Add skel classes for proto of ClickableWay feature
RZR-UA aee346d
Support ClickableWay for v1, polish isClickableWay
RZR-UA 20ea52a
Split V1/V2 methods and implement calcSearchRadius
RZR-UA 1ce52ec
Add skel of GpxFile with activity, name, tags
RZR-UA 51db28b
Merge branch 'master' into rzr-select-way
RZR-UA 2981f13
Implement public Algorithms.sanitizeFileName()
RZR-UA fb6e58c
Implement save/open GpxFile, refresh TODO list
RZR-UA e376691
Merge branch 'master' into rzr-select-way
RZR-UA 4a301a7
Fix awkward "X (X)" when name == ref (rendering)
RZR-UA ef1731f
Implement gpxColors by difficulty/scale tags
RZR-UA 9923629
Add isUniqueClickableWay(), refactor previous code
RZR-UA 56a9dc2
Merge branch 'master' into rzr-select-way
RZR-UA 9eefc8e
Draft ClickableWayReaderTask async task, refactor
RZR-UA c56c4a1
Merge branch 'master' into rzr-select-way
RZR-UA 9d10303
Avoid useless error log
RZR-UA 285209c
Simplify/refactor ClickableWay structure
RZR-UA 338c133
Migrate to OsmAnd-shared in NetworkRouteSelector
RZR-UA c93de76
Refactor naming of ClickableWay classes
RZR-UA 8a7cea9
Draft HeightDataLoader for ClickableWay (backend)
RZR-UA f7231de
Merge branch 'master' into rzr-select-way
RZR-UA 51e0216
Merge branch 'master' into rzr-select-way
RZR-UA 3f66cc9
Apply loadHeightDataAsWaypoints to clickableWay
RZR-UA 15ac702
Fix potential NPE in readHeightData()
RZR-UA 2591ab2
Merge branch 'master' into rzr-select-way
RZR-UA 066c86b
Merge branch 'master' into rzr-select-way
RZR-UA a70018f
Merge branch 'master' into rzr-select-way
RZR-UA ca2c92f
Refactor (annotations, naming, consts)
RZR-UA 8fd86b4
Overload V1/V2 methods, simplify code
RZR-UA f64e3aa
Cancel obf read with InterfaceCancellableCallback
RZR-UA 383174e
Refactor isDerivedGpxSelected block
RZR-UA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
150 changes: 150 additions & 0 deletions
150
OsmAnd-java/src/main/java/net/osmand/binary/HeightDataLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
package net.osmand.binary; | ||
|
||
import static net.osmand.router.RouteResultPreparation.SHIFT_ID; | ||
|
||
import net.osmand.PlatformUtil; | ||
import net.osmand.ResultMatcher; | ||
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion; | ||
import net.osmand.data.QuadRect; | ||
import net.osmand.shared.gpx.primitives.WptPt; | ||
import net.osmand.util.MapUtils; | ||
|
||
import org.apache.commons.logging.Log; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class HeightDataLoader { | ||
public static final int ZOOM_TO_LOAD_TILES = 15; | ||
public static final int ZOOM_TO_LOAD_TILES_SHIFT_L = ZOOM_TO_LOAD_TILES + 1; | ||
public static final int ZOOM_TO_LOAD_TILES_SHIFT_R = 31 - ZOOM_TO_LOAD_TILES; | ||
|
||
private final static Log log = PlatformUtil.getLog(HeightDataLoader.class); | ||
private final Map<RouteSubregion, List<RouteDataObject>> loadedSubregions = new HashMap<>(); | ||
private final Map<BinaryMapIndexReader, List<RouteSubregion>> readers = new LinkedHashMap<>(); | ||
|
||
public HeightDataLoader(BinaryMapIndexReader[] readers) { | ||
for (BinaryMapIndexReader r : readers) { | ||
List<RouteSubregion> subregions = new ArrayList<>(); | ||
for (BinaryMapRouteReaderAdapter.RouteRegion rInd : r.getRoutingIndexes()) { | ||
List<RouteSubregion> subregs = rInd.getSubregions(); | ||
// create a copy to avoid leaks to the original structure | ||
for (RouteSubregion rs : subregs) { | ||
subregions.add(new RouteSubregion(rs)); | ||
} | ||
} | ||
this.readers.put(r, subregions); | ||
} | ||
} | ||
|
||
public List<WptPt> loadHeightDataAsWaypoints(long osmId, QuadRect bbox31) { | ||
Map<Long, RouteDataObject> results = new HashMap<>(); | ||
ResultMatcher<RouteDataObject> matcher = new ResultMatcher<>() { | ||
@Override | ||
public boolean publish(RouteDataObject routeDataObject) { | ||
return routeDataObject != null && routeDataObject.getId() >> SHIFT_ID == osmId; | ||
} | ||
|
||
@Override | ||
public boolean isCancelled() { | ||
return results.containsKey(osmId); // fast up search | ||
} | ||
}; | ||
|
||
try { | ||
loadRouteDataObjects(bbox31, results, matcher); | ||
} catch (IOException e) { | ||
log.error(e); | ||
} | ||
|
||
RouteDataObject found = results.get(osmId); | ||
if (found != null && found.getPointsLength() > 0) { | ||
List<WptPt> waypoints = new ArrayList<>(); | ||
float[] heightArray = found.calculateHeightArray(); | ||
for (int i = 0; i < found.getPointsLength(); i++) { | ||
WptPt point = new WptPt(); | ||
point.setLat(MapUtils.get31LatitudeY(found.getPoint31YTile(i))); | ||
point.setLon(MapUtils.get31LongitudeX(found.getPoint31XTile(i))); | ||
if (heightArray != null && heightArray.length > i * 2 + 1) { | ||
point.setEle(heightArray[i * 2 + 1]); | ||
} | ||
waypoints.add(point); | ||
} | ||
return waypoints; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
private boolean loadRouteDataObjects(QuadRect bbox31, | ||
Map<Long, RouteDataObject> results, | ||
ResultMatcher<RouteDataObject> matcher) throws IOException { | ||
int loaded = 0; | ||
int left = (int) bbox31.left >> ZOOM_TO_LOAD_TILES_SHIFT_R; | ||
int top = (int) bbox31.top >> ZOOM_TO_LOAD_TILES_SHIFT_R; | ||
int right = (int) bbox31.right >> ZOOM_TO_LOAD_TILES_SHIFT_R; | ||
int bottom = (int) bbox31.bottom >> ZOOM_TO_LOAD_TILES_SHIFT_R; | ||
for (int x = left; x <= right; x++) { | ||
for (int y = top; y <= bottom; y++) { | ||
if (matcher != null && matcher.isCancelled()) { | ||
return loaded > 0; | ||
} | ||
loaded += loadRouteDataObjects(x, y, results, matcher); | ||
} | ||
} | ||
return loaded > 0; | ||
} | ||
|
||
private int loadRouteDataObjects(int x, int y, | ||
Map<Long, RouteDataObject> results, | ||
ResultMatcher<RouteDataObject> matcher) throws IOException { | ||
int loaded = 0; | ||
HashSet<Long> deletedIds = new HashSet<>(); | ||
Map<Long, BinaryMapRouteReaderAdapter.RouteRegion> usedIds = new HashMap<>(); | ||
BinaryMapIndexReader.SearchRequest<RouteDataObject> req = BinaryMapIndexReader.buildSearchRouteRequest( | ||
x << ZOOM_TO_LOAD_TILES_SHIFT_L, (x + 1) << ZOOM_TO_LOAD_TILES_SHIFT_L, | ||
y << ZOOM_TO_LOAD_TILES_SHIFT_L, (y + 1) << ZOOM_TO_LOAD_TILES_SHIFT_L, null); | ||
for (Map.Entry<BinaryMapIndexReader, List<RouteSubregion>> readerSubregions : readers.entrySet()) { | ||
req.clearSearchResults(); | ||
BinaryMapIndexReader reader = readerSubregions.getKey(); | ||
synchronized (reader) { | ||
List<RouteSubregion> routeSubregions = readerSubregions.getValue(); | ||
List<RouteSubregion> subregions = reader.searchRouteIndexTree(req, routeSubregions); | ||
for (RouteSubregion sub : subregions) { | ||
List<RouteDataObject> objects = loadedSubregions.get(sub); | ||
if (objects == null) { | ||
objects = reader.loadRouteIndexData(sub); | ||
loadedSubregions.put(sub, objects); | ||
} | ||
for (RouteDataObject obj : objects) { | ||
if (matcher != null && matcher.isCancelled()) { | ||
return loaded; | ||
} | ||
if (matcher == null || matcher.publish(obj)) { | ||
if (deletedIds.contains(obj.id)) { | ||
// live-updates, osmand_change=delete | ||
continue; | ||
} | ||
if (obj.isRoadDeleted()) { | ||
deletedIds.add(obj.id); | ||
continue; | ||
} | ||
if (usedIds.containsKey(obj.id) && usedIds.get(obj.id) != obj.region) { | ||
// live-update, changed tags | ||
continue; | ||
} | ||
loaded += (results.put(obj.getId() >> SHIFT_ID, obj) == null) ? 1 : 0; | ||
usedIds.put(obj.id, obj.region); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return loaded; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume there should be an easier way to search RouteDataObjects without additional checks