public void reapplyMapTheme(final ITileLayer tileLayer, final TileCache tileCache) {

        if (tileLayer == null || tileLayer.getTileLayer() == null) {
            return;
        }

        if (!tileLayer.hasThemes()) {
            tileLayer.getTileLayer().requestRedraw();
            return;
        }

        final TileRendererLayer rendererLayer = (TileRendererLayer) tileLayer.getTileLayer();

        //try to apply stored value
        ThemeData selectedTheme = setSelectedMapTheme(Settings.getSelectedMapRenderTheme());


        if (selectedTheme == null) {
            applyDefaultTheme(rendererLayer);
        } else {
            try {
                //get the theme
                final XmlRenderTheme xmlRenderTheme = createThemeFor(selectedTheme);

                // Validate the theme
                org.mapsforge.map.rendertheme.rule.RenderThemeHandler.getRenderTheme(AndroidGraphicFactory.INSTANCE, new DisplayModel(), xmlRenderTheme);
                rendererLayer.setXmlRenderTheme(xmlRenderTheme);
                //setting xmlrendertheme has filled prefThemeStyleKey -> now apply scales
                applyScales(rendererLayer, prefThemeStyleKey);
            } catch (final IOException e) {
                Log.w("Failed to set render theme", e);
                ActivityMixin.showApplicationToast(LocalizationUtils.getString(R.string.err_rendertheme_file_unreadable));
                rendererLayer.setXmlRenderTheme(MapsforgeThemes.OSMARENDER);
                selectedTheme = null;
            } catch (final Exception e) {
                Log.w("render theme invalid", e);
                ActivityMixin.showApplicationToast(LocalizationUtils.getString(R.string.err_rendertheme_invalid));
                rendererLayer.setXmlRenderTheme(MapsforgeThemes.OSMARENDER);
                selectedTheme = null;
            }
        }
        setSelectedTheme(selectedTheme);

        //copied from NewMap in Feb 2021. Apparently cache tile needs purgin upon theme (re)select
        if (tileCache != null) {
            tileCache.purge();
        }
        rendererLayer.requestRedraw();
    }
Helper class for Map Theme selection and related tasks.
<br>
Works in conjunction with {@link RenderThemeSettings} (for theme settings GUI).
<br>
Note: this class is an attempt to bundle all large parts of this code were simply moved from class
NewMap and might need refactoring.
main/src/main/java/cgeo/geocaching/maps/mapsforge/v6/RenderThemeHelper.java