diff --git a/CHANGELOG b/CHANGELOG
index 8d82863..73e7ed5 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,5 +1,10 @@
# Changelogs
+## 1.2.9
+### New Features
+### Bugfixes
+### Changes
+
## 1.2.8
### New Features
* Implement #12 Make icon transparent if there is no data update
diff --git a/Lora-Map/resources/js/functions.js b/Lora-Map/resources/js/functions.js
index 8873c70..b689251 100644
--- a/Lora-Map/resources/js/functions.js
+++ b/Lora-Map/resources/js/functions.js
@@ -1,43 +1,45 @@
-setInterval(timecorrectionrunner, 60000);
-timecorrectionrunner();
-
-function timecorrectionrunner() {
- var timecorrection = new XMLHttpRequest();
- timecorrection.onreadystatechange = parseAjaxTimecorrection;
- timecorrection.open("GET", "/currenttime", true);
- timecorrection.send();
-}
-
-var timeOffset = 0;
-
-function parseAjaxTimecorrection() {
- if (this.readyState === 4 && this.status === 200) {
- utcobject = JSON.parse(this.responseText);
+var FunctionsObject = {
+ _internalTimeOffset: 0,
+ Start: function () {
+ setInterval(this._Runner, 60000);
+ this._Runner();
+ return this;
+ },
+ _Runner: function () {
+ var timecorrection = new XMLHttpRequest();
+ timecorrection.onreadystatechange = function () {
+ if (timecorrection.readyState === 4 && timecorrection.status === 200) {
+ FunctionsObject._ParseAJAX(JSON.parse(timecorrection.responseText));
+ }
+ };
+ timecorrection.open("GET", "/currenttime", true);
+ timecorrection.send();
+ },
+ _ParseAJAX: function (utcobject) {
if (utcobject.hasOwnProperty("utc")) {
- timeOffset = Date.now() - Date.parse(utcobject["utc"]);
+ this._internalTimeOffset = Date.now() - Date.parse(utcobject["utc"]);
+ }
+ },
+ TimeCalculation: function (timestr, type) {
+ if (type === "diffraw" || type === "difftext") {
+ var diff = Math.round((Date.now() - Date.parse(timestr) - this._internalTimeOffset) / 1000);
+ if (type === "diffraw") {
+ return diff;
+ }
+ if (diff < 60) {
+ return diff + " s";
+ }
+ if (diff < 60 * 60) {
+ return Math.floor(diff / 60) + " m";
+ }
+ if (diff < 60 * 60 * 24) {
+ return Math.floor(diff / (60 * 60)) + " h";
+ }
+ return Math.floor(diff / (60 * 60 * 24)) + " d";
+ } else if (type === "str") {
+ var date = new Date(Date.parse(timestr) + this._internalTimeOffset);
+ var str = date.toLocaleString();
+ return str;
}
}
-}
-
-function timeCalculation(timestr, type) {
- if (type === "diffraw" || type === "difftext") {
- var diff = Math.round((Date.now() - Date.parse(timestr) - timeOffset) / 1000);
- if (type === "diffraw") {
- return diff;
- }
- if (diff < 60) {
- return diff + " s";
- }
- if (diff < 60 * 60) {
- return Math.floor(diff / 60) + " m";
- }
- if (diff < 60 * 60 * 24) {
- return Math.floor(diff / (60 * 60)) + " h";
- }
- return Math.floor(diff / (60 * 60 * 24)) + " d";
- } else if (type === "str") {
- var date = new Date(Date.parse(timestr) + timeOffset);
- var str = date.toLocaleString();
- return str;
- }
-}
\ No newline at end of file
+}.Start();
\ No newline at end of file
diff --git a/Lora-Map/resources/js/map.js b/Lora-Map/resources/js/map.js
index 747797c..674989b 100644
--- a/Lora-Map/resources/js/map.js
+++ b/Lora-Map/resources/js/map.js
@@ -1,53 +1,60 @@
-var mymap = L.map('bigmap').setView(["{%START_LOCATION%}"], 16);
-
-GetMapLayers();
-function GetMapLayers() {
- var layergetter = new XMLHttpRequest();
- layergetter.onreadystatechange = function () {
- if (layergetter.readyState === 4 && layergetter.status === 200) {
- var maps = JSON.parse(layergetter.responseText);
- var i = 0;
- for (var key in maps) {
- i++;
- }
- if (i === 1) {
- L.tileLayer(maps["online"]["url"], {
- attribution: maps["online"]["attribution"],
- minZoom: maps["online"]["minZoom"],
- maxZoom: maps["online"]["maxZoom"]
- }).addTo(mymap);
- } else {
- var baseMaps = {};
- for (key in maps) {
- if (key !== "online") {
- var basemap = L.tileLayer(maps[key]["url"], {
- attribution: maps[key]["attribution"],
- minZoom: maps[key]["minZoom"],
- maxZoom: maps[key]["maxZoom"],
- errorTileUrl: "css/icons/failtile.png"
- });
- basemap.addTo(mymap);
- baseMaps[maps[key]["title"]] = basemap;
- break;
- }
- }
- for (key in maps) {
- if (!baseMaps.hasOwnProperty(maps[key]["title"])) {
- baseMaps[maps[key]["title"]] = L.tileLayer(maps[key]["url"], {
- attribution: maps[key]["attribution"],
- minZoom: maps[key]["minZoom"],
- maxZoom: maps[key]["maxZoom"],
- errorTileUrl: "css/icons/failtile.png"
- });
- }
- }
- L.control.layers(baseMaps).addTo(mymap);
+var MapObject = {
+ Map: {},
+ Start: function () {
+ this.Map = L.map('bigmap').setView(["{%START_LOCATION%}"], 16);
+ this._GetMapLayers();
+ return this;
+ },
+ _GetMapLayers: function () {
+ var layergetter = new XMLHttpRequest();
+ layergetter.onreadystatechange = function () {
+ if (layergetter.readyState === 4 && layergetter.status === 200) {
+ MapObject._ParseAJAXLayers(JSON.parse(layergetter.responseText));
}
+ };
+ layergetter.open("GET", "/getlayer", true);
+ layergetter.send();
+ },
+ _ParseAJAXLayers: function (maps) {
+ var i = 0;
+ for (var key in maps) {
+ i++;
}
- };
- layergetter.open("GET", "/getlayer", true);
- layergetter.send();
-}
+ if (i === 1) {
+ L.tileLayer(maps["online"]["url"], {
+ attribution: maps["online"]["attribution"],
+ minZoom: maps["online"]["minZoom"],
+ maxZoom: maps["online"]["maxZoom"]
+ }).addTo(this.Map);
+ } else {
+ var baseMaps = {};
+ for (key in maps) {
+ if (key !== "online") {
+ var basemap = L.tileLayer(maps[key]["url"], {
+ attribution: maps[key]["attribution"],
+ minZoom: maps[key]["minZoom"],
+ maxZoom: maps[key]["maxZoom"],
+ errorTileUrl: "css/icons/failtile.png"
+ });
+ basemap.addTo(this.Map);
+ baseMaps[maps[key]["title"]] = basemap;
+ break;
+ }
+ }
+ for (key in maps) {
+ if (!baseMaps.hasOwnProperty(maps[key]["title"])) {
+ baseMaps[maps[key]["title"]] = L.tileLayer(maps[key]["url"], {
+ attribution: maps[key]["attribution"],
+ minZoom: maps[key]["minZoom"],
+ maxZoom: maps[key]["maxZoom"],
+ errorTileUrl: "css/icons/failtile.png"
+ });
+ }
+ }
+ L.control.layers(baseMaps).addTo(this.Map);
+ }
+ }
+}.Start();
var SpecialMarkers = new Array();
GetGeoLayer();
@@ -100,7 +107,7 @@ function GetGeoLayer() {
return L.marker(latlng, { icon: L.icon({ iconUrl: "css/icons/cctv.png", iconSize: [32, 32] }) });
}
}
- }).addTo(mymap);
+ }).addTo(MapObject.Map);
}
}
};
@@ -108,8 +115,8 @@ function GetGeoLayer() {
geogetter.send();
}
-mymap.on('zoomend', function () {
- var currentZoom = mymap.getZoom();
+MapObject.Map.on('zoomend', function () {
+ var currentZoom = MapObject.Map.getZoom();
if (currentZoom < 14) {
SpecialMarkers.forEach(function (elem, index) {
if (elem.feature.properties["description"] === "snumber") {
@@ -190,7 +197,7 @@ mymap.on('zoomend', function () {
}
});
-mymap.on("click", hidePanel);
+MapObject.Map.on("click", hidePanel);
function hidePanel(e) {
showHidePanel(null);
diff --git a/Lora-Map/resources/js/marker.js b/Lora-Map/resources/js/marker.js
index dea8915..7c60fa2 100644
--- a/Lora-Map/resources/js/marker.js
+++ b/Lora-Map/resources/js/marker.js
@@ -1,27 +1,37 @@
-setInterval(datarunner, 1000);
-function datarunner() {
- var loc = new XMLHttpRequest();
- loc.onreadystatechange = parseAjaxLoc;
- loc.open("GET", "/loc", true);
- loc.send();
+var MarkerObject = {
+ _Markers: {},
+ PanicData: {},
+ LocationData: {},
+ Start: function () {
+ setInterval(this._Runner, 1000);
+ return this;
+ },
+ _Runner: function () {
+ var loc = new XMLHttpRequest();
+ loc.onreadystatechange = function () {
+ if (loc.readyState === 4 && loc.status === 200) {
+ MarkerObject._ParseAJAXLoc(JSON.parse(loc.responseText));
+ }
+ };
+ loc.open("GET", "/loc", true);
+ loc.send();
- var panic = new XMLHttpRequest();
- panic.onreadystatechange = parseAjaxPanic;
- panic.open("GET", "/panic", true);
- panic.send();
-}
-
-var markers = {};
-var serverLocation = {};
-//https://leafletjs.com/reference-1.4.0.html#marker
-function parseAjaxLoc() {
- if (this.readyState === 4 && this.status === 200) {
- serverLocation = JSON.parse(this.responseText);
- for (var key in serverLocation) {
- if (serverLocation.hasOwnProperty(key)) {
- var positionItem = serverLocation[key];
+ var panic = new XMLHttpRequest();
+ panic.onreadystatechange = function () {
+ if (panic.readyState === 4 && panic.status === 200) {
+ MarkerObject._ParseAJAXPanic(JSON.parse(panic.responseText));
+ }
+ };
+ panic.open("GET", "/panic", true);
+ panic.send();
+ },
+ _ParseAJAXLoc: function (serverLocation) {
+ this.LocationData = serverLocation;
+ for (var key in this.LocationData) {
+ if (this.LocationData.hasOwnProperty(key)) {
+ var positionItem = this.LocationData[key];
if (positionItem['Latitude'] !== 0 || positionItem['Longitude'] !== 0) {
- if (!markers.hasOwnProperty(key)) {
+ if (!this._Markers.hasOwnProperty(key)) {
var marker = null;
if (positionItem['Icon'] === null) {
marker = L.marker([positionItem['Latitude'], positionItem['Longitude']], { 'title': positionItem['Name'] });
@@ -34,67 +44,63 @@ function parseAjaxLoc() {
});
marker = L.marker([positionItem['Latitude'], positionItem['Longitude']], { 'title': positionItem['Name'], 'icon': myIcon });
}
- markers[key] = marker.addTo(mymap).on("click", showMarkerInfo, key);
+ this._Markers[key] = marker.addTo(MapObject.Map).on("click", showMarkerInfo, key);
} else {
- markers[key].setLatLng([positionItem['Latitude'], positionItem['Longitude']]);
+ this._Markers[key].setLatLng([positionItem['Latitude'], positionItem['Longitude']]);
if (positionItem['Icon'] !== null) {
- if (markers[key]._icon.children.length === 0) {
- markers[key].setIcon(L.divIcon({
+ if (this._Markers[key]._icon.children.length === 0) {
+ this._Markers[key].setIcon(L.divIcon({
className: 'pos-marker',
iconSize: [56, 80],
iconAnchor: [0, 80],
html: ''
}));
- } else if (markers[key]._icon.children[0].hasAttribute("src")) {
- var old = markers[key]._icon.children[0]["src"].substring(markers[key]._icon.children[0]["src"].indexOf("/", 7) + 1);
+ } else if (this._Markers[key]._icon.children[0].hasAttribute("src")) {
+ var old = this._Markers[key]._icon.children[0]["src"].substring(this._Markers[key]._icon.children[0]["src"].indexOf("/", 7) + 1);
if (old !== positionItem['Icon']) {
- markers[key]._icon.children[0]["src"] = positionItem['Icon'];
+ this._Markers[key]._icon.children[0]["src"] = positionItem['Icon'];
}
}
} else {
- if (markers[key]._icon.children.length === 1 && markers[key]._icon.children[0].hasAttribute("src")) {
- markers[key].removeFrom(mymap);
- markers[key] = L.marker([positionItem['Latitude'], positionItem['Longitude']], { 'title': positionItem['Name'] }).addTo(mymap).on("click", showMarkerInfo, key);
+ if (this._Markers[key]._icon.children.length === 1 && this._Markers[key]._icon.children[0].hasAttribute("src")) {
+ this._Markers[key].removeFrom(MapObject.Map);
+ this._Markers[key] = L.marker([positionItem['Latitude'], positionItem['Longitude']], { 'title': positionItem['Name'] }).addTo(MapObject.Map).on("click", showMarkerInfo, key);
}
}
}
- var lasttime = timeCalculation(positionItem['Recievedtime'], "diffraw");
+ var lasttime = FunctionsObject.TimeCalculation(positionItem['Recievedtime'], "diffraw");
if (lasttime <= 5 * 60) {
- markers[key]._icon.style.opacity = 1;
+ this._Markers[key]._icon.style.opacity = 1;
} else if (lasttime > 5 * 60 && lasttime <= 15 * 60) {
- markers[key]._icon.style.opacity = 0.9 - (lasttime - 5 * 60) / (15 * 60 - 5 * 60) * (0.9 - 0.7);
+ this._Markers[key]._icon.style.opacity = 0.9 - (lasttime - 5 * 60) / (15 * 60 - 5 * 60) * (0.9 - 0.7);
} else if (lasttime > 15 * 60 && lasttime <= 30 * 60) {
- markers[key]._icon.style.opacity = 0.7 - (lasttime - 15 * 60) / (30 * 60 - 15 * 60) * (0.7 - 0.5);
+ this._Markers[key]._icon.style.opacity = 0.7 - (lasttime - 15 * 60) / (30 * 60 - 15 * 60) * (0.7 - 0.5);
} else if (lasttime > 30 * 60 && lasttime <= 60 * 60) {
- markers[key]._icon.style.opacity = 0.5 - (lasttime - 30 * 60) / (30 * 60 - 30 * 60) * (0.5 - 0.25);
+ this._Markers[key]._icon.style.opacity = 0.5 - (lasttime - 30 * 60) / (30 * 60 - 30 * 60) * (0.5 - 0.25);
} else if (lasttime > 60 * 60) {
- markers[key]._icon.style.opacity = 0.25;
+ this._Markers[key]._icon.style.opacity = 0.25;
}
}
}
}
updateStatus();
update_pannels_info();
- }
-}
-
-var serverPanic = {};
-function parseAjaxPanic() {
- if (this.readyState === 4 && this.status === 200) {
- serverPanic = JSON.parse(this.responseText);
- for (var id in serverPanic) {
- if (serverPanic.hasOwnProperty(id)) {
- var alertItem = serverPanic[id];
- if (markers.hasOwnProperty(id)) {
- var marker = markers[id];
- if (timeCalculation(alertItem["Recievedtime"], "diffraw") <= 10 && marker._icon.className.indexOf(" marker-alert") === -1) {
+ },
+ _ParseAJAXPanic: function (serverPanic) {
+ this.PanicData = serverPanic;
+ for (var id in this.PanicData) {
+ if (this.PanicData.hasOwnProperty(id)) {
+ var alertItem = this.PanicData[id];
+ if (this._Markers.hasOwnProperty(id)) {
+ var marker = this._Markers[id];
+ if (FunctionsObject.TimeCalculation(alertItem["Recievedtime"], "diffraw") <= 10 && marker._icon.className.indexOf(" marker-alert") === -1) {
marker._icon.className += " marker-alert";
showMarkerInfoPerId(id);
- } else if (timeCalculation(alertItem["Recievedtime"], "diffraw") > 10 && marker._icon.className.indexOf(" marker-alert") !== -1) {
+ } else if (FunctionsObject.TimeCalculation(alertItem["Recievedtime"], "diffraw") > 10 && marker._icon.className.indexOf(" marker-alert") !== -1) {
marker._icon.className = marker._icon.className.replace(" marker-alert", "");
}
}
}
}
}
-}
\ No newline at end of file
+}.Start();
\ No newline at end of file
diff --git a/Lora-Map/resources/js/menu.js b/Lora-Map/resources/js/menu.js
index 871124d..485bd09 100644
--- a/Lora-Map/resources/js/menu.js
+++ b/Lora-Map/resources/js/menu.js
@@ -41,8 +41,8 @@ function showMarkerInfoMenu() {
function update_pannels_info() {
document.getElementById("pannels_info").innerHTML = "";
- if (serverLocation.hasOwnProperty(statusToDevice)) {
- var positionItem = serverLocation[statusToDevice];
+ if (MarkerObject.LocationData.hasOwnProperty(statusToDevice)) {
+ var positionItem = MarkerObject.LocationData[statusToDevice];
var html = "