Skip to content

Commit 06c34fc

Browse files
committed
Support different query params to config values for each source
1 parent 237bb4a commit 06c34fc

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

main.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,23 @@ async function main() {
2929
}, 200),
3030
);
3131

32-
// parse image config
33-
// @ts-expect-error - TODO: validate config
34-
const config: vizarr.ImageLayerConfig = {};
35-
36-
for (const [key, value] of url.searchParams) {
37-
// @ts-expect-error - TODO: validate config
38-
config[key] = value;
39-
}
40-
4132
// We want to addImage() for each source in the query params
4233
const sources = url.searchParams.getAll("source");
43-
sources.forEach((source) => {
44-
// deepcopy config
34+
sources.forEach((source, index) => {
35+
// parse image config
36+
// @ts-expect-error - TODO: validate config
37+
const config: vizarr.ImageLayerConfig = {};
38+
39+
for (const [key, value] of url.searchParams) {
40+
// get all the values for key...
41+
const values = url.searchParams.getAll(key);
42+
if (values.length > index) {
43+
// @ts-expect-error - TODO: validate config
44+
config[key] = values[index];
45+
}
46+
}
4547
let configCopy = JSON.parse(JSON.stringify(config));
46-
configCopy['source'] = source;
48+
configCopy.source = source;
4749
viewer.addImage(configCopy);
4850
});
4951

0 commit comments

Comments
 (0)