-
Notifications
You must be signed in to change notification settings - Fork 0
/
geopkg_ui.js
83 lines (70 loc) · 2.24 KB
/
geopkg_ui.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// geopkg_ui.js
// Martin Pravda
// UI component for manipulating with geopackage format
/* jslint browser*/
import make_ui from "./ui.js";
import geopkg_conn_ui from "./geopkg_conn_ui.js";
import geopkg_table_ui from "./geopkg_table_ui.js";
import geopkg_controls_ui from "./geopkg_controls_ui.js";
const geopkg_ui = make_ui("geopkg-ui", function (element, {
modules,
on_add_source,
on_close
}) {
let connections;
let table;
let controls;
const shadow = element.attachShadow({mode: "closed"});
function on_connect({geopackage}) {
if (table) {
table.remove();
}
const feature_tables = geopackage.get_feature_tables();
Promise.all([
feature_tables.get.cols,
feature_tables.get.rows
]).then(function ([
columns,
rows
]) {
table = geopkg_table_ui({
columns,
on_row_click: function (row) {
const [table_name, geometry, srs, geom_column_name] = row;
controls.remove_listeners();
controls.attach_listeners({
on_add: function () {
geopackage.get_feature_as_geojson(
table_name,
geom_column_name
).get.objs.then(function (features) {
on_add_source({
features,
geometry,
name: table_name,
srs,
geom_column_name
});
});
}
});
},
rows
});
shadow.append(table);
})
}
connections = geopkg_conn_ui({
modules,
on_connect,
on_remove: function () {
controls?.remove_listeners();
table?.remove();
}
});
controls = geopkg_controls_ui({
on_close
});
shadow.append(connections, controls);
});
export default Object.freeze(geopkg_ui);