-
Notifications
You must be signed in to change notification settings - Fork 2
/
stores.js
64 lines (58 loc) · 1.56 KB
/
stores.js
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
import { writable, derived } from "svelte/store";
export const gjScheme = writable(emptyGeojson());
export const currentSidebarHover = writable(null);
export const currentMapHover = writable(null);
export const areaSearchDictionary = writable(emptyAreaSearchDictionary());
// TODO Should we store a map from ID to feature?
// TODO DrawControls will partly own state. Do we have to listen for every geometry change?
// TODO Should we attempt to keep properties in DrawControls or not?
export function emptyGeojson() {
return {
type: "FeatureCollection",
features: [],
};
}
// The ID of whatever's being edited
export const currentlyEditing = derived(gjScheme, ($gj) => {
let f = $gj.features.find((f) => f.properties.editing);
if (f) {
return f.id;
} else {
return null;
}
});
// TODO This is a bit of a hack; it muddies up the GeoJSON we save. But for the
// accordion to work, we have to bind something simple like this.
export function setCurrentlyEditing(id) {
gjScheme.update((gj) => {
for (let f of gj.features) {
if (f.id == id) {
f.properties.editing = true;
} else {
delete f.properties.editing;
}
}
return gj;
});
}
export function clearCurrentlyEditing() {
gjScheme.update((gj) => {
gj.features.forEach((f) => {
delete f.properties.editing;
});
return gj;
});
}
export function emptyAreaSearchDictionary() {
return {
latlong: {
latitude: null,
longitude: null,
},
eastnorth: {
easting: null,
northing: null,
},
postcode: null,
}
}