Fix holiday season and improve icon selection

This commit is contained in:
Midgard 2020-05-21 01:44:14 +02:00
parent 9e72a5dcc2
commit 855488d227
Signed by: midgard
GPG Key ID: 511C112F1331BBB4
1 changed files with 15 additions and 12 deletions

View File

@ -1,8 +1,8 @@
$(document).ready(function() { $(document).ready(function() {
/* change image path */
L.Icon.Default.imagePath = "img/"; L.Icon.Default.imagePath = "img/";
var popuptemplate = Handlebars.compile($("#popup-template").html()); var popuptemplate = Handlebars.compile($("#popup-template").html());
var RedIcon = L.Icon.Default.extend({ var RedIcon = L.Icon.Default.extend({
options: { options: {
iconUrl: "red-marker.png" iconUrl: "red-marker.png"
@ -13,11 +13,15 @@ $(document).ready(function() {
iconUrl: "christmas-marker.png" iconUrl: "christmas-marker.png"
} }
}); });
var blueIcon = new L.Icon.Default();
var redIcon = new RedIcon(); var redIcon = new RedIcon();
var BlueIcon = L.Icon.Default.extend({});
var blueIcon = new BlueIcon();
var christmasIcon = new ChristmasIcon(); var christmasIcon = new ChristmasIcon();
var christmasHoliday = Date.now() < new Date("2016-01-04").getTime();
var now = new Date();
var christmasSeason =
now.getTime() > new Date(now.getFullYear() + "-12-20").getTime() ||
now.getTime() < new Date(now.getFullYear() + "-01-04").getTime();
function onEachFeature(feature, layer) { function onEachFeature(feature, layer) {
if (feature.properties) { if (feature.properties) {
@ -28,16 +32,15 @@ $(document).ready(function() {
} }
function pointToLayer(feature, latlng) { function pointToLayer(feature, latlng) {
var marker = new HoverMarker(latlng, { icon: redIcon, riseOnHover: true}); var icon = redIcon;
if (feature.properties) { if (feature.properties) {
if (feature.properties.holidays && christmasHoliday) { if (feature.properties.holidays && christmasSeason) {
var marker = new HoverMarker(latlng, { icon: christmasIcon, riseOnHover: true}); icon = christmasIcon;
} } else if (!feature.properties.hours.saturday && !feature.properties.hours.sunday) {
if (!feature.properties.hours.saturday && !feature.properties.hours.sunday) { icon = blueIcon;
var marker = new HoverMarker(latlng, { icon: blueIcon, riseOnHover: true});
} }
} }
return marker; return new HoverMarker(latlng, { icon: icon, riseOnHover: true});
} }
var map = L.map("map").setView([50.702, 4.335], 9); var map = L.map("map").setView([50.702, 4.335], 9);
@ -150,7 +153,7 @@ $(document).ready(function() {
position: "bottomleft" position: "bottomleft"
}).addTo(map); }).addTo(map);
var legend = new SimpleControl("#legend-template", christmasHoliday ? "holiday-legend" : "legend", { var legend = new SimpleControl("#legend-template", christmasSeason ? "holiday-legend" : "legend", {
position: "bottomright" position: "bottomright"
}).addTo(map); }).addTo(map);
}); });