viewof selection = {
const selectionField = "properties";
const spec = vl.markGeoshape({ stroke: "#0005" })
.data(countries.features)
.params([
{ name: "selected", select: { type: "point", fields: [selectionField], toggle: allowMultiple } },
{ name: "highlighted", select: { type: "point", on: "mouseover", toggle: false } },
])
.encode(vl.tooltip({ field: "properties.name" }))
.encode(vl.color({
condition: [
{ param: "selected", empty: false, value: "salmon" },
{ param: "highlighted", empty: false, value: "peachpuff" },
],
value: "whitesmoke",
}))
.width(640)
.height(320);
const element = await spec.render();
const view = element.value;
const input = html`<div>${element}`;
view.addSignalListener("selected", (signal, selection) => {
const key = selectionField.replace(".", "\\.");
const items = selection[key];
input.value = allowMultiple
? ( items || [] )
: ( items ? items[0] : undefined );
input.dispatchEvent(new Event("input"));
});
return input;
}