Frontend part of the tiles caching

This commit is contained in:
Lucas Verney 2018-11-01 19:26:27 +01:00
parent 07edf2bd02
commit 068bcdbfc6
4 changed files with 58 additions and 1 deletions

View File

@ -73,6 +73,7 @@ if (process.env.MAPTILER_API_KEY) {
}; };
} }
export const DEFAULT_TILE_SERVER = 'cartodb-voyager'; export const DEFAULT_TILE_SERVER = 'cartodb-voyager';
export const DEFAULT_TILE_CACHING_DURATION = -1;
export const GEOCODING_API_ENDPOINT = 'https://api-adresse.data.gouv.fr/search/'; export const GEOCODING_API_ENDPOINT = 'https://api-adresse.data.gouv.fr/search/';

View File

@ -118,10 +118,13 @@
"customTileServer": "Custom tile server", "customTileServer": "Custom tile server",
"customTileServerURL": "Custom tile server URL", "customTileServerURL": "Custom tile server URL",
"customTileServerURLHint": "For example: http://tile.thunderforest.com/cycle/{z}/{x}/{y}.png", "customTileServerURLHint": "For example: http://tile.thunderforest.com/cycle/{z}/{x}/{y}.png",
"defaultDuration": "Default duration",
"defaultOrientationMode": "Default orientation mode", "defaultOrientationMode": "Default orientation mode",
"fixedNorth": "Fixed (North up)", "fixedNorth": "Fixed (North up)",
"locale": "Language", "locale": "Language",
"noCaching": "No caching",
"skipOnboarding": "Skip onboarding", "skipOnboarding": "Skip onboarding",
"tileCachingDuration": "Cache map tiles for",
"tileServer": "Map tiles server" "tileServer": "Map tiles server"
}, },
"shareMapViewModal": { "shareMapViewModal": {

View File

@ -2,7 +2,12 @@ import Vue from 'vue';
import { messages, getBrowserLocales } from '@/i18n'; import { messages, getBrowserLocales } from '@/i18n';
import { storageAvailable } from '@/tools'; import { storageAvailable } from '@/tools';
import { DEFAULT_TILE_SERVER, TILE_SERVERS, VERSION } from '@/constants'; import {
DEFAULT_TILE_CACHING_DURATION,
DEFAULT_TILE_SERVER,
TILE_SERVERS,
VERSION,
} from '@/constants';
import * as types from './mutations-types'; import * as types from './mutations-types';
function loadDataFromStorage(name) { function loadDataFromStorage(name) {
@ -50,6 +55,7 @@ let hasPreventSuspendPermission = null;
let hasVibratePermission = null; let hasVibratePermission = null;
let shouldAutorotateMap = null; let shouldAutorotateMap = null;
let skipOnboarding = null; let skipOnboarding = null;
let tileCachingDuration = null;
let tileServer = null; let tileServer = null;
if (storageAvailable('localStorage')) { if (storageAvailable('localStorage')) {
handleMigrations(); handleMigrations();
@ -67,6 +73,11 @@ if (storageAvailable('localStorage')) {
tileServer = null; tileServer = null;
} }
tileCachingDuration = loadDataFromStorage('tileCachingDuration');
if (tileCachingDuration !== null && !Number.isInteger(tileCachingDuration)) {
tileCachingDuration = null;
}
locale = loadDataFromStorage('locale'); locale = loadDataFromStorage('locale');
if (!(locale in messages)) { if (!(locale in messages)) {
locale = null; locale = null;
@ -123,6 +134,9 @@ export const initialState = {
), ),
shouldAutorotateMap: shouldAutorotateMap !== null ? shouldAutorotateMap : false, shouldAutorotateMap: shouldAutorotateMap !== null ? shouldAutorotateMap : false,
skipOnboarding: skipOnboarding || false, skipOnboarding: skipOnboarding || false,
tileCachingDuration: (
tileCachingDuration !== null ? tileCachingDuration : DEFAULT_TILE_CACHING_DURATION
),
tileServer: tileServer || DEFAULT_TILE_SERVER, tileServer: tileServer || DEFAULT_TILE_SERVER,
}, },
}; };

View File

@ -27,6 +27,15 @@
required required
></v-select> ></v-select>
<v-select
:items="tileCachingDurationOptions"
v-model="tileCachingDuration"
item-text="name"
item-value="duration"
:label="$t('settings.tileCachingDuration')"
required
></v-select>
<v-text-field <v-text-field
:hint="$t('settings.customTileServerURLHint')" :hint="$t('settings.customTileServerURLHint')"
:label="$t('settings.customTileServerURL')" :label="$t('settings.customTileServerURL')"
@ -51,6 +60,7 @@
<script> <script>
import { TILE_SERVERS } from '@/constants'; import { TILE_SERVERS } from '@/constants';
import { AVAILABLE_LOCALES } from '@/i18n'; import { AVAILABLE_LOCALES } from '@/i18n';
import { capitalize } from '@/tools';
import PermissionsSwitches from '@/components/PermissionsSwitches.vue'; import PermissionsSwitches from '@/components/PermissionsSwitches.vue';
@ -102,6 +112,34 @@ export default {
this.$store.dispatch('unmarkIntroAsSeen'); this.$store.dispatch('unmarkIntroAsSeen');
}, },
}, },
tileCachingDuration: {
get() {
return this.$store.state.settings.tileCachingDuration;
},
set(tileCachingDuration) {
this.$store.dispatch('setSetting', { setting: 'tileCachingDuration', value: tileCachingDuration });
},
},
tileCachingDurationOptions() {
return [
{
duration: 0,
name: this.$i18n.t('settings.noCaching'),
},
{
duration: -1,
name: this.$i18n.t('settings.defaultDuration'),
},
{
duration: 3600 * 24,
name: capitalize(this.$i18n.tc('relativeDate.day', 1, { count: 1 })),
},
{
duration: 3600 * 24 * 7,
name: capitalize(this.$i18n.tc('relativeDate.day', 7, { count: 7 })),
},
];
},
tileServer: { tileServer: {
get() { get() {
const tileServerStore = this.$store.state.settings.tileServer; const tileServerStore = this.$store.state.settings.tileServer;
@ -130,6 +168,7 @@ export default {
name: AVAILABLE_LOCALES[iso].name, name: AVAILABLE_LOCALES[iso].name,
})); }));
i18nItems.sort((a, b) => a.iso > b.iso); i18nItems.sort((a, b) => a.iso > b.iso);
return { return {
i18nItems, i18nItems,
orientationModes: [ orientationModes: [