forked from MapComplete/MapComplete
Usertests: add 'centermessage' again which indicates if data is loading or is present, see #1457
This commit is contained in:
parent
a55b84dba1
commit
1e56eb5503
8 changed files with 544 additions and 375 deletions
90
Logic/Actors/NoElementsInViewDetector.ts
Normal file
90
Logic/Actors/NoElementsInViewDetector.ts
Normal file
|
@ -0,0 +1,90 @@
|
|||
import { BBox } from "../BBox"
|
||||
import { Store } from "../UIEventSource"
|
||||
import ThemeViewState from "../../Models/ThemeViewState"
|
||||
import Constants from "../../Models/Constants"
|
||||
|
||||
export type FeatureViewState =
|
||||
| "no-data"
|
||||
| "zoom-to-low"
|
||||
| "has-visible-feature"
|
||||
| "all-filtered-away"
|
||||
export default class NoElementsInViewDetector {
|
||||
public readonly hasFeatureInView: Store<FeatureViewState>
|
||||
|
||||
constructor(themeViewState: ThemeViewState) {
|
||||
const state = themeViewState
|
||||
const minZoom = Math.min(
|
||||
...themeViewState.layout.layers
|
||||
.filter((l) => Constants.priviliged_layers.indexOf(<any>l.id) < 0)
|
||||
.map((l) => l.minzoom)
|
||||
)
|
||||
const mapProperties = themeViewState.mapProperties
|
||||
|
||||
const priviliged: Set<string> = new Set(Constants.priviliged_layers)
|
||||
|
||||
this.hasFeatureInView = state.mapProperties.bounds.stabilized(100).map(
|
||||
(bbox) => {
|
||||
if (mapProperties.zoom.data < minZoom) {
|
||||
// Not a single layer will display anything as the zoom is to low
|
||||
return "zoom-to-low"
|
||||
}
|
||||
|
||||
for (const [layerName, source] of themeViewState.perLayerFiltered) {
|
||||
if (priviliged.has(layerName)) {
|
||||
continue
|
||||
}
|
||||
if (
|
||||
mapProperties.zoom.data < themeViewState.layout.getLayer(layerName).minzoom
|
||||
) {
|
||||
continue
|
||||
}
|
||||
if (!state.layerState.filteredLayers.get(layerName).isDisplayed.data) {
|
||||
continue
|
||||
}
|
||||
const feats = source.features.data
|
||||
if (!(feats?.length > 0)) {
|
||||
// Nope, no data loaded
|
||||
continue
|
||||
}
|
||||
|
||||
for (const feat of feats) {
|
||||
if (BBox.get(feat).overlapsWith(bbox)) {
|
||||
// We found at least one item which has visible data
|
||||
return "has-visible-feature"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we arrive here, data might have been filtered away
|
||||
for (const [layerName, source] of themeViewState.perLayer) {
|
||||
if (priviliged.has(layerName)) {
|
||||
continue
|
||||
}
|
||||
if (
|
||||
mapProperties.zoom.data < themeViewState.layout.getLayer(layerName).minzoom
|
||||
) {
|
||||
continue
|
||||
}
|
||||
const feats = source.features.data
|
||||
if (!(feats?.length > 0)) {
|
||||
// Nope, no data loaded
|
||||
continue
|
||||
}
|
||||
|
||||
for (const feat of feats) {
|
||||
if (BBox.get(feat).overlapsWith(bbox)) {
|
||||
// We found at least one item, but as we didn't find it before, it is filtered away
|
||||
return "all-filtered-away"
|
||||
}
|
||||
}
|
||||
}
|
||||
return "no-data"
|
||||
},
|
||||
[
|
||||
...Array.from(themeViewState.perLayerFiltered.values()).map((f) => f.features),
|
||||
mapProperties.zoom,
|
||||
...Array.from(state.layerState.filteredLayers.values()).map((fl) => fl.isDisplayed),
|
||||
]
|
||||
)
|
||||
}
|
||||
}
|
|
@ -69,7 +69,7 @@ export default class LayoutSource extends FeatureSourceMerger {
|
|||
|
||||
const self = this
|
||||
function setIsLoading() {
|
||||
const loading = overpassSource?.runningQuery?.data && osmApiSource?.isRunning?.data
|
||||
const loading = overpassSource?.runningQuery?.data || osmApiSource?.isRunning?.data
|
||||
self._isLoading.setData(loading)
|
||||
}
|
||||
|
||||
|
|
|
@ -384,7 +384,6 @@ class ListenerTracker<T> {
|
|||
|
||||
/**
|
||||
* The mapped store is a helper type which does the mapping of a function.
|
||||
* It'll fuse
|
||||
*/
|
||||
class MappedStore<TIn, T> extends Store<T> {
|
||||
private readonly _upstream: Store<TIn>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue