forked from MapComplete/MapComplete
Full code cleanup
This commit is contained in:
parent
3a4a2a2016
commit
fa971ffbbf
300 changed files with 16352 additions and 19284 deletions
|
@ -11,7 +11,7 @@ export default class ChangeLocationAction extends OsmChangeAction {
|
|||
theme: string,
|
||||
reason: string
|
||||
}) {
|
||||
super(id,true);
|
||||
super(id, true);
|
||||
if (!id.startsWith("node/")) {
|
||||
throw "Invalid ID: only 'node/number' is accepted"
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ export default class ChangeLocationAction extends OsmChangeAction {
|
|||
this._newLonLat = newLonLat;
|
||||
this._meta = meta;
|
||||
}
|
||||
|
||||
|
||||
protected async CreateChangeDescriptions(changes: Changes): Promise<ChangeDescription[]> {
|
||||
|
||||
const d: ChangeDescription = {
|
||||
|
|
|
@ -19,7 +19,7 @@ export default class ChangeTagAction extends OsmChangeAction {
|
|||
this._currentTags = currentTags;
|
||||
this._meta = meta;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Doublechecks that no stupid values are added
|
||||
*/
|
||||
|
|
|
@ -14,35 +14,36 @@ import {TagUtils} from "../../Tags/TagUtils";
|
|||
* More or less the same as 'CreateNewWay', except that it'll try to reuse already existing points
|
||||
*/
|
||||
export default class CreateMultiPolygonWithPointReuseAction extends OsmCreateAction {
|
||||
private readonly _tags: Tag[];
|
||||
public newElementId: string = undefined;
|
||||
public newElementIdNumber: number = undefined;
|
||||
public newElementIdNumber: number = undefined;
|
||||
private readonly _tags: Tag[];
|
||||
private readonly createOuterWay: CreateWayWithPointReuseAction
|
||||
private readonly createInnerWays : CreateNewWayAction[]
|
||||
private readonly geojsonPreview: any;
|
||||
private readonly createInnerWays: CreateNewWayAction[]
|
||||
private readonly geojsonPreview: any;
|
||||
private readonly theme: string;
|
||||
private readonly changeType: "import" | "create" | string;
|
||||
|
||||
constructor(tags: Tag[],
|
||||
outerRingCoordinates: [number, number][],
|
||||
innerRingsCoordinates: [number, number][][],
|
||||
innerRingsCoordinates: [number, number][][],
|
||||
state: FeaturePipelineState,
|
||||
config: MergePointConfig[],
|
||||
changeType: "import" | "create" | string
|
||||
) {
|
||||
super(null,true);
|
||||
this._tags = [...tags, new Tag("type","multipolygon")];
|
||||
super(null, true);
|
||||
this._tags = [...tags, new Tag("type", "multipolygon")];
|
||||
this.changeType = changeType;
|
||||
this.theme = state.layoutToUse.id
|
||||
this. createOuterWay = new CreateWayWithPointReuseAction([], outerRingCoordinates, state, config)
|
||||
this. createInnerWays = innerRingsCoordinates.map(ringCoordinates =>
|
||||
new CreateNewWayAction([],
|
||||
ringCoordinates.map(([lon, lat] )=> ({lat, lon})),
|
||||
{theme: state.layoutToUse.id}))
|
||||
|
||||
this.geojsonPreview = {
|
||||
this.createOuterWay = new CreateWayWithPointReuseAction([], outerRingCoordinates, state, config)
|
||||
this.createInnerWays = innerRingsCoordinates.map(ringCoordinates =>
|
||||
new CreateNewWayAction([],
|
||||
ringCoordinates.map(([lon, lat]) => ({lat, lon})),
|
||||
{theme: state.layoutToUse.id}))
|
||||
|
||||
this.geojsonPreview = {
|
||||
type: "Feature",
|
||||
properties: TagUtils.changeAsProperties(new And(this._tags).asChange({})),
|
||||
geometry:{
|
||||
geometry: {
|
||||
type: "Polygon",
|
||||
coordinates: [
|
||||
outerRingCoordinates,
|
||||
|
@ -59,7 +60,7 @@ private readonly geojsonPreview: any;
|
|||
freshness: new Date(),
|
||||
feature: this.geojsonPreview
|
||||
})
|
||||
return outerPreview
|
||||
return outerPreview
|
||||
}
|
||||
|
||||
protected async CreateChangeDescriptions(changes: Changes): Promise<ChangeDescription[]> {
|
||||
|
@ -72,14 +73,14 @@ private readonly geojsonPreview: any;
|
|||
|
||||
|
||||
this.newElementIdNumber = changes.getNewID();
|
||||
this.newElementId = "relation/"+this.newElementIdNumber
|
||||
this.newElementId = "relation/" + this.newElementIdNumber
|
||||
descriptions.push({
|
||||
type:"relation",
|
||||
type: "relation",
|
||||
id: this.newElementIdNumber,
|
||||
tags: new And(this._tags).asChange({}),
|
||||
meta: {
|
||||
theme: this.theme,
|
||||
changeType:this.changeType
|
||||
changeType: this.changeType
|
||||
},
|
||||
changes: {
|
||||
members: [
|
||||
|
@ -93,8 +94,8 @@ private readonly geojsonPreview: any;
|
|||
]
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
return descriptions
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ export default class CreateNewNodeAction extends OsmCreateAction {
|
|||
changeType: "create" | "import" | null,
|
||||
specialMotivation?: string
|
||||
}) {
|
||||
super(null,basicTags !== undefined && basicTags.length > 0)
|
||||
super(null, basicTags !== undefined && basicTags.length > 0)
|
||||
this._basicTags = basicTags;
|
||||
this._lat = lat;
|
||||
this._lon = lon;
|
||||
|
@ -46,7 +46,7 @@ export default class CreateNewNodeAction extends OsmCreateAction {
|
|||
this.meta = {
|
||||
theme: options.theme,
|
||||
changeType: options.changeType,
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ export default class CreateNewWayAction extends OsmCreateAction {
|
|||
options: {
|
||||
theme: string
|
||||
}) {
|
||||
super(null,true)
|
||||
super(null, true)
|
||||
this.coordinates = coordinates;
|
||||
this.tags = tags;
|
||||
this._options = options;
|
||||
|
@ -56,7 +56,7 @@ export default class CreateNewWayAction extends OsmCreateAction {
|
|||
|
||||
|
||||
const id = changes.getNewID()
|
||||
this.newElementIdNumber = id
|
||||
this.newElementIdNumber = id
|
||||
const newWay = <ChangeDescription>{
|
||||
id,
|
||||
type: "way",
|
||||
|
|
|
@ -20,14 +20,14 @@ export interface MergePointConfig {
|
|||
|
||||
/**
|
||||
* CreateWayWithPointreuse will create a 'CoordinateInfo' for _every_ point in the way to be created.
|
||||
*
|
||||
*
|
||||
* The CoordinateInfo indicates the action to take, e.g.:
|
||||
*
|
||||
*
|
||||
* - Create a new point
|
||||
* - Reuse an existing OSM point (and don't move it)
|
||||
* - Reuse an existing OSM point (and leave it where it is)
|
||||
* - Reuse another Coordinate info (and don't do anything else with it)
|
||||
*
|
||||
*
|
||||
*/
|
||||
interface CoordinateInfo {
|
||||
/**
|
||||
|
@ -56,6 +56,8 @@ interface CoordinateInfo {
|
|||
* More or less the same as 'CreateNewWay', except that it'll try to reuse already existing points
|
||||
*/
|
||||
export default class CreateWayWithPointReuseAction extends OsmCreateAction {
|
||||
public newElementId: string = undefined;
|
||||
public newElementIdNumber: number = undefined
|
||||
private readonly _tags: Tag[];
|
||||
/**
|
||||
* lngLat-coordinates
|
||||
|
@ -64,20 +66,17 @@ export default class CreateWayWithPointReuseAction extends OsmCreateAction {
|
|||
private _coordinateInfo: CoordinateInfo[];
|
||||
private _state: FeaturePipelineState;
|
||||
private _config: MergePointConfig[];
|
||||
|
||||
public newElementId: string = undefined;
|
||||
public newElementIdNumber: number = undefined
|
||||
|
||||
constructor(tags: Tag[],
|
||||
coordinates: [number, number][],
|
||||
state: FeaturePipelineState,
|
||||
config: MergePointConfig[]
|
||||
) {
|
||||
super(null,true);
|
||||
super(null, true);
|
||||
this._tags = tags;
|
||||
this._state = state;
|
||||
this._config = config;
|
||||
|
||||
|
||||
// The main logic of this class: the coordinateInfo contains all the changes
|
||||
this._coordinateInfo = this.CalculateClosebyNodes(coordinates);
|
||||
|
||||
|
@ -117,7 +116,7 @@ export default class CreateWayWithPointReuseAction extends OsmCreateAction {
|
|||
"move": "yes",
|
||||
"osm-id": reusedPoint.node.properties.id,
|
||||
"id": "new-geometry-move-existing" + i,
|
||||
"distance":GeoOperations.distanceBetween(coordinateInfo.lngLat, reusedPoint.node.geometry.coordinates)
|
||||
"distance": GeoOperations.distanceBetween(coordinateInfo.lngLat, reusedPoint.node.geometry.coordinates)
|
||||
},
|
||||
geometry: {
|
||||
type: "LineString",
|
||||
|
@ -136,7 +135,7 @@ export default class CreateWayWithPointReuseAction extends OsmCreateAction {
|
|||
"move": "no",
|
||||
"osm-id": reusedPoint.node.properties.id,
|
||||
"id": "new-geometry-reuse-existing" + i,
|
||||
"distance":GeoOperations.distanceBetween(coordinateInfo.lngLat, reusedPoint.node.geometry.coordinates)
|
||||
"distance": GeoOperations.distanceBetween(coordinateInfo.lngLat, reusedPoint.node.geometry.coordinates)
|
||||
},
|
||||
geometry: {
|
||||
type: "LineString",
|
||||
|
@ -238,7 +237,7 @@ export default class CreateWayWithPointReuseAction extends OsmCreateAction {
|
|||
const newWay = new CreateNewWayAction(this._tags, nodeIdsToUse, {
|
||||
theme
|
||||
})
|
||||
|
||||
|
||||
allChanges.push(...(await newWay.CreateChangeDescriptions(changes)))
|
||||
this.newElementId = newWay.newElementId
|
||||
this.newElementIdNumber = newWay.newElementIdNumber
|
||||
|
@ -266,7 +265,7 @@ export default class CreateWayWithPointReuseAction extends OsmCreateAction {
|
|||
}[]
|
||||
}[] = coordinates.map(_ => undefined)
|
||||
|
||||
|
||||
|
||||
// First loop: gather all information...
|
||||
for (let i = 0; i < coordinates.length; i++) {
|
||||
|
||||
|
@ -328,7 +327,7 @@ export default class CreateWayWithPointReuseAction extends OsmCreateAction {
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Second loop: figure out which point moves where without creating conflicts
|
||||
let conflictFree = true;
|
||||
do {
|
||||
|
@ -348,8 +347,8 @@ export default class CreateWayWithPointReuseAction extends OsmCreateAction {
|
|||
if (other.closebyNodes === undefined || other.closebyNodes[0] === undefined) {
|
||||
continue
|
||||
}
|
||||
|
||||
if(coorInfo.closebyNodes[0] === undefined){
|
||||
|
||||
if (coorInfo.closebyNodes[0] === undefined) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ export default class DeleteAction extends OsmChangeAction {
|
|||
specialMotivation: string
|
||||
},
|
||||
hardDelete: boolean) {
|
||||
super(id,true)
|
||||
super(id, true)
|
||||
this._id = id;
|
||||
this._hardDelete = hardDelete;
|
||||
this.meta = {...meta, changeType: "deletion"};
|
||||
|
@ -51,7 +51,7 @@ export default class DeleteAction extends OsmChangeAction {
|
|||
return await new ChangeTagAction(
|
||||
this._id, this._softDeletionTags, osmObject.tags,
|
||||
{
|
||||
... this.meta,
|
||||
...this.meta,
|
||||
changeType: "soft-delete"
|
||||
}
|
||||
).CreateChangeDescriptions(changes)
|
||||
|
|
|
@ -7,7 +7,6 @@ import {ChangeDescription} from "./ChangeDescription";
|
|||
|
||||
export default abstract class OsmChangeAction {
|
||||
|
||||
private isUsed = false
|
||||
public readonly trackStatistics: boolean;
|
||||
/**
|
||||
* The ID of the object that is the center of this change.
|
||||
|
@ -15,7 +14,8 @@ export default abstract class OsmChangeAction {
|
|||
* Undefined if such an id does not make sense
|
||||
*/
|
||||
public readonly mainObjectId: string;
|
||||
|
||||
private isUsed = false
|
||||
|
||||
constructor(mainObjectId: string, trackStatistics: boolean = true) {
|
||||
this.trackStatistics = trackStatistics;
|
||||
this.mainObjectId = mainObjectId
|
||||
|
@ -32,9 +32,9 @@ export default abstract class OsmChangeAction {
|
|||
protected abstract CreateChangeDescriptions(changes: Changes): Promise<ChangeDescription[]>
|
||||
}
|
||||
|
||||
export abstract class OsmCreateAction extends OsmChangeAction{
|
||||
export abstract class OsmCreateAction extends OsmChangeAction {
|
||||
|
||||
public newElementId : string
|
||||
public newElementId: string
|
||||
public newElementIdNumber: number
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -16,10 +16,11 @@ abstract class AbstractRelationSplitHandler extends OsmChangeAction {
|
|||
protected readonly _theme: string;
|
||||
|
||||
constructor(input: RelationSplitInput, theme: string) {
|
||||
super("relation/"+input.relation.id, false)
|
||||
super("relation/" + input.relation.id, false)
|
||||
this._input = input;
|
||||
this._theme = theme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns which node should border the member at the given index
|
||||
*/
|
||||
|
|
|
@ -468,12 +468,12 @@ export default class ReplaceGeometryAction extends OsmChangeAction {
|
|||
proj.sort((a, b) => {
|
||||
// Sort descending
|
||||
const diff = b.projectAfterIndex - a.projectAfterIndex;
|
||||
if(diff !== 0){
|
||||
if (diff !== 0) {
|
||||
return diff
|
||||
}
|
||||
return b.distance - a.distance;
|
||||
|
||||
|
||||
|
||||
|
||||
})
|
||||
|
||||
for (const reprojectedNode of proj) {
|
||||
|
|
|
@ -26,7 +26,7 @@ export default class SplitAction extends OsmChangeAction {
|
|||
* @param toleranceInMeters: if a splitpoint closer then this amount of meters to an existing point, the existing point will be used to split the line instead of a new point
|
||||
*/
|
||||
constructor(wayId: string, splitPointCoordinates: [number, number][], meta: { theme: string }, toleranceInMeters = 5) {
|
||||
super(wayId,true)
|
||||
super(wayId, true)
|
||||
this.wayId = wayId;
|
||||
this._splitPointsCoordinates = splitPointCoordinates
|
||||
this._toleranceInMeters = toleranceInMeters;
|
||||
|
|
|
@ -27,16 +27,13 @@ export class Changes {
|
|||
public features = new UIEventSource<{ feature: any, freshness: Date }[]>([]);
|
||||
public readonly pendingChanges: UIEventSource<ChangeDescription[]> = LocalStorageSource.GetParsed<ChangeDescription[]>("pending-changes", [])
|
||||
public readonly allChanges = new UIEventSource<ChangeDescription[]>(undefined)
|
||||
public readonly state: { allElements: ElementStorage; historicalUserLocations: FeatureSource; osmConnection: OsmConnection }
|
||||
public readonly extraComment: UIEventSource<string> = new UIEventSource(undefined)
|
||||
private _nextId: number = -1; // Newly assigned ID's are negative
|
||||
private readonly isUploading = new UIEventSource(false);
|
||||
|
||||
private readonly previouslyCreated: OsmObject[] = []
|
||||
private readonly _leftRightSensitive: boolean;
|
||||
|
||||
public readonly state: { allElements: ElementStorage; historicalUserLocations: FeatureSource; osmConnection: OsmConnection }
|
||||
|
||||
public readonly extraComment:UIEventSource<string> = new UIEventSource(undefined)
|
||||
|
||||
constructor(
|
||||
state?: {
|
||||
allElements: ElementStorage,
|
||||
|
@ -107,7 +104,7 @@ export class Changes {
|
|||
* Uploads all the pending changes in one go.
|
||||
* Triggered by the 'PendingChangeUploader'-actor in Actors
|
||||
*/
|
||||
public async flushChanges(flushreason: string = undefined, openChangeset?: UIEventSource<number>) : Promise<void>{
|
||||
public async flushChanges(flushreason: string = undefined, openChangeset?: UIEventSource<number>): Promise<void> {
|
||||
if (this.pendingChanges.data.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -116,19 +113,37 @@ export class Changes {
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
console.log("Uploading changes due to: ", flushreason)
|
||||
this.isUploading.setData(true)
|
||||
try {
|
||||
const csNumber = await this.flushChangesAsync(openChangeset)
|
||||
this.isUploading.setData(false)
|
||||
console.log("Changes flushed. Your changeset is "+csNumber);
|
||||
console.log("Changes flushed. Your changeset is " + csNumber);
|
||||
} catch (e) {
|
||||
this.isUploading.setData(false)
|
||||
console.error("Flushing changes failed due to", e);
|
||||
}
|
||||
}
|
||||
|
||||
public async applyAction(action: OsmChangeAction): Promise<void> {
|
||||
const changeDescriptions = await action.Perform(this)
|
||||
changeDescriptions[0].meta.distanceToObject = this.calculateDistanceToChanges(action, changeDescriptions)
|
||||
this.applyChanges(changeDescriptions)
|
||||
}
|
||||
|
||||
public applyChanges(changes: ChangeDescription[]) {
|
||||
console.log("Received changes:", changes)
|
||||
this.pendingChanges.data.push(...changes);
|
||||
this.pendingChanges.ping();
|
||||
this.allChanges.data.push(...changes)
|
||||
this.allChanges.ping()
|
||||
}
|
||||
|
||||
public registerIdRewrites(mappings: Map<string, string>): void {
|
||||
CreateNewNodeAction.registerIdRewrites(mappings)
|
||||
}
|
||||
|
||||
private calculateDistanceToChanges(change: OsmChangeAction, changeDescriptions: ChangeDescription[]) {
|
||||
|
||||
const locations = this.state?.historicalUserLocations?.features?.data
|
||||
|
@ -140,7 +155,7 @@ export class Changes {
|
|||
// Probably irrelevant, such as a new helper node
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const now = new Date()
|
||||
const recentLocationPoints = locations.map(ff => ff.feature)
|
||||
.filter(feat => feat.geometry.type === "Point")
|
||||
|
@ -188,26 +203,6 @@ export class Changes {
|
|||
))
|
||||
}
|
||||
|
||||
public async applyAction(action: OsmChangeAction): Promise<void> {
|
||||
const changeDescriptions = await action.Perform(this)
|
||||
changeDescriptions[0].meta.distanceToObject = this.calculateDistanceToChanges(action, changeDescriptions)
|
||||
this.applyChanges(changeDescriptions)
|
||||
}
|
||||
|
||||
public applyChanges(changes: ChangeDescription[]) {
|
||||
console.log("Received changes:", changes)
|
||||
this.pendingChanges.data.push(...changes);
|
||||
this.pendingChanges.ping();
|
||||
this.allChanges.data.push(...changes)
|
||||
this.allChanges.ping()
|
||||
}
|
||||
|
||||
|
||||
public registerIdRewrites(mappings: Map<string, string>): void {
|
||||
CreateNewNodeAction.registerIdRewrites(mappings)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* UPload the selected changes to OSM.
|
||||
* Returns 'true' if successfull and if they can be removed
|
||||
|
@ -287,10 +282,10 @@ export class Changes {
|
|||
// This method is only called with changedescriptions for this theme
|
||||
const theme = pending[0].meta.theme
|
||||
let comment = "Adding data with #MapComplete for theme #" + theme
|
||||
if(this.extraComment.data !== undefined){
|
||||
comment+="\n\n"+this.extraComment.data
|
||||
if (this.extraComment.data !== undefined) {
|
||||
comment += "\n\n" + this.extraComment.data
|
||||
}
|
||||
|
||||
|
||||
const metatags: ChangesetTag[] = [{
|
||||
key: "comment",
|
||||
value: comment
|
||||
|
@ -329,10 +324,10 @@ export class Changes {
|
|||
pendingPerTheme.get(theme).push(changeDescription)
|
||||
}
|
||||
|
||||
const successes = await Promise.all(Array.from(pendingPerTheme,
|
||||
async ([theme, pendingChanges]) => {
|
||||
const successes = await Promise.all(Array.from(pendingPerTheme,
|
||||
async ([theme, pendingChanges]) => {
|
||||
try {
|
||||
if(openChangeset === undefined){
|
||||
if (openChangeset === undefined) {
|
||||
openChangeset = this.state.osmConnection.GetPreference("current-open-changeset-" + theme).map(
|
||||
str => {
|
||||
const n = Number(str);
|
||||
|
@ -342,9 +337,9 @@ export class Changes {
|
|||
return n
|
||||
}, [], n => "" + n
|
||||
);
|
||||
console.log("Using current-open-changeset-"+theme+" from the preferences, got "+openChangeset.data)
|
||||
console.log("Using current-open-changeset-" + theme + " from the preferences, got " + openChangeset.data)
|
||||
}
|
||||
|
||||
|
||||
return await self.flushSelectChanges(pendingChanges, openChangeset);
|
||||
} catch (e) {
|
||||
console.error("Could not upload some changes:", e)
|
||||
|
@ -395,7 +390,7 @@ export class Changes {
|
|||
// Might be a failed fetch for simply this object
|
||||
throw "Did not get an object that should be known: " + id
|
||||
}
|
||||
if(change.changes === undefined){
|
||||
if (change.changes === undefined) {
|
||||
// This object is a change to a newly created object. However, we have not seen the creation changedescription yet!
|
||||
throw "Not a creation of the object"
|
||||
}
|
||||
|
@ -522,7 +517,7 @@ export class Changes {
|
|||
|
||||
})
|
||||
|
||||
console.debug("Calculated the pending changes: ", result.newObjects.length,"new; ", result.modifiedObjects.length,"modified;",result.deletedObjects,"deleted")
|
||||
console.debug("Calculated the pending changes: ", result.newObjects.length, "new; ", result.modifiedObjects.length, "modified;", result.deletedObjects, "deleted")
|
||||
return result
|
||||
}
|
||||
}
|
|
@ -61,7 +61,7 @@ export class ChangesetHandler {
|
|||
if (!extraMetaTags.some(tag => tag.key === "comment") || !extraMetaTags.some(tag => tag.key === "theme")) {
|
||||
throw "The meta tags should at least contain a `comment` and a `theme`"
|
||||
}
|
||||
|
||||
|
||||
if (this.userDetails.data.csCount == 0) {
|
||||
// The user became a contributor!
|
||||
this.userDetails.data.csCount = 1;
|
||||
|
|
|
@ -122,6 +122,34 @@ export class OsmPreferences {
|
|||
return pref;
|
||||
}
|
||||
|
||||
public ClearPreferences() {
|
||||
let isRunning = false;
|
||||
const self = this;
|
||||
this.preferences.addCallbackAndRun(prefs => {
|
||||
if (Object.keys(prefs).length == 0) {
|
||||
return;
|
||||
}
|
||||
if (isRunning) {
|
||||
return
|
||||
}
|
||||
isRunning = true
|
||||
const prefixes = ["mapcomplete-installed-theme", "mapcomplete-installed-themes-", "mapcomplete-current-open-changeset", "mapcomplete-personal-theme-layer"]
|
||||
for (const key in prefs) {
|
||||
for (const prefix of prefixes) {
|
||||
// console.log(key)
|
||||
if (key.startsWith(prefix)) {
|
||||
console.log("Clearing ", key)
|
||||
self.GetPreference(key, "").setData("")
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
isRunning = false;
|
||||
return true;
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
private UpdatePreferences() {
|
||||
const self = this;
|
||||
this.auth.xhr({
|
||||
|
@ -184,34 +212,6 @@ export class OsmPreferences {
|
|||
console.debug(`Preference ${k} written!`);
|
||||
});
|
||||
}
|
||||
|
||||
public ClearPreferences(){
|
||||
let isRunning = false;
|
||||
const self = this;
|
||||
this.preferences.addCallbackAndRun(prefs => {
|
||||
if(Object.keys(prefs).length == 0){
|
||||
return;
|
||||
}
|
||||
if (isRunning) {
|
||||
return
|
||||
}
|
||||
isRunning = true
|
||||
const prefixes = ["mapcomplete-installed-theme","mapcomplete-installed-themes-","mapcomplete-current-open-changeset","mapcomplete-personal-theme-layer"]
|
||||
for (const key in prefs) {
|
||||
for (const prefix of prefixes) {
|
||||
// console.log(key)
|
||||
if (key.startsWith(prefix)) {
|
||||
console.log("Clearing ", key)
|
||||
self.GetPreference(key, "").setData("")
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
isRunning = false;
|
||||
return true;
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue