up emojis
This commit is contained in:
parent
205d77e2f6
commit
65956ff6be
8 changed files with 657 additions and 79 deletions
148
static/map_by_what.css
Normal file
148
static/map_by_what.css
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-family: Arial, sans-serif;
|
||||
}
|
||||
|
||||
#map {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.map-overlay {
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
left: 10px;
|
||||
background: rgba(255, 255, 255, 0.9);
|
||||
padding: 15px;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
max-width: 300px;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.filter-overlay {
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
right: 10px;
|
||||
background: rgba(255, 255, 255, 0.95);
|
||||
padding: 15px;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
max-width: 250px;
|
||||
max-height: 80vh;
|
||||
overflow-y: auto;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.filter-overlay h3 {
|
||||
margin-top: 0;
|
||||
color: #0078ff;
|
||||
}
|
||||
|
||||
.filter-overlay button {
|
||||
margin: 5px 5px 10px 0;
|
||||
padding: 5px 10px;
|
||||
background: #0078ff;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 3px;
|
||||
cursor: pointer;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.filter-overlay button:hover {
|
||||
background: #0056b3;
|
||||
}
|
||||
|
||||
.filter-list {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.filter-list li {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.filter-list input[type="checkbox"] {
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
.filter-list label {
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
/* Styles pour les marqueurs personnalisés avec forme de goutte */
|
||||
.custom-marker {
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.marker-drop {
|
||||
width: 36px;
|
||||
height: 46px;
|
||||
position: relative;
|
||||
background: #0078ff;
|
||||
border-radius: 50% 50% 50% 0;
|
||||
transform: rotate(-45deg);
|
||||
filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.3));
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.marker-drop:after {
|
||||
content: '';
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
position: absolute;
|
||||
background: white;
|
||||
border-radius: 50%;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.marker-emoji {
|
||||
font-size: 18px;
|
||||
transform: rotate(45deg);
|
||||
z-index: 2;
|
||||
position: relative;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.custom-marker:hover .marker-drop {
|
||||
transform: rotate(-45deg) scale(1.1);
|
||||
transition: transform 0.2s ease;
|
||||
}
|
||||
|
||||
.event-popup {
|
||||
max-width: 300px;
|
||||
}
|
||||
|
||||
.event-popup h3 {
|
||||
margin-top: 0;
|
||||
color: #0078ff;
|
||||
}
|
||||
|
||||
.event-popup p {
|
||||
margin: 8px 0;
|
||||
}
|
||||
|
||||
/* Responsive design */
|
||||
@media (max-width: 768px) {
|
||||
.map-overlay, .filter-overlay {
|
||||
position: static;
|
||||
max-width: none;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.filter-overlay {
|
||||
max-height: 200px;
|
||||
}
|
||||
}
|
||||
260
static/map_by_what.js
Normal file
260
static/map_by_what.js
Normal file
|
|
@ -0,0 +1,260 @@
|
|||
// Configuration des critères d'emojis pour les marqueurs de carte
|
||||
window.EMOJI_CRITERIA = {
|
||||
// Emoji mammouth pour les événements contenant "mammouth"
|
||||
mammoth: {
|
||||
emoji: '🦣',
|
||||
criteria: (name, description, what) => {
|
||||
const text = (name + ' ' + description).toLowerCase();
|
||||
return text.includes('mammouth');
|
||||
}
|
||||
},
|
||||
// Emoji notes de musique pour orchestres, concerts, fanfares ou types musicaux
|
||||
music: {
|
||||
emoji: '🎵',
|
||||
criteria: (name, description, what) => {
|
||||
const text = (name + ' ' + description + ' ' + what).toLowerCase();
|
||||
return text.includes('orchestr') || text.includes('concert') ||
|
||||
text.includes('fanfare') || text.includes('music');
|
||||
}
|
||||
},
|
||||
// Emoji éclair pour les types contenant "power"
|
||||
power: {
|
||||
emoji: '⚡',
|
||||
criteria: (name, description, what) => {
|
||||
return (what || '').toLowerCase().includes('power');
|
||||
}
|
||||
},
|
||||
// Emoji vélo pour les types contenant "bike"
|
||||
bike: {
|
||||
emoji: '🚴',
|
||||
criteria: (name, description, what) => {
|
||||
return (what || '').toLowerCase().includes('bike');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Fonction pour déterminer l'emoji approprié pour un événement
|
||||
function getEventEmoji(properties) {
|
||||
const name = properties.name || properties.label || '';
|
||||
const description = properties.description || '';
|
||||
const what = properties.what || '';
|
||||
|
||||
// Parcourir les critères dans l'ordre de priorité
|
||||
for (const [key, config] of Object.entries(window.EMOJI_CRITERIA)) {
|
||||
if (config.criteria(name, description, what)) {
|
||||
return config.emoji;
|
||||
}
|
||||
}
|
||||
|
||||
// Emoji par défaut selon le type d'événement
|
||||
if (what.includes('traffic')) return '🚗';
|
||||
if (what.includes('weather')) return '🌤️';
|
||||
if (what.includes('gathering')) return '👥';
|
||||
if (what.includes('incident')) return '⚠️';
|
||||
|
||||
return ' '; // Emoji par défaut
|
||||
}
|
||||
|
||||
// Variables globales
|
||||
let map;
|
||||
let eventMarkers = [];
|
||||
let eventTypeCounts = {};
|
||||
let allEvents = [];
|
||||
|
||||
// Initialisation de la carte
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
initMap();
|
||||
loadEvents();
|
||||
});
|
||||
|
||||
function initMap() {
|
||||
// Initialiser la carte MapLibre
|
||||
map = new maplibregl.Map({
|
||||
container: 'map',
|
||||
style: 'https://tiles.openfreemap.org/styles/liberty',
|
||||
center: [2.3522, 48.8566], // Paris par défaut
|
||||
zoom: 4
|
||||
});
|
||||
|
||||
// Ajouter les contrôles de navigation
|
||||
map.addControl(new maplibregl.NavigationControl());
|
||||
|
||||
// Ajouter le contrôle de géolocalisation
|
||||
map.addControl(new maplibregl.GeolocateControl({
|
||||
positionOptions: {
|
||||
enableHighAccuracy: true
|
||||
},
|
||||
trackUserLocation: true,
|
||||
showUserHeading: true
|
||||
}));
|
||||
}
|
||||
|
||||
function loadEvents() {
|
||||
fetch('https://api.openeventdatabase.org/event?')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.features && data.features.length > 0) {
|
||||
allEvents = data.features;
|
||||
processEvents();
|
||||
createEventTypeFilters();
|
||||
addEventsToMap();
|
||||
updateEventInfo();
|
||||
} else {
|
||||
document.getElementById('event-info').innerHTML = '<p>No events found</p>';
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error loading events:', error);
|
||||
document.getElementById('event-info').innerHTML = '<p>Error loading events</p>';
|
||||
});
|
||||
}
|
||||
|
||||
function processEvents() {
|
||||
eventTypeCounts = {};
|
||||
allEvents.forEach(event => {
|
||||
const eventType = event.properties.what || 'unknown';
|
||||
eventTypeCounts[eventType] = (eventTypeCounts[eventType] || 0) + 1;
|
||||
});
|
||||
}
|
||||
|
||||
function createEventTypeFilters() {
|
||||
const filterList = document.getElementById('filter-list');
|
||||
filterList.innerHTML = '';
|
||||
|
||||
const sortedTypes = Object.keys(eventTypeCounts).sort();
|
||||
|
||||
sortedTypes.forEach(eventType => {
|
||||
const count = eventTypeCounts[eventType];
|
||||
const li = document.createElement('li');
|
||||
|
||||
const checkbox = document.createElement('input');
|
||||
checkbox.type = 'checkbox';
|
||||
checkbox.id = `filter-${eventType}`;
|
||||
checkbox.checked = true;
|
||||
checkbox.addEventListener('change', filterEvents);
|
||||
|
||||
const label = document.createElement('label');
|
||||
label.htmlFor = `filter-${eventType}`;
|
||||
label.textContent = `${eventType} (${count})`;
|
||||
|
||||
li.appendChild(checkbox);
|
||||
li.appendChild(label);
|
||||
filterList.appendChild(li);
|
||||
});
|
||||
|
||||
// Boutons de sélection
|
||||
document.getElementById('select-all').addEventListener('click', () => {
|
||||
document.querySelectorAll('#filter-list input[type="checkbox"]').forEach(cb => {
|
||||
cb.checked = true;
|
||||
});
|
||||
filterEvents();
|
||||
});
|
||||
|
||||
document.getElementById('deselect-all').addEventListener('click', () => {
|
||||
document.querySelectorAll('#filter-list input[type="checkbox"]').forEach(cb => {
|
||||
cb.checked = false;
|
||||
});
|
||||
filterEvents();
|
||||
});
|
||||
}
|
||||
|
||||
function addEventsToMap() {
|
||||
// Supprimer les marqueurs existants
|
||||
eventMarkers.forEach(marker => marker.remove());
|
||||
eventMarkers = [];
|
||||
|
||||
// Ajouter les nouveaux marqueurs avec emojis
|
||||
allEvents.forEach(event => {
|
||||
const coordinates = event.geometry.coordinates;
|
||||
const properties = event.properties;
|
||||
|
||||
// Créer l'élément marqueur avec emoji et forme de goutte
|
||||
const el = document.createElement('div');
|
||||
el.className = 'custom-marker';
|
||||
|
||||
// Créer la forme de goutte en arrière-plan avec emoji
|
||||
el.innerHTML = `
|
||||
<div class="marker-drop">
|
||||
<div class="marker-emoji">${getEventEmoji(properties)}</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
// Créer le contenu de la popup
|
||||
const popupContent = createPopupContent(properties);
|
||||
|
||||
// Créer la popup
|
||||
const popup = new maplibregl.Popup({
|
||||
closeButton: true,
|
||||
closeOnClick: true
|
||||
}).setHTML(popupContent);
|
||||
|
||||
// Créer et ajouter le marqueur
|
||||
const marker = new maplibregl.Marker(el)
|
||||
.setLngLat(coordinates)
|
||||
.setPopup(popup)
|
||||
.addTo(map);
|
||||
|
||||
eventMarkers.push({
|
||||
marker: marker,
|
||||
eventType: properties.what || 'unknown',
|
||||
element: el
|
||||
});
|
||||
});
|
||||
|
||||
// Ajuster la vue pour inclure tous les événements
|
||||
if (allEvents.length > 0) {
|
||||
const bounds = new maplibregl.LngLatBounds();
|
||||
allEvents.forEach(event => {
|
||||
bounds.extend(event.geometry.coordinates);
|
||||
});
|
||||
map.fitBounds(bounds, { padding: 50, maxZoom: 12 });
|
||||
}
|
||||
}
|
||||
|
||||
function createPopupContent(properties) {
|
||||
const title = properties.label || properties.name || 'Événement';
|
||||
const what = properties.what || 'Non spécifié';
|
||||
const description = properties.description || 'Aucune description disponible';
|
||||
|
||||
return `
|
||||
<div class="event-popup">
|
||||
<h3 style="margin-top: 0; color: #0078ff;">${title}</h3>
|
||||
<p><strong>Type:</strong> ${what}</p>
|
||||
<p><strong>Description:</strong> ${description}</p>
|
||||
${properties.id ? `<p><a href="/demo/edit/${properties.id}" style="color: #0078ff; font-weight: bold;">Modifier</a></p>` : ''}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
function filterEvents() {
|
||||
const checkedTypes = Array.from(
|
||||
document.querySelectorAll('#filter-list input[type="checkbox"]:checked')
|
||||
).map(cb => cb.id.replace('filter-', ''));
|
||||
|
||||
eventMarkers.forEach(({ marker, eventType, element }) => {
|
||||
if (checkedTypes.includes(eventType)) {
|
||||
element.style.display = 'block';
|
||||
} else {
|
||||
element.style.display = 'none';
|
||||
}
|
||||
});
|
||||
|
||||
updateEventInfo();
|
||||
}
|
||||
|
||||
function updateEventInfo() {
|
||||
const checkedTypes = Array.from(
|
||||
document.querySelectorAll('#filter-list input[type="checkbox"]:checked')
|
||||
).map(cb => cb.id.replace('filter-', ''));
|
||||
|
||||
const visibleCount = checkedTypes.reduce((sum, type) => {
|
||||
return sum + (eventTypeCounts[type] || 0);
|
||||
}, 0);
|
||||
|
||||
const totalCount = allEvents.length;
|
||||
|
||||
document.getElementById('event-info').innerHTML = `
|
||||
<p>Showing ${visibleCount} of ${totalCount} events</p>
|
||||
<p>Event types: ${checkedTypes.length} selected</p>
|
||||
`;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue