Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions scripts/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,23 +185,24 @@ def render(value):

# Add reset zoom control using a direct approach
# This script will be added at the end and executed immediately
reset_control_script = folium.Element("""
reset_control_script = folium.Element(
"""
<script>
(function() {
var attempts = 0;
var maxAttempts = 50;

function addResetControl() {
attempts++;

// Check if Leaflet is loaded
if (typeof L === 'undefined' || !L.Control) {
if (attempts < maxAttempts) {
setTimeout(addResetControl, 100);
}
return;
}

// Define the control if not already defined
if (!L.Control.ResetZoom) {
L.Control.ResetZoom = L.Control.extend({
Expand All @@ -218,7 +219,7 @@ def render(value):
link.style.textAlign = 'center';
link.style.fontSize = '18px';
link.style.cursor = 'pointer';

L.DomEvent.on(link, 'click', function(e) {
L.DomEvent.preventDefault(e);
map.setView([20, 0], 2);
Expand All @@ -237,7 +238,7 @@ def render(value):
return new L.Control.ResetZoom(opts);
};
}

// Find all map divs and add the control
var mapDivs = document.querySelectorAll('[id^="map_"]');
var added = false;
Expand All @@ -252,13 +253,13 @@ def render(value):
}
}
});

// If we couldn't add and still have attempts, try again
if (!added && attempts < maxAttempts) {
setTimeout(addResetControl, 100);
}
}

// Start the process
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', addResetControl);
Expand All @@ -268,8 +269,9 @@ def render(value):
}
})();
</script>
""")

"""
)

m.get_root().html.add_child(reset_control_script)

# Save
Expand Down
Loading