forked from MapComplete/MapComplete
Add a personal, configurable quest
This commit is contained in:
parent
9c42839f01
commit
7ec00a3301
21 changed files with 376 additions and 237 deletions
|
@ -3,35 +3,29 @@ import {State} from "../State";
|
|||
export class CustomLayersState {
|
||||
static RemoveFavouriteLayer(layer: string) {
|
||||
|
||||
State.state.GetFilteredLayerFor(layer)?.isDisplayed?.setData(false);
|
||||
|
||||
const favs = State.state.favourteLayers.data;
|
||||
const ind = favs.indexOf(layer);
|
||||
if (ind < 0) {
|
||||
return;
|
||||
}
|
||||
console.log("REmovign fav layer", layer);
|
||||
|
||||
favs.splice(ind, 1);
|
||||
State.state.favourteLayers.ping();
|
||||
|
||||
|
||||
const osmConnection = State.state.osmConnection;
|
||||
const count = osmConnection.GetPreference("mapcomplete-custom-layer-count");
|
||||
if (favs.length === 0) {
|
||||
count.setData("0")
|
||||
} else if (count.data === undefined || isNaN(Number(count.data))) {
|
||||
count.data = "0";
|
||||
}
|
||||
const lastId = Number(count.data);
|
||||
|
||||
for (let i = 0; i < lastId; i++) {
|
||||
for (let i = 0; i < favs.length; i++) {
|
||||
const layerIDescr = osmConnection.GetPreference("mapcomplete-custom-layer-" + i);
|
||||
if (layerIDescr.data === layer) {
|
||||
// We found the value to remove - mark with a tombstone
|
||||
layerIDescr.setData("-");
|
||||
return;
|
||||
}
|
||||
layerIDescr.setData(favs[i]);
|
||||
}
|
||||
count.setData("" + favs.length)
|
||||
}
|
||||
|
||||
static AddFavouriteLayer(layer: string) {
|
||||
State.state.GetFilteredLayerFor(layer)?.isDisplayed?.setData(true);
|
||||
|
||||
const favs = State.state.favourteLayers.data;
|
||||
const ind = favs.indexOf(layer);
|
||||
if (ind >= 0) {
|
||||
|
@ -39,7 +33,6 @@ export class CustomLayersState {
|
|||
}
|
||||
console.log("Adding fav layer", layer);
|
||||
favs.push(layer);
|
||||
State.state.favourteLayers.ping();
|
||||
|
||||
|
||||
const osmConnection = State.state.osmConnection;
|
||||
|
@ -51,7 +44,7 @@ export class CustomLayersState {
|
|||
|
||||
for (let i = 0; i < lastId; i++) {
|
||||
const layerIDescr = osmConnection.GetPreference("mapcomplete-custom-layer-" + i);
|
||||
if (layerIDescr.data === undefined || layerIDescr.data === "-") {
|
||||
if (layerIDescr.data === undefined || layerIDescr.data === "") {
|
||||
// An earlier item was removed -> overwrite it
|
||||
layerIDescr.setData(layer);
|
||||
count.ping();
|
||||
|
@ -65,12 +58,13 @@ export class CustomLayersState {
|
|||
count.setData((lastId + 1) + "");
|
||||
}
|
||||
|
||||
static InitFavouriteLayer() {
|
||||
const osmConnection = State.state.osmConnection;
|
||||
static InitFavouriteLayers(state: State) {
|
||||
const osmConnection = state.osmConnection;
|
||||
const count = osmConnection.GetPreference("mapcomplete-custom-layer-count");
|
||||
const favs = State.state.favourteLayers.data;
|
||||
const favs = state.favourteLayers.data;
|
||||
let changed = false;
|
||||
count.addCallback((countStr) => {
|
||||
console.log("UPdating favourites")
|
||||
if (countStr === undefined) {
|
||||
return;
|
||||
}
|
||||
|
@ -80,13 +74,13 @@ export class CustomLayersState {
|
|||
}
|
||||
for (let i = 0; i < countI; i++) {
|
||||
const layerId = osmConnection.GetPreference("mapcomplete-custom-layer-" + i).data;
|
||||
if (layerId !== undefined && layerId !== "-" && favs.indexOf(layerId) < 0) {
|
||||
State.state.favourteLayers.data.push(layerId);
|
||||
if (layerId !== undefined && layerId !== "" && favs.indexOf(layerId) < 0) {
|
||||
state.favourteLayers.data.push(layerId);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (changed) {
|
||||
State.state.favourteLayers.ping();
|
||||
state.favourteLayers.ping();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue