hop hours
This commit is contained in:
parent
7999ad078a
commit
3e7cb3c7ae
|
@ -26,5 +26,11 @@ https://overpass-api.de/api/interpreter?data=[out:json][timeout:15];(%20%20%20%2
|
|||
# licence
|
||||
Gnu Affero 3+
|
||||
|
||||
# Documentation
|
||||
* Leaflet:
|
||||
https://leafletjs.com/reference.html
|
||||
|
||||
# sources
|
||||
https://forge.chapril.org/tykayn/melting-pot
|
||||
# contact me
|
||||
https://www.cipherbliss.com/contact
|
42
js/main.js
42
js/main.js
|
@ -938,6 +938,7 @@ const loadQueryPoints = () => {
|
|||
}
|
||||
|
||||
};
|
||||
|
||||
function loadedSuccess() {
|
||||
document.querySelector('#success_load').classList.add('visible')
|
||||
setTimeout(function () {
|
||||
|
@ -945,6 +946,7 @@ function loadedSuccess(){
|
|||
}, 1000)
|
||||
$('#spinning_icon').fadeOut();
|
||||
}
|
||||
|
||||
function displayPointsFromApi(points) {
|
||||
|
||||
var resultAsGeojson = osmtogeojson(points);
|
||||
|
@ -961,9 +963,6 @@ function displayPointsFromApi(points) {
|
|||
}
|
||||
return true;
|
||||
},
|
||||
onzoomend: function(event){
|
||||
console.log('event', event);
|
||||
},
|
||||
onEachFeature: function (feature, layer) {
|
||||
var popupContent = '';
|
||||
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>' +
|
||||
'<a class="edit-button" href="https://www.openstreetmap.org/edit?editor=id&node=' + feature.properties.id + '">' +
|
||||
'✏️</a>';
|
||||
|
||||
console.log('layer', layer);
|
||||
var label = L.marker(layer._latlng, {
|
||||
icon: L.divIcon({
|
||||
iconUrl: 'https://www.cipherbliss.com/ou-manger/img/' + getIconFromTags(feature.properties.tags),
|
||||
|
@ -1036,9 +1033,7 @@ function displayPointsFromApi(points) {
|
|||
}
|
||||
|
||||
function makeCssClassFromTags(tags) {
|
||||
console.log('tags', tags);
|
||||
let tagKeys = Object.keys(tags);
|
||||
console.log('tagKeys', tagKeys);
|
||||
if (!tags) {
|
||||
return '';
|
||||
}
|
||||
|
@ -1068,18 +1063,46 @@ function makeCssClassFromTags(tags) {
|
|||
*/
|
||||
function getIsOpenFromOpeningHours(tags) {
|
||||
let isOpen = 'has-no-opening-hours';
|
||||
|
||||
let currentDay = new Date();
|
||||
let daysArray = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa']
|
||||
let todayInLetters = daysArray[currentDay.getDay()];
|
||||
let todayInHour = daysArray[currentDay.getHours()];
|
||||
|
||||
if (tags['opening_hours']) {
|
||||
let opening_hours = tags['opening_hours'].trim();
|
||||
|
||||
|
||||
// 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
|
||||
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)
|
||||
return isOpen;
|
||||
}
|
||||
|
||||
function getIconFromTags(tags) {
|
||||
let iconFileName = 'icon_restaurant.png';
|
||||
if (tags['man_made']) {
|
||||
|
@ -1136,6 +1159,10 @@ $('#query-button').click(function () {
|
|||
|
||||
let isLoading = false;
|
||||
|
||||
function removeOlderPoints() {
|
||||
// L.clearLayers()
|
||||
}
|
||||
|
||||
function loadOverpassQuery() {
|
||||
|
||||
// ne pas charger si on recherche déjà
|
||||
|
@ -1147,6 +1174,7 @@ function loadOverpassQuery() {
|
|||
|
||||
$.get(overpassApiUrl, function (geoDataPointsFromApi) {
|
||||
|
||||
removeOlderPoints()
|
||||
displayPointsFromApi(geoDataPointsFromApi);
|
||||
|
||||
loadedSuccess();
|
||||
|
|
Loading…
Reference in New Issue