From cddf5db1cb1b05f02f9c1cce5cf74441a9f7b002 Mon Sep 17 00:00:00 2001 From: Innovator Dev Date: Sun, 21 Jan 2024 22:17:38 +0200 Subject: [PATCH] Implemented `configuration` mechanism, added method for fetching data used by all other dataSets implementations --- assets/js/app.js | 4 ++-- assets/js/app.min.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/assets/js/app.js b/assets/js/app.js index 71786d7..1c9fe6b 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -672,7 +672,7 @@ const app = (() => { map.ref.panTo(new google.maps.LatLng(lat, lng)); } - }, (err) => { + }, () => { try { // Clear marker @@ -700,7 +700,7 @@ const app = (() => { // Show warning that location coult not be determined if (app.config.messages['location.error.unableToDetermine']) { - throw app.config.messages['location.error.unableToDetermine']; + notification(app.config.messages['location.error.unableToDetermine'], 'error', 10); } } catch (err) { diff --git a/assets/js/app.min.js b/assets/js/app.min.js index 95e4316..cf17e80 100644 --- a/assets/js/app.min.js +++ b/assets/js/app.min.js @@ -14,10 +14,10 @@ return g},notify:m,render:function(){p.add("initiateDirectionService",()=>{c.loa c.mapCenter.lng)),c.ref.setZoom(14))});h.appendChild(a);a=document.createElement("div");a.classList.add("mapControlsContainer");const g=document.createElement("button");g.setAttribute("data-state","disabled");g.classList.add("mapCustomControl","separator","hide");g.innerHTML='';g.title="Activeaz\u0103/Dezactiveaz\u0103 localizarea persistent\u0103";g.type="button";g.addEventListener("click",l=>{l.preventDefault();l.stopPropagation();"disabled"===g.getAttribute("data-state")? (g.setAttribute("data-state","enabled"),g.classList.add("selected"),f.persistent=!0):(g.setAttribute("data-state","disabled"),g.classList.remove("selected"),f.persistent=!1)});const e=document.createElement("button");e.setAttribute("data-state","hideLocation");e.classList.add("mapCustomControl","separator");e.innerHTML='';e.title="Afi\u0219eaz\u0103/Ascunde loca\u021bia mea pe hart\u0103";e.type="button";e.addEventListener("click",l=>{l.preventDefault();l.stopPropagation(); navigator.geolocation?"hideLocation"===e.getAttribute("data-state")?(e.setAttribute("data-state","showLocation"),e.classList.add("selected"),g.classList.remove("hide"),p.fire("initiateDirectionService"),f.watcher=navigator.geolocation.watchPosition(b=>{const q=b.coords.latitude;b=b.coords.longitude;f.location.lat=q;f.location.lng=b;null===f.app&&(f.app=new google.maps.Marker({position:{lat:parseFloat(q),lng:parseFloat(b)},map:app.map.ref,title:"Loca\u021bia mea",optimized:!0,icon:{url:"https://iasi.digital/assets/pin/me.png", -size:new google.maps.Size(22,35),origin:new google.maps.Point(0,0),anchor:new google.maps.Point(11,35),scaledSize:new google.maps.Size(22,35)}}),f.app.setMap(c.ref));f.app.setPosition(new google.maps.LatLng(q,b));f.lastUpdate=(new Date).getTime();f.visible=!0;!0===f.persistent&&c.ref.panTo(new google.maps.LatLng(q,b))},b=>{try{if(null!==f.app&&(f.app.setMap(null),f.app=null),null!==f.watcher&&(navigator.geolocation.clearWatch(f.watcher),f.watcher=null),f.lastUpdate=null,f.visible=!1,f.location.lat= -0,f.location.lng=0,app.events.fire("clearDirectionService"),app.config.messages["location.error.unableToDetermine"])throw app.config.messages["location.error.unableToDetermine"];}catch(q){m(q,"error",10),e.setAttribute("data-state","hideLocation"),e.classList.remove("selected"),e.setAttribute("disabled","disabled"),g.classList.remove("selected"),g.classList.add("hide"),g.setAttribute("data-state","disabled"),f.persistent=!1}},{enableHighAccuracy:!0,timeout:5E3})):(e.setAttribute("data-state","hideLocation"), -e.classList.remove("selected"),g.classList.remove("selected"),g.classList.add("hide"),g.setAttribute("data-state","disabled"),f.persistent=!1,null!==f.app&&(f.app.setMap(null),f.app=null),null!==f.watcher&&(navigator.geolocation.clearWatch(f.watcher),f.watcher=null),f.lastUpdate=null,f.visible=!1,f.location.lat=0,f.location.lng=0,app.events.fire("clearDirectionService")):(e.setAttribute("data-state","hideLocation"),e.classList.remove("selected"),g.classList.add("hide"))});a.appendChild(g);a.appendChild(e); -c.ref.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(h);c.ref.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(a);c.controls={spinner:d.querySelector("h2 .spinner"),publicTransportation:d.querySelector('input[type=checkbox][name="toggle.mobility.publicTransportation"]'),publicParking:d.querySelector('input[type=checkbox][name="toggle.mobility.publicParking"]'),trafficLayer:d.querySelector('input[type=checkbox][name="toggle.mobility.trafficLayer"]'),airQuality:d.querySelector('input[type=checkbox][name="toggle.environment.airQuality"]'), +size:new google.maps.Size(22,35),origin:new google.maps.Point(0,0),anchor:new google.maps.Point(11,35),scaledSize:new google.maps.Size(22,35)}}),f.app.setMap(c.ref));f.app.setPosition(new google.maps.LatLng(q,b));f.lastUpdate=(new Date).getTime();f.visible=!0;!0===f.persistent&&c.ref.panTo(new google.maps.LatLng(q,b))},()=>{try{null!==f.app&&(f.app.setMap(null),f.app=null),null!==f.watcher&&(navigator.geolocation.clearWatch(f.watcher),f.watcher=null),f.lastUpdate=null,f.visible=!1,f.location.lat= +0,f.location.lng=0,app.events.fire("clearDirectionService"),app.config.messages["location.error.unableToDetermine"]&&m(app.config.messages["location.error.unableToDetermine"],"error",10)}catch(b){m(b,"error",10),e.setAttribute("data-state","hideLocation"),e.classList.remove("selected"),e.setAttribute("disabled","disabled"),g.classList.remove("selected"),g.classList.add("hide"),g.setAttribute("data-state","disabled"),f.persistent=!1}},{enableHighAccuracy:!0,timeout:5E3})):(e.setAttribute("data-state", +"hideLocation"),e.classList.remove("selected"),g.classList.remove("selected"),g.classList.add("hide"),g.setAttribute("data-state","disabled"),f.persistent=!1,null!==f.app&&(f.app.setMap(null),f.app=null),null!==f.watcher&&(navigator.geolocation.clearWatch(f.watcher),f.watcher=null),f.lastUpdate=null,f.visible=!1,f.location.lat=0,f.location.lng=0,app.events.fire("clearDirectionService")):(e.setAttribute("data-state","hideLocation"),e.classList.remove("selected"),g.classList.add("hide"))});a.appendChild(g); +a.appendChild(e);c.ref.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(h);c.ref.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(a);c.controls={spinner:d.querySelector("h2 .spinner"),publicTransportation:d.querySelector('input[type=checkbox][name="toggle.mobility.publicTransportation"]'),publicParking:d.querySelector('input[type=checkbox][name="toggle.mobility.publicParking"]'),trafficLayer:d.querySelector('input[type=checkbox][name="toggle.mobility.trafficLayer"]'),airQuality:d.querySelector('input[type=checkbox][name="toggle.environment.airQuality"]'), wasteCollection:d.querySelector('input[type=checkbox][name="toggle.environment.wasteCollection"]')};d.classList.remove("hide");d.querySelectorAll(".btn-toggle").forEach(l=>{const b=l.dataset;b.set&&(n[b.set]={app:null,watcher:null,loaded:!1,visible:!1,hasData:!1,updated:null,data:{},markers:[],selectedMarker:null},b.source&&(k(b.source,()=>{n[b.set].loaded=!0;n[b.set].app.getData()?(n[b.set].hasData=!0,n[b.set].app.init()):c.controls[b.set].setAttribute("disabled","disabled")}),l.addEventListener("click", ()=>{c.controls.spinner.classList.remove("hide");c.controls[b.set].checked?n[b.set].app.show():n[b.set].app.hide();c.controls.spinner.classList.add("hide")})),"trafficLayer"===b.set&&l.addEventListener("click",()=>{c.controls.spinner.classList.remove("hide");c.controls[b.set].checked?(n[b.set].app=new google.maps.TrafficLayer,n[b.set].app.setMap(c.ref),n[b.set].visible=!0):(n[b.set].visible=!1,n[b.set].app.setMap(null),n[b.set].app=null);c.controls.spinner.classList.add("hide")}))})}});r()}}})(); (()=>{const k=document.querySelector("body.page").dataset;k.bind&&(app.config=JSON.parse(atob(k.bind)));app.api("config.json").then(m=>m.ok?m.json():!1).then(m=>{app.config=Object.assign(app.config,m)}).catch(m=>{});app.render()})();