Skip to content

Commit

Permalink
#587 Raster and Vector Refresh Intervals
Browse files Browse the repository at this point in the history
  • Loading branch information
tariqksoliman committed Sep 26, 2024
1 parent afd3bb5 commit 0503b9d
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 128 deletions.
20 changes: 0 additions & 20 deletions configure/src/metaconfigs/layer-data-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,26 +369,6 @@
"defaultChecked": false
}
]
},
{
"components": [
{
"field": "time.refreshIntervalEnabled",
"name": "Refresh Interval Enabled",
"description": "If 'Time Enabled' and 'Refresh Interval Enabled', this layer will automatically refresh/requery its data every 'Refresh Every N Seconds'. This is useful when the layer's data updates at some uniform cadence. Be aware that this may be an expensive operation depending on the amount of data a layer needs and the number of layers that have this enabled.",
"type": "switch",
"width": 5,
"defaultChecked": false
},
{
"field": "time.refreshIntervalAmount",
"name": "Refresh Every N Seconds",
"description": "If 'Time Enabled' and 'Refresh Interval Enabled', this layer will automatically refresh/requery its data every n seconds.",
"type": "number",
"min": 1,
"width": 3
}
]
}
]
},
Expand Down
20 changes: 0 additions & 20 deletions configure/src/metaconfigs/layer-model-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,26 +408,6 @@
"width": 6
}
]
},
{
"components": [
{
"field": "time.refreshIntervalEnabled",
"name": "Refresh Interval Enabled",
"description": "If 'Time Enabled' and 'Refresh Interval Enabled', this layer will automatically refresh/requery its data every 'Refresh Every N Seconds'. This is useful when the layer's data updates at some uniform cadence. Be aware that this may be an expensive operation depending on the amount of data a layer needs and the number of layers that have this enabled.",
"type": "switch",
"width": 5,
"defaultChecked": false
},
{
"field": "time.refreshIntervalAmount",
"name": "Refresh Every N Seconds",
"description": "If 'Time Enabled' and 'Refresh Interval Enabled', this layer will automatically refresh/requery its data every n seconds.",
"type": "number",
"min": 1,
"width": 3
}
]
}
]
},
Expand Down
20 changes: 0 additions & 20 deletions configure/src/metaconfigs/layer-query-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -531,26 +531,6 @@
"width": 6
}
]
},
{
"components": [
{
"field": "time.refreshIntervalEnabled",
"name": "Refresh Interval Enabled",
"description": "If 'Time Enabled' and 'Refresh Interval Enabled', this layer will automatically refresh/requery its data every 'Refresh Every N Seconds'. This is useful when the layer's data updates at some uniform cadence. Be aware that this may be an expensive operation depending on the amount of data a layer needs and the number of layers that have this enabled.",
"type": "switch",
"width": 5,
"defaultChecked": false
},
{
"field": "time.refreshIntervalAmount",
"name": "Refresh Every N Seconds",
"description": "If 'Time Enabled' and 'Refresh Interval Enabled', this layer will automatically refresh/requery its data every n seconds.",
"type": "number",
"min": 1,
"width": 3
}
]
}
]
},
Expand Down
50 changes: 42 additions & 8 deletions src/essence/Ancillary/TimeControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ var TimeControl = {
layer,
evenIfOff,
evenIfControlled,
forceRequery
forceRequery,
skipOrderedBringToFront
) {
// reload layer
if (typeof layer == 'string') {
Expand All @@ -204,7 +205,8 @@ var TimeControl = {

layer.url = await TimeControl.performTimeUrlReplacements(
layer.url,
layer
layer,
forceRequery
)
let changedUrl = null
if (layer.url !== originalUrl) changedUrl = layer.url
Expand Down Expand Up @@ -269,19 +271,46 @@ var TimeControl = {
// refresh map
if (evenIfControlled === true || layer.controlled !== true)
if (L_.layers.on[layer.name] || evenIfOff) {
return await Map_.refreshLayer(layer, () => {
// put start/endtime keywords back
if (layer.time && layer.time.enabled === true)
layer.url = originalUrl
})
return await Map_.refreshLayer(
layer,
() => {
if (layer.time && layer.time.enabled === true) {
// put start/endtime keywords back
layer.url = originalUrl

// if requery was force, remember to timeFilter after load
if (
layer.type === 'vector' &&
layer.time.type === 'local' &&
layer.time.endProp != null &&
forceRequery === true
) {
if (
evenIfControlled === true ||
layer.controlled !== true
)
L_.timeFilterVectorLayer(
layer.name,
new Date(
layer.time.start
).getTime(),
new Date(
layer.time.end
).getTime()
)
}
}
},
skipOrderedBringToFront
)
}
}
}
// put start/endtime keywords back
if (layer.time && layer.time.enabled === true) layer.url = originalUrl
return true
},
performTimeUrlReplacements: async function (url, layer) {
performTimeUrlReplacements: async function (url, layer, forceRequery) {
return new Promise(async (resolve, reject) => {
let layerTimeFormat =
layer.time?.format == null
Expand Down Expand Up @@ -322,6 +351,11 @@ var TimeControl = {
}
}
}
if (forceRequery === true) {
nextUrl += `${
nextUrl.indexOf('?') === -1 ? '?' : '&'
}nocache=${new Date().getTime()}`
}
resolve(nextUrl)
})
},
Expand Down
50 changes: 25 additions & 25 deletions src/essence/Basics/Layers_/Layers_.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ const L_ = {
//Takes in config layer obj
//Toggles a layer on and off and accounts for sublayers
//Takes in a config layer object
toggleLayer: async function (s) {
toggleLayer: async function (s, skipOrderedBringToFront) {
if (s == null) return

const wasNeverOn = L_.layers.layer[s.name] === false
Expand All @@ -254,7 +254,7 @@ const L_ = {
if (L_.layers.on[s.name] === true) on = true
else on = false

await L_.toggleLayerHelper(s, on)
await L_.toggleLayerHelper(s, on, null, null, skipOrderedBringToFront)

Object.keys(L_._onLayerToggleSubscriptions).forEach((k) => {
L_._onLayerToggleSubscriptions[k](s.name, !on)
Expand Down Expand Up @@ -292,7 +292,8 @@ const L_ = {
s,
on,
ignoreToggleStateChange,
globeOnly
globeOnly,
skipOrderedBringToFront
) {
if (s.type !== 'header') {
if (on) {
Expand All @@ -303,7 +304,7 @@ const L_ = {
try {
$('.drawToolContextMenuHeaderClose').click()
} catch (err) {}
L_.Map_.map.removeLayer(L_.layers.layer[s.name])
L_.Map_.rmNotNull(L_.layers.layer[s.name])
if (L_.layers.attachments[s.name]) {
for (let sub in L_.layers.attachments[s.name]) {
switch (L_.layers.attachments[s.name][sub].type) {
Expand Down Expand Up @@ -588,7 +589,11 @@ const L_ = {

if (s.type === 'vector') L_._updatePairings(s.name, !on)

if (!on && s.type === 'vector') {
if (
!on &&
s.type === 'vector' &&
skipOrderedBringToFront !== true
) {
L_.Map_.orderedBringToFront()
}
L_._refreshAnnotationEvents()
Expand Down Expand Up @@ -1639,6 +1644,10 @@ const L_ = {
}
}
L_.layers.opacity[name] = newOpacity

if (L_.activeFeature?.layer && L_.activeFeature.layerName === name) {
L_.highlight(L_.activeFeature.layer)
}
},
getLayerOpacity: function (name) {
var l = L_.layers.layer[name]
Expand Down Expand Up @@ -3540,13 +3549,6 @@ function parseConfig(configData, urlOnLayers) {
L_.layers.refreshIntervals[d[i].name] = setInterval(
async () => {
if (L_.layers.on[d[i].name] === true) {
console.log(
JSON.stringify(
L_.activeFeature
? L_.activeFeature.layerName
: ''
)
)
let savedActiveFeature
if (
L_.activeFeature &&
Expand All @@ -3563,24 +3565,22 @@ function parseConfig(configData, urlOnLayers) {
d[i].name,
false,
false,
true,
true
)
// Reselect activeFeature

setTimeout(() => {
if (
savedActiveFeature &&
savedActiveFeature.layerName === d[i].name
) {
L_.selectFeature(
savedActiveFeature.layerName,
savedActiveFeature.feature
)
}
}, 800)
if (
savedActiveFeature &&
savedActiveFeature.layerName === d[i].name
) {
L_.selectFeature(
savedActiveFeature.layerName,
savedActiveFeature.feature
)
}
}
},
d[i].time.refreshIntervalAmount * 1000
(d[i].time.refreshIntervalAmount || 30) * 1000
)
}
//Save the prevName for easy tracing back
Expand Down
14 changes: 10 additions & 4 deletions src/essence/Basics/Map_/Map_.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ let Map_ = {
removeTempTileLayer: function () {
this.rmNotNull(this.tempTileLayer)
},
//Removes the map layer if it isnt null
//Removes the map layer if it isn't null
rmNotNull: function (layer) {
if (layer != null) {
this.map.removeLayer(layer)
Expand Down Expand Up @@ -395,7 +395,7 @@ let Map_ = {
)
}
},
refreshLayer: async function (layerObj, cb) {
refreshLayer: async function (layerObj, cb, skipOrderedBringToFront) {
// We need to find and remove all points on the map that belong to the layer
// Not sure if there is a cleaner way of doing this
for (var i = L_._layersOrdered.length - 1; i >= 0; i--) {
Expand All @@ -407,15 +407,21 @@ let Map_ = {
if (L_._layersBeingMade[layerObj.name] !== true) {
const wasOn = L_.layers.on[layerObj.name]
if (wasOn)
await L_.toggleLayer(L_.layers.data[layerObj.name]) // turn off if on
L_.toggleLayer(
L_.layers.data[layerObj.name],
skipOrderedBringToFront
) // turn off if on
// fake on
L_.layers.on[layerObj.name] = true
await makeLayer(layerObj, true, null)
L_.addVisible(Map_, [layerObj.name])

// turn off if was off
if (wasOn) L_.layers.on[layerObj.name] = false
await L_.toggleLayer(L_.layers.data[layerObj.name]) // turn back on/off
L_.toggleLayer(
L_.layers.data[layerObj.name],
skipOrderedBringToFront
) // turn back on/off

L_.enforceVisibilityCutoffs()
} else {
Expand Down
15 changes: 12 additions & 3 deletions src/essence/Tools/Layers/LayersTool.css
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,17 @@
padding: 0;
margin: 0;
}
#layersTool .settings .layerTimeTitle {
display: flex;
height: 30px;
line-height: 30px;
}
#layersTool .settings .layerTimeTitle > div:first-child {
color: var(--color-h);
text-transform: uppercase;
font-size: 12px;
}

#layersTool .settings .layerSettingsTitle {
display: flex;
height: 30px;
Expand All @@ -213,7 +224,6 @@
font-size: 12px;
}
#layersTool .settings .layerSettingsTitle > div:last-child {

}
#layersTool .settings ul > li {
line-height: 30px;
Expand Down Expand Up @@ -620,7 +630,6 @@
}
}


.layersToolExport {
cursor: default;
height: unset !important;
Expand Down Expand Up @@ -674,4 +683,4 @@
}
.layersToolExportGo:hover {
background-color: var(--color-a1-5);
}
}
Loading

0 comments on commit 0503b9d

Please sign in to comment.