Skip to content

Commit

Permalink
persist state for max 1 day #34
Browse files Browse the repository at this point in the history
  • Loading branch information
peer35 committed Mar 24, 2021
1 parent 762091e commit 65b5e67
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mapviewer",
"version": "2.2.5",
"version": "2.2.6",
"private": true,
"scripts": {
"serve:kloosters": "vue-cli-service serve src/kloosters.js",
Expand Down
16 changes: 8 additions & 8 deletions src/gpz.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {get as getProjection} from 'ol/proj'
import proj4 from 'proj4';

import {getParam, hashCode} from './shared'
import {saveState} from "./helpers/ViewerDataHelpers";

proj4.defs("EPSG:28992", "+title=Amersfoort / RD New +proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +towgs84=565.417,50.3319,465.552,-0.398957,0.343988,-1.8774,4.0725 +no_defs");
register(proj4);
Expand All @@ -26,16 +27,15 @@ function getState(config) {
const key = hashCode(config.title);
config.hash=key; // only calculate once
if (!localStorage[key]) {
localStorage[key] = JSON.stringify({
'crs': config.crs,
'baselayer': config.baselayer,
'bbox': config.bbox,
});
saveState(config);
} else {
const delta = 1000 * 3600 * 24; // 1 day
const s = JSON.parse(localStorage[key]);
config.crs = s.crs;
config.baselayer = s.baselayer;
config.bbox = s.bbox;
if (Date.now() - s.updated < delta) {
config.crs = s.crs;
config.baselayer = s.baselayer;
config.bbox = s.bbox;
}
}
return config;
}
Expand Down
1 change: 1 addition & 0 deletions src/helpers/ViewerDataHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function saveState(config, olmap = null) {
'crs': config.crs,
'baselayer': config.baselayer,
'bbox': bbox,
'updated': Date.now()
}
if (typeof config.klooster !== 'undefined') {
def_config.year = config.klooster.year;
Expand Down
15 changes: 9 additions & 6 deletions src/kloosters.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ function getState(config) {
if (!localStorage[key]) {
saveState(config);
} else {
const delta = 1000 * 3600 * 24; // 1 day
const s = JSON.parse(localStorage[key]);
config.crs = s.crs;
config.baselayer = s.baselayer;
config.bbox = s.bbox;
config.klooster.year = s.year
config.klooster.language = s.language
config.klooster.filter = s.filter
if (Date.now() - s.updated < delta) {
config.crs = s.crs;
config.baselayer = s.baselayer;
config.bbox = s.bbox;
config.klooster.year = s.year
config.klooster.language = s.language
config.klooster.filter = s.filter
}
}
return config;
}
Expand Down

0 comments on commit 65b5e67

Please sign in to comment.