This sample demonstrates how the Value Picker component can be used to step through or automatically play through a list of values. When the application starts, two Value Picker components are added on the map.
The imagery layer in this app displays a global map of land use/land cover (between 2017 - 2022) derived from Sentinel-2 imagery at 10m resolution. You can learn more about the data here.
Value Picker with label component
The first Value Picker component allows users to display land cover for a selected year by setting the map component’s timeExtent. The time Value Picker component uses the label component to present a list of predefined years, as shown below:
// Create year labels for the image service data from 2017 to 2022. const startDate = new Date(2017, 0, 1); const endDate = new Date(2022, 0, 1); let currentDate = startDate;
// Build label items for the Value Picker to drive the view time extent. const labelComponentForDates = []; while (currentDate <= endDate) { labelComponentForDates.push({ value: currentDate.getTime(), label: "Land cover in " + currentDate.getFullYear(), }); currentDate.setFullYear(currentDate.getFullYear() + 1); }
// Assign the year labels to the Value Picker. const timeValuePicker = document.getElementById("timeValuePicker"); timeValuePicker.items = labelComponentForDates;The user’s interaction is then handled by listening for the arcgisPropertyChange event which fires whenever a the user cycles through the years manually or via the play button.
// Update the view time extent when the selected year changes. timeValuePicker.addEventListener("arcgisPropertyChange", (event) => { const currentDate = new Date(timeValuePicker.currentValue.value); const endDate = currentDate.getFullYear() + 1; viewElement.timeExtent = { start: currentDate, end: new Date(endDate, 0, 1), }; });Value Picker with combobox component
The second Value Picker component allows users to change the land cover type displayed in the imagery layer by setting its rasterFunction property. This Value Picker component uses the combobox component to present a searchable dropdown list of land cover categories, as shown below:
// Populate combobox items from the image service raster functions. let comboboxItems = []; layer.rasterFunctionInfos.forEach((rf) => { comboboxItems.push({ value: rf.name, label: rf.name, }); });
const rasterFunctionPicker = document.getElementById("rasterFunctionPicker"); rasterFunctionPicker.items = comboboxItems;The user’s interaction is then handled by listening for the arcgisPropertyChange event which detects when the subcomponent’s currentValue property changes, as shown below:
// Update the layer raster function when the Value Picker selection changes. rasterFunctionPicker.addEventListener("arcgisPropertyChange", (event) => { layer.rasterFunction = { functionName: rasterFunctionPicker.currentValue.value, }; });