From 2c80712fb92b3c0b66340ee95d5738a60aed6742 Mon Sep 17 00:00:00 2001 From: Xaver Maierhofer Date: Sat, 17 Sep 2016 19:59:18 +0200 Subject: [PATCH] [TASK] Automatic map switch based on time --- lib/map.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/lib/map.js b/lib/map.js index 79c6645..da4a555 100644 --- a/lib/map.js +++ b/lib/map.js @@ -132,10 +132,42 @@ define(["map/clientlayer", "map/labelslayer", }); } - var iconOnline = {color: "#1566A9", fillColor: "#1566A9", radius: 6, fillOpacity: 0.5, opacity: 0.5, weight: 2, className: "stroke-first"}; - var iconOffline = {color: "#D43E2A", fillColor: "#D43E2A", radius: 3, fillOpacity: 0.5, opacity: 0.5, weight: 1, className: "stroke-first"}; - var iconLost = {color: "#D43E2A", fillColor: "#D43E2A", radius: 4, fillOpacity: 0.8, opacity: 0.8, weight: 1, className: "stroke-first"}; - var iconAlert = {color: "#D43E2A", fillColor: "#D43E2A", radius: 5, fillOpacity: 0.8, opacity: 0.8, weight: 2, className: "stroke-first"}; + var iconOnline = { + color: "#1566A9", + fillColor: "#1566A9", + radius: 6, + fillOpacity: 0.5, + opacity: 0.5, + weight: 2, + className: "stroke-first" + }; + var iconOffline = { + color: "#D43E2A", + fillColor: "#D43E2A", + radius: 3, + fillOpacity: 0.5, + opacity: 0.5, + weight: 1, + className: "stroke-first" + }; + var iconLost = { + color: "#D43E2A", + fillColor: "#D43E2A", + radius: 4, + fillOpacity: 0.8, + opacity: 0.8, + weight: 1, + className: "stroke-first" + }; + var iconAlert = { + color: "#D43E2A", + fillColor: "#D43E2A", + radius: 5, + fillOpacity: 0.8, + opacity: 0.8, + weight: 2, + className: "stroke-first" + }; var iconNew = {color: "#1566A9", fillColor: "#93E929", radius: 6, fillOpacity: 1.0, opacity: 0.5, weight: 2}; return function (config, linkScale, sidebar, router, buttons) { @@ -241,6 +273,18 @@ define(["map/clientlayer", "map/labelslayer", el.classList.add("map"); map = L.map(el, options); + var now = new Date(); + config.mapLayers.forEach(function (item, i) { + if (item.config.start <= now.getHours() || item.config.end > now.getHours()) { + item.config.order = item.config.start * -1; + } else { + item.config.order = i; + } + }); + + config.mapLayers = config.mapLayers.sort(function (a, b) { + return a.config.order - b.config.order; + }); var layers = config.mapLayers.map(function (d) { return { @@ -294,8 +338,8 @@ define(["map/clientlayer", "map/labelslayer", if (e.layer.options.mode) { document.querySelector("head").innerHTML += ""; document.querySelector("html").classList.add(e.layer.options.mode); - var cssInterval = setInterval(function() { - if(document.querySelector(".css-mode").sheet) { + var cssInterval = setInterval(function () { + if (document.querySelector(".css-mode").sheet) { labelsLayer.updateColor(); clearInterval(cssInterval); }