Skip to content

Commit

Permalink
feat: Make layer updated in realtime based on service events be aware…
Browse files Browse the repository at this point in the history
… of time (closes #935)
  • Loading branch information
claustres committed Aug 14, 2024
1 parent 692aed9 commit 77da537
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions map/client/mixins/mixin.feature-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ export const featureService = {
if (!layer || !this.isLayerVisible(layer.name)) return
// Only possible when not edited by default
if ((typeof this.isLayerEdited === 'function') && this.isLayerEdited(layer)) return
// Check for time-based layers if update is in the currently visualized time range
// so that we don't add too much old features
if (!features.isFeatureInQueryInterval(feature, layer)) return
// As by default we update the whole layer in fetch and replace mode force add/update only mode
// Can only apply to realtime layers as we need to force a data refresh
if (typeof this.updateLayer === 'function') {
Expand All @@ -113,6 +116,10 @@ export const featureService = {
if (!layer || !this.isLayerVisible(layer.name)) return
// Only possible when not edited by default
if ((typeof this.isLayerEdited === 'function') && this.isLayerEdited(layer)) return
// Check for time-based layers if update is in the currently visualized time range ? Should not be relevent in this case.
// Indeed, as time has passed we might have old features that need to be cleaned,
// ie features now outside the request time range but inside the initial time range when they were requested
//if (!features.isFeatureInQueryInterval(feature, layer)) return
// Can only apply to realtime layers as we need to force a data refresh
if (typeof this.updateLayer === 'function') {
// Check if feature should be filtered or not according to layer base query
Expand Down
18 changes: 18 additions & 0 deletions map/client/utils/utils.features.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,24 @@ export async function getFeaturesQuery (options, queryInterval, queryLevel) {
return query
}

export function isFeatureInQueryInterval (feature, options) {
// We assume this is not a time-varying layer
if (!feature.time) return true
const queryInterval = getFeaturesQueryInterval(options)
if (!moment.isDuration(queryInterval)) return true
const now = Time.getCurrentTime()
const time = moment.utc(feature.time)
// Depending on the duration format we might have negative or positive values
const gte = (queryInterval.asMilliseconds() > 0
? now.clone().subtract(queryInterval)
: now.clone().add(queryInterval))
const lte = now
// In realtime mode take into account that we don't update time continuously but according to a frequency
// so that we might receive features "in the future" according to the current time
if (Time.isRealtime()) lte.add(Time.get().interval, 's')
return time.isSameOrAfter(gte) && time.isSameOrBefore(lte)
}

export async function getFeaturesFromQuery (options, query) {
// Check API to be used in case the layer is coming from a remote "planet"
const planetApi = (typeof options.getPlanetApi === 'function' ? options.getPlanetApi() : api)
Expand Down

0 comments on commit 77da537

Please sign in to comment.