-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathdecorate.mjs
151 lines (109 loc) · 3.38 KB
/
decorate.mjs
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
149
150
151
export default location => {
Object.assign(location, {
flyTo,
Layers: [],
remove,
removeCallbacks: [],
trash,
update,
updateCallbacks: [],
})
return location;
}
function remove() {
// Checks may be performed after async oprations
// whether a location has already been removed.
delete this.remove
this.layer.mapview.hooks && mapp.hooks.filter('locations', this.hook)
delete this.layer.mapview.locations[this.hook]
this.view instanceof HTMLElement && this.view.remove()
this.Layers?.forEach(
L => this.layer.mapview.Map.removeLayer(L))
this.layer.mapview.interaction.type !== 'highlight'
&& this.layer.mapview.interactions.highlight()
if (this.layer.format === 'mvt') {
this.layer.L.changed()
} else {
this.layer.reload && this.layer.reload()
}
this.removeCallbacks?.forEach(
fn => typeof fn === 'function' && fn(this))
}
async function update() {
const newValues = {}
this.infoj
.filter(entry => typeof entry.newValue !== 'undefined')
.forEach(entry => {
if(entry.type === 'integer') entry
.newValue = !isNaN(parseInt(entry.newValue)) ? entry.newValue : null;
if(entry.type === 'numeric') entry
.newValue = !isNaN(parseFloat(entry.newValue)) ? entry.newValue : null;
Object.assign(newValues, { [entry.field] : entry.newValue })
})
if (!Object.keys(newValues).length) return;
await mapp.utils.xhr({
method: "POST",
url:
`${this.layer.mapview.host}/api/location/update?` +
mapp.utils.paramString({
locale: this.layer.mapview.locale.key,
layer: this.layer.key,
table: this.table,
id: this.id,
}),
body: JSON.stringify(newValues),
});
let dependents = this.infoj
.filter(entry => typeof entry.newValue !== 'undefined')
.filter(entry => entry.dependents && entry.dependents.length)
.map(entry => entry.dependents)
.flat()
this.infoj
.filter(entry => typeof entry.newValue !== 'undefined')
.forEach(entry => {
entry.value = entry.newValue;
delete entry.newValue;
})
if (dependents.length) {
const response = await mapp.utils.xhr(
`${this.layer.mapview.host}/api/location/get?` +
mapp.utils.paramString({
locale: this.layer.mapview.locale.key,
layer: this.layer.key,
table: this.table,
id: this.id,
fields: [...new Set(dependents)].join(),
})
);
this.infoj
.filter(entry => typeof response[entry.field] !== 'undefined')
.forEach(entry => {
entry.value = response[entry.field];
})
}
// Reload layer.
this.layer.reload()
this.updateCallbacks?.forEach(
fn => typeof fn === 'function' && fn(this))
}
function flyTo () {
const sourceVector = new ol.source.Vector();
this.Layers.forEach(layer => {
const source = layer.getSource()
typeof source.getFeatures === 'function'
&& sourceVector.addFeatures(source.getFeatures())
})
this.layer.mapview.fitView(sourceVector.getExtent());
}
async function trash() {
if(!confirm(mapp.dictionary.confirm_delete)) return;
await mapp.utils.xhr(`${this.layer.mapview.host}/api/location/delete?` +
mapp.utils.paramString({
locale: this.layer.mapview.locale.key,
layer: this.layer.key,
table: this.table,
id: this.id
}))
this.layer.reload()
this.remove()
}