Hi Lucas,
Thanks for the feedback, and after much deliberation and searching following that post, I sort of came to the same conclusion.
This is the code that I ended up going with:
// Function to change the map style based on the dayNightMode variable in the app object
function changeMapStyle() {
// Get the current dayNightMode value from the app object and convert it to uppercase
let dayNightMode = app.dayNightMode.toUpperCase();
// Log the current mode to the console
console.log("Mode set to: " + dayNightMode);
// Loop through all the operational layers in the map, starting from the last layer
for (let i = mapView.map.operationalLayers.count - 1; i >= 0; i--) {
// Get the current layer
let layer = mapView.map.operationalLayers.get(i);
// Get the name of the layer and convert it to uppercase
let layerName = layer.name.toUpperCase();
// Check if the layer name contains "DAY" or "NIGHT"
if (layerName.includes("DAY") || layerName.includes("NIGHT")) {
// Log that the layer is sensitive to day/night mode
//console.log("Layer is DN sensitive so check");
// If the layer name contains the current dayNightMode value, make the layer visible
layer.visible = layerName.indexOf(dayNightMode) !== -1;
}
}
}
Note: my tendency in dev is to break apart code as much as possible...and doc it... lots of refactoring can go on later 🙂