forked from MapComplete/MapComplete
Refactoring: split 'ThemeViewState' into many classes
This commit is contained in:
parent
2b858bd2aa
commit
dbcbf2787d
34 changed files with 1503 additions and 1227 deletions
|
|
@ -2,18 +2,17 @@ import { QueryParameters } from "../Web/QueryParameters"
|
|||
import { BBox } from "../BBox"
|
||||
import Constants from "../../Models/Constants"
|
||||
import { GeoLocationState } from "../State/GeoLocationState"
|
||||
import { UIEventSource } from "../UIEventSource"
|
||||
import { Store, UIEventSource } from "../UIEventSource"
|
||||
import { Feature, LineString, Point } from "geojson"
|
||||
import { FeatureSource, WritableFeatureSource } from "../FeatureSource/FeatureSource"
|
||||
import { LocalStorageSource } from "../Web/LocalStorageSource"
|
||||
import { GeoOperations } from "../GeoOperations"
|
||||
import { OsmTags } from "../../Models/OsmFeature"
|
||||
import StaticFeatureSource, {
|
||||
WritableStaticFeatureSource,
|
||||
} from "../FeatureSource/Sources/StaticFeatureSource"
|
||||
import StaticFeatureSource, { WritableStaticFeatureSource } from "../FeatureSource/Sources/StaticFeatureSource"
|
||||
import { MapProperties } from "../../Models/MapProperties"
|
||||
import { Orientation } from "../../Sensors/Orientation"
|
||||
;("use strict")
|
||||
|
||||
("use strict")
|
||||
/**
|
||||
* The geolocation-handler takes a map-location and a geolocation state.
|
||||
* It'll move the map as appropriate given the state of the geolocation-API
|
||||
|
|
@ -45,14 +44,14 @@ export default class GeoLocationHandler {
|
|||
public readonly mapHasMoved: UIEventSource<Date | undefined> = new UIEventSource<
|
||||
Date | undefined
|
||||
>(undefined)
|
||||
private readonly selectedElement: UIEventSource<Feature>
|
||||
private readonly mapProperties?: MapProperties
|
||||
private readonly selectedElement: Store<object>
|
||||
private readonly mapProperties: MapProperties
|
||||
private readonly gpsLocationHistoryRetentionTime?: UIEventSource<number>
|
||||
|
||||
constructor(
|
||||
geolocationState: GeoLocationState,
|
||||
selectedElement: UIEventSource<Feature>,
|
||||
mapProperties?: MapProperties,
|
||||
selectedElement: Store<object>,
|
||||
mapProperties: MapProperties,
|
||||
gpsLocationHistoryRetentionTime?: UIEventSource<number>
|
||||
) {
|
||||
this.geolocationState = geolocationState
|
||||
|
|
@ -62,7 +61,7 @@ export default class GeoLocationHandler {
|
|||
this.gpsLocationHistoryRetentionTime = gpsLocationHistoryRetentionTime
|
||||
// Did an interaction move the map?
|
||||
const initTime = new Date()
|
||||
mapLocation.addCallbackD(() => {
|
||||
mapLocation?.addCallbackD(() => {
|
||||
if (new Date().getTime() - initTime.getTime() < 250) {
|
||||
return
|
||||
}
|
||||
|
|
@ -139,7 +138,7 @@ export default class GeoLocationHandler {
|
|||
}
|
||||
}
|
||||
|
||||
mapLocation.setData({
|
||||
mapLocation?.setData({
|
||||
lon: newLocation.longitude,
|
||||
lat: newLocation.latitude,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { BBox } from "../BBox"
|
||||
import { Store } from "../UIEventSource"
|
||||
import ThemeViewState from "../../Models/ThemeViewState"
|
||||
import Constants from "../../Models/Constants"
|
||||
import { WithChangesState } from "../../Models/ThemeViewState/WithChangesState"
|
||||
|
||||
export type FeatureViewState =
|
||||
| "no-data"
|
||||
|
|
@ -11,7 +11,7 @@ export type FeatureViewState =
|
|||
export default class NoElementsInViewDetector {
|
||||
public readonly hasFeatureInView: Store<FeatureViewState>
|
||||
|
||||
constructor(themeViewState: ThemeViewState) {
|
||||
constructor(themeViewState: WithChangesState) {
|
||||
const state = themeViewState
|
||||
const minZoom = Math.min(
|
||||
...themeViewState.theme.layers
|
||||
|
|
@ -32,7 +32,6 @@ export default class NoElementsInViewDetector {
|
|||
return "zoom-to-low"
|
||||
}
|
||||
|
||||
let minzoomWithData = 9999
|
||||
|
||||
for (const [layerName, source] of themeViewState.perLayerFiltered) {
|
||||
if (priviliged.has(layerName)) {
|
||||
|
|
@ -45,7 +44,6 @@ export default class NoElementsInViewDetector {
|
|||
}
|
||||
const layer = themeViewState.theme.getLayer(layerName)
|
||||
if (mapProperties.zoom.data < layer.minzoom) {
|
||||
minzoomWithData = Math.min(layer.minzoom)
|
||||
continue
|
||||
}
|
||||
if (!state.layerState.filteredLayers.get(layerName).isDisplayed.data) {
|
||||
|
|
|
|||
|
|
@ -4,10 +4,12 @@
|
|||
import SimpleMetaTagger from "../SimpleMetaTagger"
|
||||
import { OsmTags } from "../../Models/OsmFeature"
|
||||
import { Utils } from "../../Utils"
|
||||
import ThemeViewState from "../../Models/ThemeViewState"
|
||||
import { BBox } from "../BBox"
|
||||
import { Feature } from "geojson"
|
||||
import { SpecialVisualizationState } from "../../UI/SpecialVisualization"
|
||||
import { Changes } from "../Osm/Changes"
|
||||
import ThemeConfig from "../../Models/ThemeConfig/ThemeConfig"
|
||||
import FeaturePropertiesStore from "../FeatureSource/Actors/FeaturePropertiesStore"
|
||||
import { WithChangesState } from "../../Models/ThemeViewState/WithChangesState"
|
||||
|
||||
export default class SelectedElementTagsUpdater {
|
||||
private static readonly metatags = new Set([
|
||||
|
|
@ -18,9 +20,9 @@ export default class SelectedElementTagsUpdater {
|
|||
"uid",
|
||||
"id",
|
||||
])
|
||||
private readonly state: ThemeViewState
|
||||
private readonly state: WithChangesState
|
||||
|
||||
constructor(state: ThemeViewState) {
|
||||
constructor(state: WithChangesState) {
|
||||
this.state = state
|
||||
state.osmConnection.isLoggedIn.addCallbackAndRun((isLoggedIn) => {
|
||||
if (!isLoggedIn && !Utils.runningFromConsole) {
|
||||
|
|
@ -32,7 +34,11 @@ export default class SelectedElementTagsUpdater {
|
|||
})
|
||||
}
|
||||
|
||||
public static applyUpdate(latestTags: OsmTags, id: string, state: SpecialVisualizationState) {
|
||||
public static applyUpdate(latestTags: OsmTags, id: string, state: {
|
||||
theme: ThemeConfig,
|
||||
changes: Changes,
|
||||
featureProperties: FeaturePropertiesStore
|
||||
}) {
|
||||
try {
|
||||
const leftRightSensitive = state.theme.isLeftRightSensitive()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue