So I have a multiple-select option and I was wondering how do I retrieve the values from the multi-select and assign it to the following layer expression:
map.allLayers.forEach((layer) => {
layer.definitionExpression = "CSDNAME IN";
layer.queryExtent().then(function (results) {
view.goTo(results.extent);
});
});
Solved! Go to Solution.
You can get the values from the multi-select and turn them into a string, which would be then used in the definition expression
const options = document.getElementById('your-multi-select').selectedOptions;
const values = Array.from(options).map(({ value }) => "'" + value + "'");
//if the values are numbers, omit the quotes
//const values = Array.from(options).map(({ value }) => value);
const output = values.join();
layer.definitionExpression = "CSDNAME IN (" + output + ")";
You can get the values from the multi-select and turn them into a string, which would be then used in the definition expression
const options = document.getElementById('your-multi-select').selectedOptions;
const values = Array.from(options).map(({ value }) => "'" + value + "'");
//if the values are numbers, omit the quotes
//const values = Array.from(options).map(({ value }) => value);
const output = values.join();
layer.definitionExpression = "CSDNAME IN (" + output + ")";