-
Notifications
You must be signed in to change notification settings - Fork 0
/
xyz_ui.js
144 lines (126 loc) · 4.07 KB
/
xyz_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
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
// source_xyz.js
// Martin Pravda
// Main XYZ Source view. User can interactively select from the predefined
// sources or define a custom XYZ source
/*jslint browser */
import make_ui from "./ui.js";
import dom from "./dom.js";
import details_xyz_ui from "./details_xyz_ui.js";
const xyz_ui = make_ui("xyz-ui", function (element, {
on_add_source,
sources_list = [
// make empty option first
{
max_zoom_level: 0,
min_zoom_level: 0,
name: "Custom",
url: ""
},
{
center: [0, 0],
max_zoom_level: 19,
min_zoom_level: 0,
name: "OpenStreetMap",
srs: "EPSG:3857",
url: "https://tile.openstreetmap.org/{z}/{x}/{y}.png",
zoom: 2
},
{
center: [0, 0],
max_zoom_level: 15,
min_zoom_level: 0,
name: "MapZen",
url: "https://s3.amazonaws.com/elevation-tiles-prod/terrarium/{z}/{x}/{y}.png",
zoom: 2
}
]
}) {
let source_select;
let source_details;
const shadow = element.attachShadow({mode: "closed"});
function on_input_change({name, url}) {
// default buttons state
source_details.disable_add(false);
source_details.disable_save(false);
source_details.disable_delete(false);
if (!url || !name) {
source_details.disable_add(true);
source_details.disable_save(true);
source_details.disable_delete(true);
return;
}
if (sources_list.some(function (source) {
return source.name === name;
}) === true) {
source_details.disable_save(true);
return;
} else {
source_details.disable_delete(true);
return;
}
}
function get_sources_list() {
return sources_list;
}
source_select = dom("select", {
onchange: function (event) {
const source = sources_list.find(function (source) {
return (
source.name === event.target.value
);
});
if (source.name === "Custom") {
source_details.clear_details();
source_details.disable_delete(true);
source_details.disable_add(true);
source_details.disable_save(true);
return;
}
source_details.update_details(source);
source_details.disable_add(false);
source_details.disable_delete(false);
source_details.disable_save(true);
}
}, sources_list.map(function (source) {
return dom("option", {
value: source.name
}, [source.name]);
}));
source_details = details_xyz_ui({
delete_disabled: true,
on_add_source,
on_delete_source: function on_delete_source(source) {
sources_list = sources_list.filter(function ({name}) {
return name !== source.name;
});
const option = Array.from(
source_select.options
).find(function (option) {
return source.name === option.value;
});
option.remove();
source_details.clear_details();
source_details.disable_delete(true);
source_details.disable_add(true);
source_details.disable_save(true);
},
on_name_change: on_input_change,
on_save_source: function on_save_source(source) {
source_select.append(dom("option", {
selected: true,
value: source.name
}, [source.name]));
sources_list.push(source);
},
on_url_change: on_input_change
});
shadow.append(source_select, source_details);
element.get_sources_list = get_sources_list;
});
//demo import demo from "./demo.js";
//demo demo(xyz_ui({
//demo on_add_source: function (source) {
//demo console.log(source);
//demo }
//demo }));
export default Object.freeze(xyz_ui);