chore: automated housekeeping...

This commit is contained in:
Pieter Vander Vennet 2025-01-28 15:42:34 +01:00
parent 6bc8760adf
commit 0ad881316b
359 changed files with 2049 additions and 938 deletions

View file

@ -35,10 +35,8 @@ import ShowDataLayer from "../../UI/Map/ShowDataLayer"
*/
export class UserMapFeatureswitchState extends WithUserRelatedState {
readonly map: UIEventSource<MlMap>
readonly mapProperties: MapLibreAdaptor & MapProperties & ExportableMap
readonly lastClickObject: LastClickFeatureSource
@ -47,19 +45,22 @@ export class UserMapFeatureswitchState extends WithUserRelatedState {
readonly geolocationControl: GeolocationControlState
readonly historicalUserLocations: WritableFeatureSource<Feature<Point>>
readonly availableLayers: { store: Store<RasterLayerPolygon[]> }
readonly currentView: FeatureSource<Feature<Polygon>>
readonly fullNodeDatabase?: FullNodeDatabaseSource
constructor(theme: ThemeConfig, selectedElement: Store<object>) {
const rasterLayer: UIEventSource<RasterLayerPolygon> = new UIEventSource<RasterLayerPolygon>(undefined)
const rasterLayer: UIEventSource<RasterLayerPolygon> =
new UIEventSource<RasterLayerPolygon>(undefined)
super(theme, rasterLayer)
this.geolocationState = new GeoLocationState()
const initial = new InitialMapPositioning(theme, this.geolocationState, this.osmConnection)
this.map = new UIEventSource<MlMap>(undefined)
this.mapProperties = new MapLibreAdaptor(this.map, { rasterLayer, ...initial }, { correctClick: 20 })
this.mapProperties = new MapLibreAdaptor(
this.map,
{ rasterLayer, ...initial },
{ correctClick: 20 }
)
this.geolocation = new GeoLocationHandler(
this.geolocationState,
@ -70,7 +71,6 @@ export class UserMapFeatureswitchState extends WithUserRelatedState {
this.geolocationControl = new GeolocationControlState(this.geolocation, this.mapProperties)
this.historicalUserLocations = this.geolocation.historicalUserLocations
this.userRelatedState.fixateNorth.addCallbackAndRunD((fixated) => {
this.mapProperties.allowRotating.setData(fixated !== "yes")
})
@ -100,8 +100,8 @@ export class UserMapFeatureswitchState extends WithUserRelatedState {
bbox.asGeoJson({
zoom: this.mapProperties.zoom.data,
...this.mapProperties.location.data,
id: "current_view_" + currentViewIndex
})
id: "current_view_" + currentViewIndex,
}),
]
})
)
@ -111,12 +111,10 @@ export class UserMapFeatureswitchState extends WithUserRelatedState {
this.fullNodeDatabase = new FullNodeDatabaseSource()
}
///////// Actors ///////////////
new BackgroundLayerResetter(this.mapProperties.rasterLayer, this.availableLayers)
this.userRelatedState.showScale.addCallbackAndRun((showScale) => {
this.mapProperties.showScale.set(showScale)
})
@ -127,14 +125,11 @@ export class UserMapFeatureswitchState extends WithUserRelatedState {
this.userRelatedState.preferredBackgroundLayer
)
this.initHotkeys()
this.drawOverlayLayers()
this.drawLock()
}
/**
* If the map is locked to a certain area _and_ we are in test mode, draw this on the map
* @private
@ -159,7 +154,6 @@ export class UserMapFeatureswitchState extends WithUserRelatedState {
}
}
/* By focussing on the map, the keyboard panning and zoom with '+' and '+' works */
public focusOnMap() {
if (this.map.data) {
@ -205,55 +199,35 @@ export class UserMapFeatureswitchState extends WithUserRelatedState {
})
}
Hotkeys.RegisterHotkey(
{ nomod: "O" },
docs.selectOsmbasedmap,
() => setLayerCategory("osmbasedmap")
Hotkeys.RegisterHotkey({ nomod: "O" }, docs.selectOsmbasedmap, () =>
setLayerCategory("osmbasedmap")
)
Hotkeys.RegisterHotkey(
{ nomod: "M" },
docs.selectMap,
() => setLayerCategory("map")
Hotkeys.RegisterHotkey({ nomod: "M" }, docs.selectMap, () => setLayerCategory("map"))
Hotkeys.RegisterHotkey({ nomod: "P" }, docs.selectAerial, () =>
setLayerCategory("photo")
)
Hotkeys.RegisterHotkey({ shift: "O" }, docs.selectOsmbasedmap, () =>
setLayerCategory("osmbasedmap", 2)
)
Hotkeys.RegisterHotkey(
{ nomod: "P" },
docs.selectAerial,
() => setLayerCategory("photo")
)
Hotkeys.RegisterHotkey(
{ shift: "O" },
docs.selectOsmbasedmap,
() => setLayerCategory("osmbasedmap", 2)
)
Hotkeys.RegisterHotkey({ shift: "M" }, docs.selectMap, () => setLayerCategory("map", 2))
Hotkeys.RegisterHotkey(
{ shift: "M" },
docs.selectMap,
() => setLayerCategory("map", 2)
)
Hotkeys.RegisterHotkey(
{ shift: "P" },
docs.selectAerial,
() => setLayerCategory("photo", 2)
Hotkeys.RegisterHotkey({ shift: "P" }, docs.selectAerial, () =>
setLayerCategory("photo", 2)
)
return true
})
Hotkeys.RegisterHotkey(
{ nomod: "L" },
Translations.t.hotkeyDocumentation.geolocate,
() => {
this.geolocationControl.handleClick()
}
)
Hotkeys.RegisterHotkey({ nomod: "L" }, Translations.t.hotkeyDocumentation.geolocate, () => {
this.geolocationControl.handleClick()
})
Hotkeys.RegisterHotkey(
{
shift: "T"
shift: "T",
},
docs.translationMode,
() => {
@ -286,7 +260,7 @@ export class UserMapFeatureswitchState extends WithUserRelatedState {
return new ShowDataLayer(map, {
features,
layer,
metaTags: this.userRelatedState.preferencesAsTags
metaTags: this.userRelatedState.preferencesAsTags,
})
}
}

View file

@ -1,7 +1,5 @@
import { Changes } from "../../Logic/Osm/Changes"
import {
NewGeometryFromChangesFeatureSource
} from "../../Logic/FeatureSource/Sources/NewGeometryFromChangesFeatureSource"
import { NewGeometryFromChangesFeatureSource } from "../../Logic/FeatureSource/Sources/NewGeometryFromChangesFeatureSource"
import { WithLayoutSourceState } from "./WithLayoutSourceState"
import ThemeConfig from "../ThemeConfig/ThemeConfig"
import { Utils } from "../../Utils"
@ -20,10 +18,11 @@ import { Map as MlMap } from "maplibre-gl"
import FilteringFeatureSource from "../../Logic/FeatureSource/Sources/FilteringFeatureSource"
import ShowDataLayer from "../../UI/Map/ShowDataLayer"
import SelectedElementTagsUpdater from "../../Logic/Actors/SelectedElementTagsUpdater"
import NoElementsInViewDetector, { FeatureViewState } from "../../Logic/Actors/NoElementsInViewDetector"
import NoElementsInViewDetector, {
FeatureViewState,
} from "../../Logic/Actors/NoElementsInViewDetector"
export class WithChangesState extends WithLayoutSourceState {
readonly changes: Changes
readonly newFeatures: WritableFeatureSource
readonly osmObjectDownloader: OsmObjectDownloader
@ -44,7 +43,7 @@ export class WithChangesState extends WithLayoutSourceState {
osmConnection: this.osmConnection,
featureProperties: this.featureProperties,
historicalUserLocations: this.historicalUserLocations,
reportError: this.reportError
reportError: this.reportError,
},
theme?.isLeftRightSensitive() ?? false
)
@ -66,8 +65,7 @@ export class WithChangesState extends WithLayoutSourceState {
),
new ChangeGeometryApplicator(this.indexedFeatures, this.changes),
{
constructStore: (features, layer) =>
new GeoIndexedStoreForLayer(features, layer),
constructStore: (features, layer) => new GeoIndexedStoreForLayer(features, layer),
handleLeftovers: (features) => {
console.warn(
"Got ",
@ -75,7 +73,7 @@ export class WithChangesState extends WithLayoutSourceState {
"leftover features, such as",
features[0].properties
)
}
},
}
)
this.perLayer = perLayer.perLayer
@ -85,7 +83,6 @@ export class WithChangesState extends WithLayoutSourceState {
this.toCacheSavers = theme.enableCache ? this.initSaveToLocalStorage() : undefined
////// ACTORS ////////
new ChangeToElementsActor(this.changes, this.featureProperties)
@ -97,7 +94,7 @@ export class WithChangesState extends WithLayoutSourceState {
featureProperties: this.featureProperties,
indexedFeatures: this.indexedFeatures,
osmObjectDownloader: this.osmObjectDownloader,
perLayer: this.perLayer
perLayer: this.perLayer,
})
}
@ -154,8 +151,8 @@ export class WithChangesState extends WithLayoutSourceState {
userid: this.osmConnection.userDetails.data?.uid,
pendingChanges: this.changes.pendingChanges.data,
previousChanges: this.changes.allChanges.data,
changeRewrites: Utils.MapToObj(this.changes._changesetHandler._remappings)
})
changeRewrites: Utils.MapToObj(this.changes._changesetHandler._remappings),
}),
})
} catch (e) {
console.error("Could not upload an error report")
@ -227,10 +224,9 @@ export class WithChangesState extends WithLayoutSourceState {
doShowLayer,
metaTags: this.userRelatedState.preferencesAsTags,
selectedElement: this.selectedElement,
fetchStore: (id) => this.featureProperties.getStore(id)
fetchStore: (id) => this.featureProperties.getStore(id),
})
})
return filteringFeatureSource
}
}

