diff --git a/Lora-Map/resources/js/marker.js b/Lora-Map/resources/js/marker.js index 8e8884a..f84a888 100644 --- a/Lora-Map/resources/js/marker.js +++ b/Lora-Map/resources/js/marker.js @@ -7,6 +7,7 @@ _Markers: {}, _Sensors: {}, _SensorSettings: {}, + _History: {}, /// public functions ChangeFilter: function (select) { this.VisibleMarkers = {}; @@ -53,6 +54,21 @@ return this; }, /// private functions + _ClearHistory: function (key) { + if (Object.prototype.hasOwnProperty.call(this._History, key)) { + if (typeof this._History[key].Polyline === 'object') { + this._History[key].Polyline.remove(); + delete this._History[key]; + } + } + }, + _CreateLatLonFromHist: function (key) { + var latlngs = []; + for (var i = 0; i < this._History[key].Items.length; i++) { + latlngs.push([this._History[key].Items[i][0], this._History[key].Items[i][1]]); + } + return latlngs; + }, _ParseAJAXLoc: function (serverLocation) { this.LocationData = serverLocation; for (var key in this.LocationData) { @@ -113,11 +129,16 @@ } } } + if (positionItem.History.length > 0) { + this._UpdateHistory(positionItem.History, key); + } else { + this._ClearHistory(key); + } } } MenuObject.UpdateStatus(); - MenuObject._Update_pannels_info(); - }, + MenuObject.UpdatePannelsInfo(); + }, _ParseAJAXPanic: function (serverPanic) { this.PanicData = serverPanic; for (var id in this.PanicData) { @@ -167,5 +188,38 @@ } } } + }, + _UpdateHistory: function (History, key) { + if (!Object.prototype.hasOwnProperty.call(this._History, key)) { + this._History[key] = { Items: History }; + this._History[key].Polyline = L.polyline(this._CreateLatLonFromHist(key), { color: 'blue', weight: 2, bubblingMouseEvents: false, interactive: false }).addTo(MapObject.Map); + } + if (History[0][2] !== this._History[key].Items[0][2] || History[History.length - 1][2] !== this._History[key].Items[this._History[key].Items.length - 1][2]) { + if (History[History.length - 1][2] !== this._History[key].Items[this._History[key].Items.length - 1][2]) { + // Last element are different, so add element to the line + for (var i = History.length - 1; i >= 0; i--) { + if (History[i][2] === this._History[key].Items[this._History[key].Items.length - 1][2]) { + break; + } + } + for (var j = i + 1; j < History.length; j++) { + this._History[key].Items.push(History[j]); + } + } + if (History[0][2] !== this._History[key].Items[0][2]) { + //First elemt are different, so delete element from the line + var deletefirst = 0; + for (var k = 0; k < this._History[key].Items.length; k++) { + if (History[0][2] === this._History[key].Items[k][2]) { + break; + } + deletefirst++; + } + for (var l = 0; l < deletefirst; l++) { + this._History[key].Items.splice(0, 1); + } + } + this._History[key].Polyline.setLatLngs(this._CreateLatLonFromHist(key)); + } } }.Start(); \ No newline at end of file