This commit is contained in:
Tykayn 2025-09-23 12:18:10 +02:00 committed by tykayn
parent c3dc3bdbb5
commit a2834c1f25

View file

@ -228,26 +228,28 @@ class DemoMainResource:
# <div id="auth-section" class="auth-section">
# <h3>OpenStreetMap Authentication</h3>
#
# <a href="https://www.openstreetmap.org/oauth2/authorize?client_id={client_id}&redirect_uri={client_redirect}&response_type=code&scope=read_prefs" class="osm-login-btn">
# <span class="osm-logo"></span>
# Login with OpenStreetMap
# </a>
# <script>
<a href="https://www.openstreetmap.org/oauth2/authorize?client_id={client_id}&redirect_uri={client_redirect}&response_type=code&scope=read_prefs" class="osm-login-btn">
<span class="osm-logo"></span>
Login with OpenStreetMap
</a>
<script>
# // Replace server-side auth section with JavaScript-rendered version if available
# document.addEventListener('DOMContentLoaded', function() {
# if (window.osmAuth) {
# const clientId = document.getElementById('osmClientId').value;
# const redirectUri = document.getElementById('osmRedirectUri').value;
# const authSection = document.getElementById('auth-section');
#
# // Only replace if osmAuth is loaded and has renderAuthSection method
# if (osmAuth.renderAuthSection) {
# authSection.innerHTML = osmAuth.renderAuthSection(clientId, redirectUri);
# }
# }
# });
# </script>
# </div> -->
document.addEventListener('DOMContentLoaded', function() {
fetchEvents();
if (window.osmAuth) {
const clientId = document.getElementById('osmClientId').value;
const redirectUri = document.getElementById('osmRedirectUri').value;
const authSection = document.getElementById('auth-section');
// Only replace if osmAuth is loaded and has renderAuthSection method
if (osmAuth.renderAuthSection) {
authSection.innerHTML = osmAuth.renderAuthSection(clientId, redirectUri);
}
}
});
</script>
</div> -->
<h3 id="endpoints_list_header">API Endpoints:</h3>
<ul id="endpoints_list">
@ -276,7 +278,7 @@ class DemoMainResource:
// Fonction pour gérer les listes dépliantes
document.addEventListener('DOMContentLoaded', function() {
fetchEvents();
const endpointsHeader = document.getElementById('endpoints_list_header');
const endpointsList = document.getElementById('endpoints_list');
@ -352,63 +354,8 @@ class DemoMainResource:
// Style switcher functionality
let currentStyle = 'default';
let eventsData = null;
document.getElementById('style-default').addEventListener('click', () => {
if (currentStyle !== 'default') {
switchMapStyle('default');
}
});
document.getElementById('style-osm-vector').addEventListener('click', () => {
if (currentStyle !== 'osmVector') {
switchMapStyle('osmVector');
}
});
document.getElementById('style-osm-raster').addEventListener('click', () => {
if (currentStyle !== 'osmRaster') {
switchMapStyle('osmRaster');
}
});
function switchMapStyle(styleName) {
// Update active button
document.querySelectorAll('.map-style-control button').forEach(button => {
button.classList.remove('active');
});
document.getElementById(`style-${styleName.replace('osm', 'osm-')}`).classList.add('active');
// Save current center and zoom
const center = map.getCenter();
const zoom = map.getZoom();
// Save events data if already loaded
if (map.getSource('events')) {
try {
eventsData = map.getSource('events')._data;
} catch (e) {
console.error('Error saving events data:', e);
}
}
// Apply new style
map.setStyle(mapStyles[styleName]);
// Restore center and zoom after style is loaded
map.once('style.load', () => {
map.setCenter(center);
map.setZoom(zoom);
// Restore events data if available
if (eventsData) {
addEventsToMap(eventsData);
} else {
fetchEvents();
}
});
currentStyle = styleName;
}
// Fetch events when the map is loaded
map.on('load', function() {
@ -870,6 +817,8 @@ class DemoMainResource:
errorToast.classList.remove('show');
}, 6000);
}
</script>
</body>
</html>