View file

@ -34,7 +34,6 @@ export class WithGuiState extends WithSpecialLayers {
this.initHotkeysGui()
}
private initHotkeysGui() {
const docs = Translations.t.hotkeyDocumentation
@ -44,7 +43,7 @@ export class WithGuiState extends WithSpecialLayers {
Hotkeys.RegisterHotkey(
{
nomod: "b"
nomod: "b",
},
docs.openLayersPanel,
() => {
@ -55,7 +54,7 @@ export class WithGuiState extends WithSpecialLayers {
)
Hotkeys.RegisterHotkey(
{
nomod: "s"
nomod: "s",
},
Translations.t.hotkeyDocumentation.openFilterPanel,
() => {
@ -70,5 +69,4 @@ export class WithGuiState extends WithSpecialLayers {
this.guistate.closeAll()
this.selectedElement.setData(this.currentView.features?.data?.[0])
}
}

View file

@ -12,12 +12,10 @@ import { WithGuiState } from "./WithGuiState"
import { SpecialVisualizationState } from "../../UI/SpecialVisualization"
export class WithImageState extends WithGuiState implements SpecialVisualizationState {
readonly imageUploadManager: ImageUploadManager
readonly previewedImage = new UIEventSource<ProvidedImage>(undefined)
readonly nearbyImageSearcher: CombinedFetcher
constructor(layout: ThemeConfig, mvtAvailableLayers: Store<Set<string>>) {
super(layout, mvtAvailableLayers)
this.imageUploadManager = new ImageUploadManager(
@ -40,28 +38,23 @@ export class WithImageState extends WithGuiState implements SpecialVisualization
longAgo.setTime(new Date().getTime() - 5 * 365 * 24 * 60 * 60 * 1000)
this.nearbyImageSearcher = new CombinedFetcher(50, longAgo, this.indexedFeatures)
this.initActors()
Hash.hash.addCallbackAndRunD((hash) => {
if (hash === "current_view" || hash.match(/current_view_[0-9]+/)) {
this.selectCurrentView()
}
})
}
/**
* Setup various services for which no reference are needed
*/
private initActors() {
new ThemeViewStateHashActor({
selectedElement: this.selectedElement,
indexedFeatures: this.indexedFeatures,
guistate: this.guistate
guistate: this.guistate,
})
new PendingChangesUploader(this.changes, this.selectedElement, this.imageUploadManager)
}
}

View file

@ -9,7 +9,6 @@ import { FeatureSource, IndexedFeatureSource } from "../../Logic/FeatureSource/F
import { Tag } from "../../Logic/Tags/Tag"
export class WithLayoutSourceState extends WithSelectedElementState {
readonly layerState: LayerState
readonly dataIsLoading: Store<boolean>
@ -21,7 +20,6 @@ export class WithLayoutSourceState extends WithSelectedElementState {
*/
readonly floors: Store<string[]>
constructor(theme: ThemeConfig, mvtAvailableLayers: Store<Set<string>>) {
super(theme)
/* Set up the layout source
@ -62,24 +60,23 @@ export class WithLayoutSourceState extends WithSelectedElementState {
this.layerState.filteredLayers
.get("favourite")
?.isDisplayed?.addCallbackAndRunD((favouritesShown) => {
const oldGlobal = this.layerState.globalFilters.data
const key = "show-favourite"
if (favouritesShown) {
this.layerState.globalFilters.set([
...oldGlobal,
{
forceShowOnMatch: true,
id: key,
osmTags: new Tag("_favourite", "yes"),
state: 0,
onNewPoint: undefined
}
])
} else {
this.layerState.globalFilters.set(oldGlobal.filter((gl) => gl.id !== key))
}
})
const oldGlobal = this.layerState.globalFilters.data
const key = "show-favourite"
if (favouritesShown) {
this.layerState.globalFilters.set([
...oldGlobal,
{
forceShowOnMatch: true,
id: key,
osmTags: new Tag("_favourite", "yes"),
state: 0,
onNewPoint: undefined,
},
])
} else {
this.layerState.globalFilters.set(oldGlobal.filter((gl) => gl.id !== key))
}
})
}
private static initFloors(features: FeatureSource): Store<string[]> {
@ -124,6 +121,4 @@ export class WithLayoutSourceState extends WithSelectedElementState {
this.featureProperties.trackFeature(feature)
this.selectedElement.setData(feature)
}
}

View file

@ -30,7 +30,7 @@ export class WithSearchState extends WithVisualFeedbackState {
metaTags: this.userRelatedState.preferencesAsTags,
onClick: (feature) => {
this.searchState.clickedOnMap(feature)
}
},
}
new ShowDataLayer(this.map, options)
}
@ -39,17 +39,12 @@ export class WithSearchState extends WithVisualFeedbackState {
private initHotkeysSearch() {
const docs = Translations.t.hotkeyDocumentation
Hotkeys.RegisterHotkey(
{ ctrl: "F" },
docs.selectSearch,
() => {
this.searchState.feedback.set(undefined)
this.searchState.searchIsFocused.set(true)
}
)
Hotkeys.RegisterHotkey({ ctrl: "F" }, docs.selectSearch, () => {
this.searchState.feedback.set(undefined)
this.searchState.searchIsFocused.set(true)
})
Hotkeys.RegisterHotkey({ nomod: "Escape", onUp: true }, docs.closeSidebar, () => {
if (this.guistate.closeAll()) {
return
}
@ -59,7 +54,5 @@ export class WithSearchState extends WithVisualFeedbackState {
Zoomcontrol.resetzoom()
this.focusOnMap()
})
}
}

View file

@ -13,12 +13,13 @@ import { GeocodeResult } from "../../Logic/Search/GeocodingProvider"
* No GUI stuff
*/
export class WithSelectedElementState extends UserMapFeatureswitchState {
readonly selectedElement: UIEventSource<Feature>
constructor(theme: ThemeConfig) {
const selectedElement = new UIEventSource<Feature | undefined>(undefined, "Selected element")
const selectedElement = new UIEventSource<Feature | undefined>(
undefined,
"Selected element"
)
super(theme, selectedElement)
this.selectedElement = selectedElement
this.selectedElement.addCallback((selected) => {
@ -34,7 +35,6 @@ export class WithSelectedElementState extends UserMapFeatureswitchState {
this.setSelectedElement(lastClick.nearestFeature)
})
// Add the selected element to the recently visited history
this.selectedElement.addCallbackD((selected) => {
const [osm_type, osm_id] = selected.properties.id.split("/")
@ -47,7 +47,7 @@ export class WithSelectedElementState extends UserMapFeatureswitchState {
selected?.properties?.local_name,
layer?.title.GetRenderValue(selected?.properties ?? {}).txt,
selected.properties.display_name,
selected.properties.id
selected.properties.id,
]
const r = <GeocodeResult>{
feature: selected,
@ -55,11 +55,10 @@ export class WithSelectedElementState extends UserMapFeatureswitchState {
osm_id,
osm_type,
lon,
lat
lat,
}
this.userRelatedState.recentlyVisitedSearch.add(r)
})
}
protected setSelectedElement(feature: Feature) {
@ -73,6 +72,4 @@ export class WithSelectedElementState extends UserMapFeatureswitchState {
}
this.selectedElement.setData(feature)
}
}

View file

@ -18,12 +18,11 @@ import { Store, UIEventSource } from "../../Logic/UIEventSource"
import NearbyFeatureSource from "../../Logic/FeatureSource/Sources/NearbyFeatureSource"
import {
SummaryTileSource,
SummaryTileSourceRewriter
SummaryTileSourceRewriter,
} from "../../Logic/FeatureSource/TiledFeatureSource/SummaryTileSource"
import { ShowDataLayerOptions } from "../../UI/Map/ShowDataLayerOptions"
export class WithSpecialLayers extends WithChangesState {
readonly favourites: FavouritesFeatureSource
/**
* When hovering (in the popup) an image, the location of the image will be revealed on the main map.
@ -42,7 +41,6 @@ export class WithSpecialLayers extends WithChangesState {
*/
readonly visualFeedbackViewportBounds: UIEventSource<BBox> = new UIEventSource<BBox>(undefined)
constructor(theme: ThemeConfig, mvtAvailableLayers: Store<Set<string>>) {
super(theme, mvtAvailableLayers)
@ -57,7 +55,7 @@ export class WithSpecialLayers extends WithChangesState {
bounds: this.visualFeedbackViewportBounds.map(
(bounds) => bounds ?? this.mapProperties.bounds?.data,
[this.mapProperties.bounds]
)
),
}
)
this.closestFeatures.registerSource(this.favourites, "favourite")
@ -85,11 +83,8 @@ export class WithSpecialLayers extends WithChangesState {
})
}
}
}
private setupSummaryLayer(): SummaryTileSourceRewriter | undefined {
/**
* MaxZoom for the summary layer
@ -113,17 +108,20 @@ export class WithSpecialLayers extends WithChangesState {
this.mapProperties.zoom.map((z) => Math.max(Math.floor(z), 0)),
this.mapProperties,
{
isActive: this.mapProperties.zoom.map((z) => z < maxzoom)
isActive: this.mapProperties.zoom.map((z) => z < maxzoom),
}
)
const source = new SummaryTileSourceRewriter(summaryTileSource, this.layerState.filteredLayers)
const source = new SummaryTileSourceRewriter(
summaryTileSource,
this.layerState.filteredLayers
)
new ShowDataLayer(this.map, {
features: source,
layer: new LayerConfig(<LayerConfigJson>summaryLayer, "summaryLayer"),
// doShowLayer: this.mapProperties.zoom.map((z) => z < maxzoom),
selectedElement: this.selectedElement
selectedElement: this.selectedElement,
})
return source
}
@ -139,7 +137,7 @@ export class WithSpecialLayers extends WithChangesState {
doShowLayer: flayer.isDisplayed,
layer: flayer.layerDef,
metaTags: this.userRelatedState.preferencesAsTags,
selectedElement: this.selectedElement
selectedElement: this.selectedElement,
}
new ShowDataLayer(this.map, options)
}
@ -154,14 +152,14 @@ export class WithSpecialLayers extends WithChangesState {
lastClickLayerConfig.isShown === undefined
? source
: source.features.mapD((fs) =>
fs.filter((f) => {
const matches = lastClickLayerConfig.isShown.matchesProperties(
f.properties
)
console.debug("LastClick ", f, "matches", matches)
return matches
})
)
fs.filter((f) => {
const matches = lastClickLayerConfig.isShown.matchesProperties(
f.properties
)
console.debug("LastClick ", f, "matches", matches)
return matches
})
)
// show last click = new point/note marker
const features = new StaticFeatureSource(lastClickFiltered)
this.featureProperties.trackFeatureSource(features)
@ -175,9 +173,9 @@ export class WithSpecialLayers extends WithChangesState {
}
this.map.data.flyTo({
zoom: Constants.minZoomLevelToAddNewPoint,
center: GeoOperations.centerpointCoordinates(feature)
center: GeoOperations.centerpointCoordinates(feature),
})
}
},
})
}
@ -189,15 +187,17 @@ export class WithSpecialLayers extends WithChangesState {
}
private drawSpecialLayers() {
type AddedByDefaultTypes = (typeof Constants.added_by_default)[number]
type LayersToAdd = "current_view" | Exclude<AddedByDefaultTypes,
"search" // Handled by WithSearchState
| "last_click" // handled by this.drawLastClick()
| "summary" // handled by setupSummaryLayer
| "range" // handled by UserMapFeatureSwitchState
| "selected_element" // handled by this.drawSelectedElement
>
type LayersToAdd =
| "current_view"
| Exclude<
AddedByDefaultTypes,
| "search" // Handled by WithSearchState
| "last_click" // handled by this.drawLastClick()
| "summary" // handled by setupSummaryLayer
| "range" // handled by UserMapFeatureSwitchState
| "selected_element" // handled by this.drawSelectedElement
>
const empty = []
/**
* A listing which maps the layerId onto the featureSource
@ -209,15 +209,13 @@ export class WithSpecialLayers extends WithChangesState {
gps_track: this.geolocation.historicalUserLocationsTrack,
current_view: this.currentView,
favourite: this.favourites,
geocoded_image: new StaticFeatureSource(this.geocodedImages)
geocoded_image: new StaticFeatureSource(this.geocodedImages),
}
// enumerate all 'normal' layers and match them with the appropriate 'special' layer - if applicable
this.layerState.filteredLayers.forEach((flayer) => {
this.registerSpecialLayer(flayer, specialLayers[flayer.layerDef.id])
})
}
private initActorsSpecialLayers() {
@ -230,5 +228,4 @@ export class WithSpecialLayers extends WithChangesState {
}
})
}
}

View file

@ -27,7 +27,11 @@ export class WithUserRelatedState {
{
// Some weird setups
Utils.initDomPurify()
if (!Utils.runningFromConsole && theme.customCss !== undefined && window.location.pathname.indexOf("theme") >= 0) {
if (
!Utils.runningFromConsole &&
theme.customCss !== undefined &&
window.location.pathname.indexOf("theme") >= 0
) {
Utils.LoadCustomCss(theme.customCss)
}
}
@ -40,7 +44,7 @@ export class WithUserRelatedState {
"oauth_token",
undefined,
"Used to complete the login"
)
),
})
this.featureSwitchIsTesting = this.featureSwitches.featureSwitchIsTesting
@ -61,7 +65,7 @@ export class WithUserRelatedState {
icon: th.icon,
title: th.title.translations,
shortDescription: th.shortDescription.translations,
layers: th.layers.filter((l) => l.isNormal()).map((l) => l.id)
layers: th.layers.filter((l) => l.isNormal()).map((l) => l.id),
})
}
@ -103,5 +107,4 @@ export class WithUserRelatedState {
}
return this.theme.getMatchingLayer(properties)
}
}

View file

@ -35,7 +35,6 @@ export class WithVisualFeedbackState extends ThemeViewState {
})
}
/**
* Selects the feature that is 'i' closest to the map center
*/
@ -65,7 +64,7 @@ export class WithVisualFeedbackState extends ThemeViewState {
Hotkeys.RegisterHotkey(
{
nomod: " ",
onUp: true
onUp: true,
},
docs.selectItem,
() => {
@ -97,12 +96,11 @@ export class WithVisualFeedbackState extends ThemeViewState {
Hotkeys.RegisterHotkey(
{
nomod: "" + i,
onUp: true
onUp: true,
},
doc,
() => this.selectClosestAtCenter(i - 1)
)
}
}
}