-
Notifications
You must be signed in to change notification settings - Fork 90
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
feat(track): allow track truncation by time / age out #1243
Open
bradh
wants to merge
1
commit into
ngageoint:master
Choose a base branch
from
bradh:track_age_out_2021-04-15
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
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 |
---|---|---|
|
@@ -481,9 +481,7 @@ os.track.addToTrack = function(options) { | |
track.getGeometry()); | ||
|
||
// merge the split line so coordinates can be added in the correct location | ||
geometry.toLonLat(); | ||
geometry = os.geo.mergeLineGeometry(geometry); | ||
geometry.osTransform(); | ||
os.track.mergeSplitGeometry_(geometry); | ||
|
||
var flatCoordinates = geometry.flatCoordinates; | ||
var stride = geometry.stride; | ||
|
@@ -548,9 +546,7 @@ os.track.clamp = function(track, start, end) { | |
track.getGeometry()); | ||
|
||
// merge the split line so features can be added in the correct location | ||
geometry.toLonLat(); | ||
geometry = os.geo.mergeLineGeometry(geometry); | ||
geometry.osTransform(); | ||
os.track.mergeSplitGeometry_(geometry); | ||
|
||
var stride = geometry.stride; | ||
|
||
|
@@ -609,25 +605,71 @@ os.track.truncate = function(track, size) { | |
|
||
if (geometry.getType() === ol.geom.GeometryType.MULTI_LINE_STRING) { | ||
// merge the split line so coordinates can be truncated to the correct size | ||
geometry.toLonLat(); | ||
geometry = os.geo.mergeLineGeometry(geometry); | ||
geometry.osTransform(); | ||
os.track.mergeSplitGeometry_(geometry); | ||
} | ||
|
||
var flatCoordinates = geometry.flatCoordinates; | ||
var stride = geometry.stride; | ||
var numCoords = size * stride; | ||
os.track.prunePointsAt_(track, geometry, numCoords); | ||
}; | ||
|
||
/** | ||
* Merge a split line geometry. | ||
* @param {!os.track.TrackLike} geometry the geometry to merge | ||
*/ | ||
os.track.mergeSplitGeometry_ = function(geometry) { | ||
geometry.toLonLat(); | ||
geometry = os.geo.mergeLineGeometry(geometry); | ||
geometry.osTransform(); | ||
}; | ||
|
||
/** | ||
* Remove old track points from a track. Keeps the most recent points. | ||
* | ||
* @param {!ol.Feature} track The track. | ||
* @param {number} maximumAge The maximum age that a track point can get to before it is considered for removal, in milliseconds. | ||
* | ||
* @suppress {accessControls} To allow direct access to feature metadata and line coordinates. | ||
*/ | ||
os.track.truncateByAge = function(track, maximumAge) { | ||
// ensure the age-out is >= 0 | ||
maximumAge = Math.max(0, maximumAge); | ||
|
||
// add point(s) to the original geometry, in case the track was interpolated | ||
var geometry = /** @type {!(os.track.TrackLike)} */ (track.values_[os.interpolate.ORIGINAL_GEOM_FIELD] || | ||
track.getGeometry()); | ||
|
||
if (geometry.getType() === ol.geom.GeometryType.MULTI_LINE_STRING) { | ||
// merge the split line so coordinates can be counted and truncated cleanly | ||
os.track.mergeSplitGeometry_(geometry); | ||
} | ||
var coords = geometry.getCoordinates(); | ||
var timeNow = Date.now(); | ||
var pointsToKeep = 0; | ||
if (coords) { | ||
coords.reverse().forEach(function(c) { | ||
var timeForThisCoord = c[c.length - 1]; | ||
var ageForThisCoord = timeNow - timeForThisCoord; | ||
if (ageForThisCoord < maximumAge) { | ||
pointsToKeep = pointsToKeep + 1; | ||
} | ||
}); | ||
} | ||
var numCoords = pointsToKeep * geometry.stride; | ||
os.track.prunePointsAt_(track, geometry, numCoords); | ||
}; | ||
|
||
os.track.prunePointsAt_ = function(track, geometry, numCoords) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing JSDoc for this new function. |
||
var flatCoordinates = geometry.flatCoordinates; | ||
if (flatCoordinates.length > numCoords) { | ||
var removed = flatCoordinates.splice(0, flatCoordinates.length - numCoords); | ||
os.track.setGeometry(track, geometry); | ||
|
||
// remove old metadata fields from the track | ||
os.track.pruneMetadata_(track, removed, stride); | ||
os.track.pruneMetadata_(track, removed, geometry.stride); | ||
} | ||
}; | ||
|
||
|
||
/** | ||
* Prune the metadata map for a track, removing metadata by indexed sort values. | ||
* @param {!ol.Feature} track The track. | ||
|
@@ -1076,7 +1118,7 @@ os.track.getLineTime = function(coords) { | |
|
||
|
||
/** | ||
* Get the time (in meters) covered by a set of coordinates for a multi-line. | ||
* Get the time (in seconds) covered by a set of coordinates for a multi-line. | ||
* | ||
* @param {Array<Array<ol.Coordinate>>} coords The multi-line coordinates | ||
* @return {number} The time | ||
|
@@ -1430,7 +1472,7 @@ os.track.getTrackPositionAt = function(track, timestamp, index, coordinates, str | |
* @param {number} endIndex The index of the most recent known coordinate. | ||
* @param {!Array<number>} coordinates The flat track coordinate array. | ||
* @param {number} stride The stride of the coordinate array. | ||
* @param {Array<number>=} opt_ends The end indicies of each line in a multi-line. Undefined if not a multi-line. | ||
* @param {Array<number>=} opt_ends The end indices of each line in a multi-line. Undefined if not a multi-line. | ||
* | ||
* @suppress {accessControls} To allow direct access to line string coordinates. | ||
*/ | ||
|
@@ -1650,3 +1692,5 @@ os.track.splitIntoTracks = function(options) { | |
|
||
return result; | ||
}; | ||
|
||
|
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
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.
os.track.getTimeIndex
will get the closest index to a specified timestamp using binary search, so it may be more performant to:This would avoid the
getCoordinates
call which reconstitutes the flat coordinates (unnecessary GC of all those arrays), and reversing/iterating over the entire array.