forked from MapComplete/MapComplete
Small fixes after feedback
This commit is contained in:
parent
6f70dc702e
commit
4da6070b28
3 changed files with 19 additions and 3 deletions
|
@ -7,6 +7,7 @@ import {FeatureSourceForLayer} from "../FeatureSource";
|
||||||
|
|
||||||
export default class SaveTileToLocalStorageActor {
|
export default class SaveTileToLocalStorageActor {
|
||||||
public static readonly storageKey: string = "cached-features";
|
public static readonly storageKey: string = "cached-features";
|
||||||
|
public static readonly formatVersion : string = "1"
|
||||||
|
|
||||||
constructor(source: FeatureSourceForLayer, tileIndex: number) {
|
constructor(source: FeatureSourceForLayer, tileIndex: number) {
|
||||||
source.features.addCallbackAndRunD(features => {
|
source.features.addCallbackAndRunD(features => {
|
||||||
|
@ -20,6 +21,7 @@ export default class SaveTileToLocalStorageActor {
|
||||||
try {
|
try {
|
||||||
localStorage.setItem(key, JSON.stringify(features));
|
localStorage.setItem(key, JSON.stringify(features));
|
||||||
localStorage.setItem(key + "-time", JSON.stringify(now))
|
localStorage.setItem(key + "-time", JSON.stringify(now))
|
||||||
|
localStorage.setItem(key+"-format", SaveTileToLocalStorageActor.formatVersion)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("Could not save the features to local storage:", e)
|
console.warn("Could not save the features to local storage:", e)
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,8 +32,18 @@ public tileFreshness : Map<number, Date> = new Map<number, Date>()
|
||||||
|
|
||||||
console.debug("Layer", layer.layerDef.id, "has following tiles in available in localstorage", indexes.map(i => Tiles.tile_from_index(i).join("/")).join(", "))
|
console.debug("Layer", layer.layerDef.id, "has following tiles in available in localstorage", indexes.map(i => Tiles.tile_from_index(i).join("/")).join(", "))
|
||||||
for (const index of indexes) {
|
for (const index of indexes) {
|
||||||
const prefix = SaveTileToLocalStorageActor.storageKey + "-" + layer.layerDef.id + "-" +index+"-time";
|
|
||||||
const data = Number(localStorage.getItem(prefix))
|
const prefix = SaveTileToLocalStorageActor.storageKey + "-" + layer.layerDef.id + "-" +index;
|
||||||
|
const version = localStorage.getItem(prefix+"-format")
|
||||||
|
if(version === undefined || version !== SaveTileToLocalStorageActor.formatVersion){
|
||||||
|
// Invalid version! Remove this tile from local storage
|
||||||
|
localStorage.removeItem(prefix)
|
||||||
|
undefinedTiles.add(index)
|
||||||
|
console.log("Dropped old format tile", prefix)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = Number(localStorage.getItem(prefix+"-time"))
|
||||||
const freshness = new Date()
|
const freshness = new Date()
|
||||||
freshness.setTime(data)
|
freshness.setTime(data)
|
||||||
this.tileFreshness.set(index, freshness)
|
this.tileFreshness.set(index, freshness)
|
||||||
|
|
|
@ -35,6 +35,10 @@
|
||||||
"startLon": 3.2228,
|
"startLon": 3.2228,
|
||||||
"maintainer": "MapComplete",
|
"maintainer": "MapComplete",
|
||||||
"widenfactor": 2,
|
"widenfactor": 2,
|
||||||
|
"clustering": {
|
||||||
|
"maxZoom": 12,
|
||||||
|
"minNeededElements": 200
|
||||||
|
},
|
||||||
"roamingRenderings": [
|
"roamingRenderings": [
|
||||||
{
|
{
|
||||||
"question": {
|
"question": {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue