More refactoring!

This commit is contained in:
Pieter Vander Vennet 2021-01-03 00:19:42 +01:00
parent b2c234b51d
commit 6ac8ec84e4
22 changed files with 170 additions and 158 deletions

View file

@ -0,0 +1,8 @@
import {UIEventSource} from "../UIEventSource";
export default interface FeatureSource {
features : UIEventSource<any[]>;
freshness: UIEventSource<Date>;
}

View file

@ -3,7 +3,7 @@ import {UIEventSource} from "../UIEventSource";
import {UIElement} from "../../UI/UIElement";
import {Utils} from "../../Utils";
import Svg from "../../Svg";
import {Img} from "../../UI/Img";
import Img from "../../UI/Base/Img";
export class GeoLocationHandler extends UIElement {

View file

@ -0,0 +1,55 @@
import {UIEventSource} from "../UIEventSource";
import LayoutConfig from "../../Customizations/JSON/LayoutConfig";
import {OsmConnection} from "../Osm/OsmConnection";
export default class InstalledThemes {
public installedThemes: UIEventSource<{ layout: LayoutConfig; definition: string }[]>;
constructor(osmConnection: OsmConnection) {
this.installedThemes = osmConnection.preferencesHandler.preferences.map<{ layout: LayoutConfig, definition: string }[]>(allPreferences => {
const installedThemes: { layout: LayoutConfig, definition: string }[] = [];
if (allPreferences === undefined) {
console.log("All prefs is undefined");
return installedThemes;
}
const invalidThemes = []
for (var allPreferencesKey in allPreferences) {
const themename = allPreferencesKey.match(/^mapcomplete-installed-theme-(.*)-combined-length$/);
if (themename && themename[1] !== "") {
const customLayout = osmConnection.GetLongPreference("installed-theme-" + themename[1]);
if (customLayout.data === undefined) {
console.log("No data defined for ", themename[1]);
continue;
}
try {
const json = atob(customLayout.data);
const layout = new LayoutConfig(
JSON.parse(json));
installedThemes.push({
layout: layout,
definition: customLayout.data
});
} catch (e) {
console.warn("Could not parse custom layout from preferences - deleting: ", allPreferencesKey, e, customLayout.data);
invalidThemes.push(themename[1])
}
}
}
InstalledThemes.DeleteInvalid(osmConnection, invalidThemes);
return installedThemes;
});
}
private static DeleteInvalid(osmConnection: OsmConnection, invalidThemes: any[]) {
for (const invalid of invalidThemes) {
console.error("Attempting to remove ", invalid)
osmConnection.GetLongPreference(
"installed-theme-" + invalid
).setData(null);
}
}
}

View file

@ -1,9 +1,9 @@
import * as L from "leaflet";
import {UIElement} from "../../UI/UIElement";
import {Img} from "../../UI/Img";
import Svg from "../../Svg";
import {UIEventSource} from "../UIEventSource";
import {FilteredLayer} from "../FilteredLayer";
import Img from "../../UI/Base/Img";
/**
* The stray-click-hanlders adds a marker to the map if no feature was clicked.