forked from dimartarmizi/map-to-poster
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstate.js
More file actions
148 lines (135 loc) · 2.91 KB
/
state.js
File metadata and controls
148 lines (135 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import { themes } from './themes.js';
import { artisticThemes } from './artistic-themes.js';
import { loadCustomThemes } from './custom-themes.js';
let observers = [];
const STORAGE_KEY = 'map-to-poster:settings';
export const defaultState = {
city: "JAKARTA",
cityOverride: "",
country: "INDONESIA",
countryOverride: "",
cityFont: "'Playfair Display', serif",
countryFont: "'Outfit', sans-serif",
coordsFont: "'Outfit', sans-serif",
lat: -6.2088,
lon: 106.8456,
zoom: 12,
theme: "minimal",
width: 1080,
height: 1080,
isExporting: false,
overlayBgType: 'vignette',
overlaySize: 'medium',
showLabels: true,
renderMode: 'tile',
artisticTheme: 'cyber_noir',
matEnabled: false,
matWidth: 40,
matShowBorder: true,
matBorderWidth: 1,
matBorderOpacity: 1,
showMarker: false,
markers: [
{ lat: -6.2088, lon: 106.8456 }
],
markerIcon: 'pin',
markerSize: 1,
showRoute: false,
routeStartLat: -6.2088,
routeStartLon: 106.8456,
routeEndLat: -6.2150,
routeEndLon: 106.8550,
routeGeometry: [],
routeViaPoints: [],
overlayX: 0.5,
overlayY: 0.85,
showCountry: true,
showCoords: true,
};
export const state = { ...defaultState };
const SAVED_KEYS = [
'city',
'cityOverride',
'country',
'countryOverride',
'cityFont',
'countryFont',
'coordsFont',
'lat',
'lon',
'zoom',
'theme',
'width',
'height',
'overlayBgType',
'overlaySize',
'showLabels',
'renderMode',
'artisticTheme',
'matEnabled',
'matWidth',
'matShowBorder',
'matBorderWidth',
'matBorderOpacity',
'showMarker',
'markers',
'markerIcon',
'markerSize',
'showRoute',
'routeStartLat',
'routeStartLon',
'routeEndLat',
'routeEndLon',
'routeViaPoints',
'overlayX',
'overlayY',
'showCountry',
'showCoords'
];
function loadSettings() {
try {
const raw = localStorage.getItem(STORAGE_KEY);
if (!raw) return;
const parsed = JSON.parse(raw);
if (typeof parsed !== 'object' || parsed === null) return;
const toApply = {};
for (const k of SAVED_KEYS) {
if (k in parsed) toApply[k] = parsed[k];
}
Object.assign(state, toApply);
} catch (e) {
}
}
function saveSettings() {
try {
const out = {};
for (const k of SAVED_KEYS) {
out[k] = state[k];
}
localStorage.setItem(STORAGE_KEY, JSON.stringify(out));
} catch (e) {
}
}
loadSettings();
export function updateState(partialState) {
Object.assign(state, partialState);
saveSettings();
notifyObservers();
}
export function subscribe(callback) {
observers.push(callback);
callback(state);
}
function notifyObservers() {
observers.forEach(callback => callback(state));
}
export function getSelectedTheme() {
return themes[state.theme] || themes.standard || themes.minimal;
}
export function getSelectedArtisticTheme() {
if (state.artisticTheme && state.artisticTheme.startsWith('custom_')) {
const custom = loadCustomThemes();
if (custom[state.artisticTheme]) return custom[state.artisticTheme];
}
return artisticThemes[state.artisticTheme] || artisticThemes.cyber_noir;
}