Hi all,
I'm seeking some advice, suggestions, examples or anything else that might help me change my symbology between a 'dark' and 'light' mode. E.g., I have a map that I wish to use in a day/night configuration.
I toyed with the idea of creating two maps, with different symbology, and switching the map out (I am using a mobile map package) but that adds some complexity as I have routing on networks associated with the loaded map.
I was hoping for a way to be able to load the map, and then look up the symbology from a stylx file (maybe?) and just load a different style file based on my dark/light mode. I have looked at the dictionary style examples but they seem fixed to military type symbology.
The other option is iterating through each of the operational layers and setting a renderer.
If anyone has any other suggestions, I would be delighted to hear them.
Regards,
Sean
I am guessing from your question that you have a mainly offline workflow since you mentioned using a mobile map package? Are you using vector tiles as a basemap?
I think in some of the conference demos Esri like to show they can do neat stuff with vector styles, I just dont know if the runtime Qt/maps Qt allows you to change the style with the data underlying not changing.
reference: https://www.youtube.com/watch?v=COf8isFlebE
Thanks TroyFoster,
Yes, planning to be totally offline due to remote location with no internet coverage. At the moment, I'm using a map package built in ArcGIS Pro (.mmpk). I'm really keen to look into vtpk's as you're the second person who has mentioned these to me now, on two different occasions. I don't know what the difference is between a true vtpk and the mmpk (and I say that because I only have 'shape' data in my map layers i.e. polys and points and no raster or other tilesets) <-- still learning! From what I can gather, there is probably a whole bunch of styling and other references in the mmpk. Anyway, I digress.
...and an update...
About 32 seconds after posting, 😁 I decided to try something else, and that is to create a duplicated layer in my map. Based on the name, I can then change the visibility. Working on the code right now, but still interested in other options.
Your solution of toggling visibility depending on dark/light mode is pretty clean and simple in my opinion. That seems like a good option.
We do have other samples where we use dictionary symbol styles without military symbols. You could input some custom Arcade that would swap the correct colors depending on some condition, but that will be much more complicated to maintain and debug than your solution. https://github.com/Esri/arcgis-maps-sdk-samples-qt/tree/main/ArcGISRuntimeSDKQt_QMLSamples/DisplayIn...
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 🙂