Spaces:
Sleeping
Sleeping
Fix theme toggle functionality with Dark Matter and Light Matter labels
Browse files- Updated theme toggle to properly switch between CartoDB tiles
- Replaced unreliable layer detection with direct tile layer management
- Updated button labels to "Dark Matter" and "Light Matter" as requested
- Fixed theme detection for particle color adaptation
- Improved tile layer switching with proper cleanup and replacement
π€ Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
app.py
CHANGED
@@ -404,7 +404,7 @@ def create_wind_map(region="global"):
|
|
404 |
# Add light theme option (but don't make it active by default)
|
405 |
folium.TileLayer(
|
406 |
tiles="CartoDB positron",
|
407 |
-
name="Light
|
408 |
control=False # We'll control this with our custom button
|
409 |
).add_to(m)
|
410 |
|
@@ -453,16 +453,15 @@ def create_wind_map(region="global"):
|
|
453 |
// Check if we're on light theme by looking at current tile layer
|
454 |
var currentTileLayer = 'dark'; // default to dark
|
455 |
map.eachLayer(function(layer) {{
|
456 |
-
if (layer.options && layer.options.
|
457 |
-
if (layer.options.
|
|
|
458 |
currentTileLayer = 'light';
|
459 |
}}
|
460 |
}}
|
461 |
-
// Also check
|
462 |
-
if (layer.
|
463 |
-
|
464 |
-
currentTileLayer = 'light';
|
465 |
-
}}
|
466 |
}}
|
467 |
}});
|
468 |
|
@@ -725,7 +724,7 @@ def create_wind_map(region="global"):
|
|
725 |
|
726 |
// Add theme toggle button
|
727 |
var buttonTheme = L.DomUtil.create('button', 'theme-toggle', windControlDiv);
|
728 |
-
buttonTheme.innerHTML = 'π Dark
|
729 |
buttonTheme.style.display = 'block';
|
730 |
buttonTheme.style.width = '120px';
|
731 |
buttonTheme.style.margin = '2px 0';
|
@@ -752,53 +751,50 @@ def create_wind_map(region="global"):
|
|
752 |
|
753 |
// Theme toggle functionality
|
754 |
var isLightTheme = false; // Start with dark theme
|
755 |
-
var
|
756 |
-
var lightTileLayer = null;
|
757 |
|
758 |
-
// Find the
|
759 |
map.eachLayer(function(layer) {{
|
760 |
-
if (layer.options && layer.options.
|
761 |
-
|
762 |
-
darkTileLayer = layer;
|
763 |
-
console.log("π Found dark tile layer");
|
764 |
-
}} else if (layer.options.tiles.includes('positron')) {{
|
765 |
-
lightTileLayer = layer;
|
766 |
-
console.log("βοΈ Found light tile layer");
|
767 |
-
// Remove light layer by default (start with dark)
|
768 |
-
map.removeLayer(layer);
|
769 |
-
}}
|
770 |
}}
|
771 |
}});
|
772 |
|
773 |
L.DomEvent.on(buttonTheme, 'click', function() {{
|
774 |
isLightTheme = !isLightTheme;
|
775 |
|
|
|
|
|
|
|
|
|
|
|
776 |
if (isLightTheme) {{
|
777 |
-
// Switch to light theme
|
778 |
-
console.log("π Switching to LIGHT theme...");
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
buttonTheme.innerHTML = 'βοΈ Light
|
786 |
buttonTheme.style.background = '#f59e0b';
|
787 |
}} else {{
|
788 |
-
// Switch to dark theme
|
789 |
-
console.log("π Switching to DARK theme...");
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
buttonTheme.innerHTML = 'π Dark
|
797 |
buttonTheme.style.background = '#374151';
|
798 |
}}
|
799 |
|
800 |
// Trigger particle color update after theme change
|
801 |
setTimeout(reloadParticlesWithTheme, 200);
|
|
|
802 |
}});
|
803 |
|
804 |
// Add controls to map
|
|
|
404 |
# Add light theme option (but don't make it active by default)
|
405 |
folium.TileLayer(
|
406 |
tiles="CartoDB positron",
|
407 |
+
name="Light Matter",
|
408 |
control=False # We'll control this with our custom button
|
409 |
).add_to(m)
|
410 |
|
|
|
453 |
// Check if we're on light theme by looking at current tile layer
|
454 |
var currentTileLayer = 'dark'; // default to dark
|
455 |
map.eachLayer(function(layer) {{
|
456 |
+
if (layer.options && layer.options.attribution) {{
|
457 |
+
if (layer.options.attribution.includes('Light Matter') ||
|
458 |
+
layer.options.attribution.includes('light_all')) {{
|
459 |
currentTileLayer = 'light';
|
460 |
}}
|
461 |
}}
|
462 |
+
// Also check tile URL patterns
|
463 |
+
if (layer._url && layer._url.includes('light_all')) {{
|
464 |
+
currentTileLayer = 'light';
|
|
|
|
|
465 |
}}
|
466 |
}});
|
467 |
|
|
|
724 |
|
725 |
// Add theme toggle button
|
726 |
var buttonTheme = L.DomUtil.create('button', 'theme-toggle', windControlDiv);
|
727 |
+
buttonTheme.innerHTML = 'π Dark Matter';
|
728 |
buttonTheme.style.display = 'block';
|
729 |
buttonTheme.style.width = '120px';
|
730 |
buttonTheme.style.margin = '2px 0';
|
|
|
751 |
|
752 |
// Theme toggle functionality
|
753 |
var isLightTheme = false; // Start with dark theme
|
754 |
+
var currentTileLayer = null;
|
|
|
755 |
|
756 |
+
// Find and store the current base layer
|
757 |
map.eachLayer(function(layer) {{
|
758 |
+
if (layer.options && layer.options.attribution && layer.options.attribution.includes('CartoDB')) {{
|
759 |
+
currentTileLayer = layer;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
760 |
}}
|
761 |
}});
|
762 |
|
763 |
L.DomEvent.on(buttonTheme, 'click', function() {{
|
764 |
isLightTheme = !isLightTheme;
|
765 |
|
766 |
+
// Remove current tile layer
|
767 |
+
if (currentTileLayer) {{
|
768 |
+
map.removeLayer(currentTileLayer);
|
769 |
+
}}
|
770 |
+
|
771 |
if (isLightTheme) {{
|
772 |
+
// Switch to light matter theme
|
773 |
+
console.log("π Switching to LIGHT MATTER theme...");
|
774 |
+
currentTileLayer = L.tileLayer('https://{{s}}.basemaps.cartocdn.com/light_all/{{z}}/{{x}}/{{y}}{{r}}.png', {{
|
775 |
+
attribution: 'Β© CartoDB Light Matter',
|
776 |
+
subdomains: 'abcd',
|
777 |
+
maxZoom: 19
|
778 |
+
}});
|
779 |
+
currentTileLayer.addTo(map);
|
780 |
+
buttonTheme.innerHTML = 'βοΈ Light Matter';
|
781 |
buttonTheme.style.background = '#f59e0b';
|
782 |
}} else {{
|
783 |
+
// Switch to dark matter theme
|
784 |
+
console.log("π Switching to DARK MATTER theme...");
|
785 |
+
currentTileLayer = L.tileLayer('https://{{s}}.basemaps.cartocdn.com/dark_all/{{z}}/{{x}}/{{y}}{{r}}.png', {{
|
786 |
+
attribution: 'Β© CartoDB Dark Matter',
|
787 |
+
subdomains: 'abcd',
|
788 |
+
maxZoom: 19
|
789 |
+
}});
|
790 |
+
currentTileLayer.addTo(map);
|
791 |
+
buttonTheme.innerHTML = 'π Dark Matter';
|
792 |
buttonTheme.style.background = '#374151';
|
793 |
}}
|
794 |
|
795 |
// Trigger particle color update after theme change
|
796 |
setTimeout(reloadParticlesWithTheme, 200);
|
797 |
+
console.log("β
Theme switched successfully!");
|
798 |
}});
|
799 |
|
800 |
// Add controls to map
|