Chargement Évènements

Urbanisme et Biodiversité – Bastia

Intégrer la séquence "Eviter-Réduire-Compenser" dans les documents d'urbanisme

Ateliers d’échanges et de prospective territoriale “Concevoir avec le vivant : Quels choix pour ma commune ?”
Vous êtes élu et votre commune est en cours d’élaboration d’un document d’urbanisme ? Vous êtes invité à participer à des ateliers interactifs animés par un bureau d’études.
=> Inscrivez-vous vite ! Places limitéesDes ateliers pour vous aider à répondre ces questions :
Quel visage pour ma commune demain?
Où ne faut-il pas construire ?
Construire avec le vivant : comment concevoir mon quartier ?
Comment réparer les impacts ?
avec la participation de Caroline Tafani, agronome et géographe, Professeur de Géographie l’UMR / CNRS LISA Université de Corse

🐘
filename.php
add_shortcode('test_carte', function() {
    return '<div style="background:red; color:white; padding:20px; font-weight:bold;">LE SHORTCODE FONCTIONNE !</div>';
});
[test_carte]

 

01 et 02 octobre

 

Conditions

Inscrivez-vous vite ! Places limitées
 
S’inscrire / Réserver

https://forms.gle/X9zivTYvvc81SrY29

 
Renseignements  [email protected]
[carte_evenement]

A propos du lieu

Les salons de la Préfecture – Bastia
42.7021, 9.45075
Haute-Corse
Corse
🐘
functions.php
add_shortcode( 'carte_evenement', function() {
    // 1. Détection robuste de l'ID de l'événement
    $event_id = get_the_ID();
    if ( ! $event_id || get_post_type( $event_id ) !== 'tribe_events' ) {
        if ( isset( $GLOBALS['post']->ID ) && get_post_type( $GLOBALS['post']->ID ) === 'tribe_events' ) {
            $event_id = $GLOBALS['post']->ID;
        }
    }

    if ( ! $event_id || ! function_exists( 'tribe_get_venue_id' ) ) {
        return '<p style="padding:10px; background:#fff3cd; color:#856404; font-size:12px; border-radius:4px;">⚠️ Impossible de détecter l\'événement en cours.</p>';
    }

    $venue_id = tribe_get_venue_id( $event_id );
    if ( ! $venue_id ) {
        return '<p style="padding:10px; background:#fff3cd; color:#856404; font-size:12px; border-radius:4px;">📍 Aucun lieu n\'est attribué à cet événement dans The Events Calendar.</p>';
    }

    // 2. Récupération des données du lieu
    $venue_name   = tribe_get_venue( $event_id );
    $address      = tribe_get_address( $event_id );
    $city         = tribe_get_city( $event_id );
    $full_address = trim( $address . ' ' . $city );

    if ( empty( $full_address ) ) {
        return '<p style="padding:10px; background:#fff3cd; color:#856404; font-size:12px; border-radius:4px;">📍 L\'adresse du lieu est vide.</p>';
    }

    // Coordonnées GPS
    $lat = get_post_meta( $venue_id, '_VenueLatitude', true );
    $lng = get_post_meta( $venue_id, '_VenueLongitude', true );

    $map_id = 'map_evt_' . $event_id . '_' . rand(100, 999);

    ob_start();
    ?>
    <div class="carte-event-wrapper" style="width: 100%; margin: 15px 0;">
        <!-- Ingestion garantie de Leaflet CSS / JS -->
        <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
        <script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>

        <div id="<?php echo esc_attr( $map_id ); ?>" style="width: 100%; height: 280px; border-radius: 8px; border: 1px solid #ddd; background: #e9ecef; position: relative; z-index: 1;">
            <p style="padding: 15px; text-align: center; color: #666; font-size: 13px;">Chargement de la carte...</p>
        </div>
    </div>

    <script>
    (function() {
        function chargerCarte() {
            var el = document.getElementById('<?php echo esc_js( $map_id ); ?>');
            if (!el) return;
            if (typeof L === 'undefined') {
                setTimeout(chargerCarte, 150);
                return;
            }
            if (el._leaflet_id) return;

            var lat = "<?php echo esc_js( $lat ); ?>";
            var lng = "<?php echo esc_js( $lng ); ?>";
            var searchAddr = "<?php echo esc_js( $full_address ); ?>";
            var title = "<?php echo esc_js( $venue_name ); ?>";

            function afficherPoint(latitude, longitude) {
                el.innerHTML = ""; // Vider le texte de chargement
                var map = L.map('<?php echo esc_js( $map_id ); ?>', { scrollWheelZoom: false }).setView([latitude, longitude], 14);

                L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
                    attribution: '© OpenStreetMap'
                }).addTo(map);

                L.marker([latitude, longitude]).addTo(map)
                    .bindPopup("<b>" + title + "</b><br>" + searchAddr)
                    .openPopup();

                setTimeout(function(){ map.invalidateSize(); }, 400);
            }

            if (lat && lng && lat !== "0" && lng !== "0") {
                afficherPoint(parseFloat(lat), parseFloat(lng));
            } else {
                // Recherche automatique par adresse si pas de GPS
                fetch('https://nominatim.openstreetmap.org/search?format=json&q=' + encodeURIComponent(searchAddr))
                    .then(res => res.json())
                    .then(data => {
                        if (data && data.length > 0) {
                            afficherPoint(parseFloat(data[0].lat), parseFloat(data[0].lon));
                        } else {
                            el.innerHTML = "<div style='padding:15px; font-size:13px; color:#c0392b;'>Impossible de géolocaliser l'adresse : " + searchAddr + "</div>";
                        }
                    })
                    .catch(function() {
                        el.innerHTML = "<div style='padding:15px; font-size:13px; color:#c0392b;'>Erreur lors du chargement de la carte.</div>";
                    });
            }
        }

        if (document.readyState === 'complete' || document.readyState === 'interactive') {
            setTimeout(chargerCarte, 200);
        } else {
            document.addEventListener('DOMContentLoaded', chargerCarte);
        }
    })();
    </script>
    return ob_get_clean();
});