I have a map with borders and different "background maps", e.g. OpenStreetMap and Google Satellite. When the Google Satellite Map is in the background, the borders are the best visible in white color. With OpenStreetMap turned visible, it is the color black.
Is there a way to change the color of a polygon (f.e. state border) depending on whether OpenStreetMap is visible or not?
Best Answer
An alternative if you want the symbology to show up correctly in legends and customise more layer settings depending on basemap, is to use style presets and map themes. This will also let you rename the basemap layers without needing to update the expression if using a data defined override (unless you use the layer's uuid).
Set up 'black' and 'white' style presets for your borders layer
Set up map themes
You can now toggle between map themes and set them up as required in your map layouts as well by getting the map item to follow whatever theme you select, regardless of what is displayed on the canvas.
See below for example. Note how the active layer style changes (in the layer styling panel to the right) when the map theme is changed.