hop hours

This commit is contained in:
Tykayn 2022-12-11 17:24:23 +01:00 committed by tykayn
parent 7999ad078a
commit 3e7cb3c7ae
2 changed files with 1097 additions and 1063 deletions

View File

@ -26,5 +26,11 @@ https://overpass-api.de/api/interpreter?data=[out:json][timeout:15];(%20%20%20%2
# licence # licence
Gnu Affero 3+ Gnu Affero 3+
# Documentation
* Leaflet:
https://leafletjs.com/reference.html
# sources # sources
https://forge.chapril.org/tykayn/melting-pot https://forge.chapril.org/tykayn/melting-pot
# contact me
https://www.cipherbliss.com/contact

View File

@ -938,6 +938,7 @@ const loadQueryPoints = () => {
} }
}; };
function loadedSuccess() { function loadedSuccess() {
document.querySelector('#success_load').classList.add('visible') document.querySelector('#success_load').classList.add('visible')
setTimeout(function () { setTimeout(function () {
@ -945,6 +946,7 @@ function loadedSuccess(){
}, 1000) }, 1000)
$('#spinning_icon').fadeOut(); $('#spinning_icon').fadeOut();
} }
function displayPointsFromApi(points) { function displayPointsFromApi(points) {
var resultAsGeojson = osmtogeojson(points); var resultAsGeojson = osmtogeojson(points);
@ -961,9 +963,6 @@ function displayPointsFromApi(points) {
} }
return true; return true;
}, },
onzoomend: function(event){
console.log('event', event);
},
onEachFeature: function (feature, layer) { onEachFeature: function (feature, layer) {
var popupContent = ''; var popupContent = '';
popupContent = popupContent + '<dt>@id</dt><dd>' + feature.properties.type + '/' + feature.properties.id + '</dd>'; popupContent = popupContent + '<dt>@id</dt><dd>' + feature.properties.type + '/' + feature.properties.id + '</dd>';
@ -996,8 +995,6 @@ function displayPointsFromApi(points) {
let html = '<a href="https://www.openstreetmap.org/' + feature.id + '"> ' + rest_name + ' ' + cuisine + '</a>' + let html = '<a href="https://www.openstreetmap.org/' + feature.id + '"> ' + rest_name + ' ' + cuisine + '</a>' +
'<a class="edit-button" href="https://www.openstreetmap.org/edit?editor=id&node=' + feature.properties.id + '">' + '<a class="edit-button" href="https://www.openstreetmap.org/edit?editor=id&node=' + feature.properties.id + '">' +
'✏️</a>'; '✏️</a>';
console.log('layer', layer);
var label = L.marker(layer._latlng, { var label = L.marker(layer._latlng, {
icon: L.divIcon({ icon: L.divIcon({
iconUrl: 'https://www.cipherbliss.com/ou-manger/img/' + getIconFromTags(feature.properties.tags), iconUrl: 'https://www.cipherbliss.com/ou-manger/img/' + getIconFromTags(feature.properties.tags),
@ -1036,9 +1033,7 @@ function displayPointsFromApi(points) {
} }
function makeCssClassFromTags(tags) { function makeCssClassFromTags(tags) {
console.log('tags', tags);
let tagKeys = Object.keys(tags); let tagKeys = Object.keys(tags);
console.log('tagKeys', tagKeys);
if (!tags) { if (!tags) {
return ''; return '';
} }
@ -1068,18 +1063,46 @@ function makeCssClassFromTags(tags) {
*/ */
function getIsOpenFromOpeningHours(tags) { function getIsOpenFromOpeningHours(tags) {
let isOpen = 'has-no-opening-hours'; let isOpen = 'has-no-opening-hours';
let currentDay = new Date(); let currentDay = new Date();
let daysArray = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'] let daysArray = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa']
let todayInLetters = daysArray[currentDay.getDay()]; let todayInLetters = daysArray[currentDay.getDay()];
let todayInHour = daysArray[currentDay.getHours()]; let todayInHour = daysArray[currentDay.getHours()];
if (tags['opening_hours']) { if (tags['opening_hours']) {
let opening_hours = tags['opening_hours'].trim();
// trouver les sections séparées par des points virgule // trouver les sections séparées par des points virgule
let sections = opening_hours.split(' ')
// séparer les sections d'ouverture par un espace entre la plage de jour et les heures // séparer les sections d'ouverture par un espace entre la plage de jour et les heures
sections.map(part => {
// prendre en compte les périodes de plusieurs jours Mo-Sa
// prise en compte d'un seul jour à la fois
if (part.indexOf(todayInLetters)) {
// voir si le jour actuel est inclus dans la section
// voir si les horaires de ce jour sont dans le futur
// dans ce cas le restaurant est ouvert, YES!
isOpen = 'is-open-this-day'
let splitDay = part.split('-')
if (splitDay.length) {
let start = splitDay[0]
let end = splitDay[1]
if (start.substring(0, 2) < todayInHour) {
//sera ouvert aujourd'hui
} else {
//était ouvert aujourd'hui
}
}
}
})
} }
console.log(tags['opening_hours'], isOpen) console.log(tags['opening_hours'], isOpen)
return isOpen; return isOpen;
} }
function getIconFromTags(tags) { function getIconFromTags(tags) {
let iconFileName = 'icon_restaurant.png'; let iconFileName = 'icon_restaurant.png';
if (tags['man_made']) { if (tags['man_made']) {
@ -1136,6 +1159,10 @@ $('#query-button').click(function () {
let isLoading = false; let isLoading = false;
function removeOlderPoints() {
// L.clearLayers()
}
function loadOverpassQuery() { function loadOverpassQuery() {
// ne pas charger si on recherche déjà // ne pas charger si on recherche déjà
@ -1147,6 +1174,7 @@ function loadOverpassQuery() {
$.get(overpassApiUrl, function (geoDataPointsFromApi) { $.get(overpassApiUrl, function (geoDataPointsFromApi) {
removeOlderPoints()
displayPointsFromApi(geoDataPointsFromApi); displayPointsFromApi(geoDataPointsFromApi);
loadedSuccess(); loadedSuccess();