From 8ead897ea6b562567aceedee85a6c5c4f9088a5d Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Wed, 30 Nov 2016 09:59:14 +0500 Subject: Show events on map --- web/app/view/MapMarkerController.js | 36 ++++++++++++++-------- web/app/view/ReportController.js | 59 +++++++++++++++++++++++++++++++++---- 2 files changed, 77 insertions(+), 18 deletions(-) (limited to 'web') diff --git a/web/app/view/MapMarkerController.js b/web/app/view/MapMarkerController.js index 4ef55bbe..100ede9f 100644 --- a/web/app/view/MapMarkerController.js +++ b/web/app/view/MapMarkerController.js @@ -45,6 +45,7 @@ Ext.define('Traccar.view.MapMarkerController', { update: 'updateLatest' }, '#ReportRoute': { + add: 'addReportMarkers', load: 'loadReport', clear: 'clearReport' } @@ -197,13 +198,18 @@ Ext.define('Traccar.view.MapMarkerController', { }, loadReport: function (store, data) { - var i, position, point, geometry, marker, style; + var i, position, point; - this.clearReport(store); + this.addReportMarkers(store, data); if (data.length > 0) { this.reportRoute = []; for (i = 0; i < data.length; i++) { + position = data[i]; + point = ol.proj.fromLonLat([ + position.get('longitude'), + position.get('latitude') + ]); if (i === 0 || data[i].get('deviceId') !== data[i - 1].get('deviceId')) { this.reportRoute.push(new ol.Feature({ geometry: new ol.geom.LineString([]) @@ -211,33 +217,37 @@ Ext.define('Traccar.view.MapMarkerController', { this.reportRoute[this.reportRoute.length - 1].setStyle(this.getRouteStyle(data[i].get('deviceId'))); this.getView().getRouteSource().addFeature(this.reportRoute[this.reportRoute.length - 1]); } - position = data[i]; + this.reportRoute[this.reportRoute.length - 1].getGeometry().appendCoordinate(point); + } + this.getView().getMapView().fit(this.reportRoute[0].getGeometry(), this.getView().getMap().getSize()); + } + }, + + addReportMarkers: function (store, data) { + var i, position, point, geometry, marker, style; + this.clearReport(); + if (data.length > 0) { + for (i = 0; i < data.length; i++) { + position = data[i]; point = ol.proj.fromLonLat([ position.get('longitude'), position.get('latitude') ]); geometry = new ol.geom.Point(point); - marker = new ol.Feature(geometry); marker.set('record', position); - this.reportMarkers[position.get('id')] = marker; - this.getView().getReportSource().addFeature(marker); - style = this.getReportMarker(position.get('deviceId'), position.get('course')); /*style.getText().setText( Ext.Date.format(position.get('fixTime'), Traccar.Style.dateTimeFormat24));*/ - marker.setStyle(style); - - this.reportRoute[this.reportRoute.length - 1].getGeometry().appendCoordinate(point); + this.reportMarkers[position.get('id')] = marker; + this.getView().getReportSource().addFeature(marker); } - - this.getView().getMapView().fit(this.reportRoute[0].getGeometry(), this.getView().getMap().getSize()); } }, - clearReport: function (store) { + clearReport: function () { var key, i; if (this.reportRoute) { diff --git a/web/app/view/ReportController.js b/web/app/view/ReportController.js index 8f8cf741..a9c98a96 100644 --- a/web/app/view/ReportController.js +++ b/web/app/view/ReportController.js @@ -37,6 +37,11 @@ Ext.define('Traccar.view.ReportController', { 'map': { selectreport: 'selectReport' } + }, + store: { + '#ReportEvents': { + load: 'loadEvents' + } } } }, @@ -126,7 +131,7 @@ Ext.define('Traccar.view.ReportController', { clearReport: function (reportType) { this.getView().getStore().removeAll(); - if (reportType === 'trips') { + if (reportType === 'trips' || reportType === 'events') { Ext.getStore('ReportRoute').removeAll(); } }, @@ -139,6 +144,9 @@ Ext.define('Traccar.view.ReportController', { if (report instanceof Traccar.model.ReportTrip) { this.selectTrip(report); } + if (report instanceof Traccar.model.Event) { + this.selectEvent(report); + } } }, @@ -149,10 +157,16 @@ Ext.define('Traccar.view.ReportController', { }, selectReport: function (object, center) { - var reportType = this.lookupReference('reportTypeField').getValue(); - if (object instanceof Traccar.model.Position && reportType === 'route') { - this.getView().getSelectionModel().select([object], false, true); - this.getView().getView().focusRow(object); + var positionEvent, reportType = this.lookupReference('reportTypeField').getValue(); + if (object instanceof Traccar.model.Position) { + if (reportType === 'route') { + this.getView().getSelectionModel().select([object], false, true); + this.getView().getView().focusRow(object); + } else if (reportType === 'events') { + positionEvent = this.getView().getStore().findRecord('positionId', object.get('id'), 0, false, true, true); + this.getView().getSelectionModel().select([positionEvent], false, true); + this.getView().getView().focusRow(positionEvent); + } } }, @@ -170,6 +184,41 @@ Ext.define('Traccar.view.ReportController', { }); }, + selectEvent: function (event) { + var position; + if (event.get('positionId')) { + position = Ext.getStore('ReportRoute').getById(event.get('positionId')); + if (position) { + this.fireEvent('selectreport', position, true); + } + } + }, + + loadEvents: function (store, data) { + var i, eventObject, positionIds = {}; + Ext.getStore('ReportRoute').removeAll(); + if (data.length > 0) { + for (i = 0; i < data.length; i++) { + eventObject = data[i]; + if (eventObject.get('positionId')) { + positionIds[eventObject.get('positionId')] = true; + } + } + } + if (Object.keys(positionIds).length > 0) { + Ext.getStore('Positions').load({ + params: { + positionId: Object.keys(positionIds) + }, + callback: function (records, operation, success) { + if (success) { + Ext.getStore('ReportRoute').add(records); + } + } + }); + } + }, + downloadFile: function (requestUrl, requestParams) { Ext.Ajax.request({ url: requestUrl, -- cgit v1.2.3 From cffccb69b067fe0f838b0257d8cb48fa4e13ce2f Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Wed, 30 Nov 2016 11:15:07 +0500 Subject: - Removed unnecessary check - Use array instead of object - Use id as parameter name --- web/app/view/MapMarkerController.js | 66 +++++++++++++++++-------------------- web/app/view/ReportController.js | 8 ++--- 2 files changed, 35 insertions(+), 39 deletions(-) (limited to 'web') diff --git a/web/app/view/MapMarkerController.js b/web/app/view/MapMarkerController.js index 100ede9f..bda206ec 100644 --- a/web/app/view/MapMarkerController.js +++ b/web/app/view/MapMarkerController.js @@ -202,48 +202,44 @@ Ext.define('Traccar.view.MapMarkerController', { this.addReportMarkers(store, data); - if (data.length > 0) { - this.reportRoute = []; - for (i = 0; i < data.length; i++) { - position = data[i]; - point = ol.proj.fromLonLat([ - position.get('longitude'), - position.get('latitude') - ]); - if (i === 0 || data[i].get('deviceId') !== data[i - 1].get('deviceId')) { - this.reportRoute.push(new ol.Feature({ - geometry: new ol.geom.LineString([]) - })); - this.reportRoute[this.reportRoute.length - 1].setStyle(this.getRouteStyle(data[i].get('deviceId'))); - this.getView().getRouteSource().addFeature(this.reportRoute[this.reportRoute.length - 1]); - } - this.reportRoute[this.reportRoute.length - 1].getGeometry().appendCoordinate(point); + this.reportRoute = []; + for (i = 0; i < data.length; i++) { + position = data[i]; + point = ol.proj.fromLonLat([ + position.get('longitude'), + position.get('latitude') + ]); + if (i === 0 || data[i].get('deviceId') !== data[i - 1].get('deviceId')) { + this.reportRoute.push(new ol.Feature({ + geometry: new ol.geom.LineString([]) + })); + this.reportRoute[this.reportRoute.length - 1].setStyle(this.getRouteStyle(data[i].get('deviceId'))); + this.getView().getRouteSource().addFeature(this.reportRoute[this.reportRoute.length - 1]); } - - this.getView().getMapView().fit(this.reportRoute[0].getGeometry(), this.getView().getMap().getSize()); + this.reportRoute[this.reportRoute.length - 1].getGeometry().appendCoordinate(point); } + + this.getView().getMapView().fit(this.reportRoute[0].getGeometry(), this.getView().getMap().getSize()); }, addReportMarkers: function (store, data) { var i, position, point, geometry, marker, style; this.clearReport(); - if (data.length > 0) { - for (i = 0; i < data.length; i++) { - position = data[i]; - point = ol.proj.fromLonLat([ - position.get('longitude'), - position.get('latitude') - ]); - geometry = new ol.geom.Point(point); - marker = new ol.Feature(geometry); - marker.set('record', position); - style = this.getReportMarker(position.get('deviceId'), position.get('course')); - /*style.getText().setText( - Ext.Date.format(position.get('fixTime'), Traccar.Style.dateTimeFormat24));*/ - marker.setStyle(style); - this.reportMarkers[position.get('id')] = marker; - this.getView().getReportSource().addFeature(marker); - } + for (i = 0; i < data.length; i++) { + position = data[i]; + point = ol.proj.fromLonLat([ + position.get('longitude'), + position.get('latitude') + ]); + geometry = new ol.geom.Point(point); + marker = new ol.Feature(geometry); + marker.set('record', position); + style = this.getReportMarker(position.get('deviceId'), position.get('course')); + /*style.getText().setText( + Ext.Date.format(position.get('fixTime'), Traccar.Style.dateTimeFormat24));*/ + marker.setStyle(style); + this.reportMarkers[position.get('id')] = marker; + this.getView().getReportSource().addFeature(marker); } }, diff --git a/web/app/view/ReportController.js b/web/app/view/ReportController.js index a9c98a96..50775ace 100644 --- a/web/app/view/ReportController.js +++ b/web/app/view/ReportController.js @@ -195,20 +195,20 @@ Ext.define('Traccar.view.ReportController', { }, loadEvents: function (store, data) { - var i, eventObject, positionIds = {}; + var i, eventObject, positionIds = []; Ext.getStore('ReportRoute').removeAll(); if (data.length > 0) { for (i = 0; i < data.length; i++) { eventObject = data[i]; if (eventObject.get('positionId')) { - positionIds[eventObject.get('positionId')] = true; + positionIds.push(eventObject.get('positionId')); } } } - if (Object.keys(positionIds).length > 0) { + if (positionIds.length > 0) { Ext.getStore('Positions').load({ params: { - positionId: Object.keys(positionIds) + id: positionIds }, callback: function (records, operation, success) { if (success) { -- cgit v1.2.3 From 60fe1537206e2286423a7bc1ed5591b1f9c7a1d7 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Wed, 30 Nov 2016 11:23:46 +0500 Subject: Revert one check, remove another. --- web/app/view/MapMarkerController.js | 34 ++++++++++++++++++---------------- web/app/view/ReportController.js | 10 ++++------ 2 files changed, 22 insertions(+), 22 deletions(-) (limited to 'web') diff --git a/web/app/view/MapMarkerController.js b/web/app/view/MapMarkerController.js index bda206ec..97e75925 100644 --- a/web/app/view/MapMarkerController.js +++ b/web/app/view/MapMarkerController.js @@ -202,24 +202,26 @@ Ext.define('Traccar.view.MapMarkerController', { this.addReportMarkers(store, data); - this.reportRoute = []; - for (i = 0; i < data.length; i++) { - position = data[i]; - point = ol.proj.fromLonLat([ - position.get('longitude'), - position.get('latitude') - ]); - if (i === 0 || data[i].get('deviceId') !== data[i - 1].get('deviceId')) { - this.reportRoute.push(new ol.Feature({ - geometry: new ol.geom.LineString([]) - })); - this.reportRoute[this.reportRoute.length - 1].setStyle(this.getRouteStyle(data[i].get('deviceId'))); - this.getView().getRouteSource().addFeature(this.reportRoute[this.reportRoute.length - 1]); + if (data.length > 0) { + this.reportRoute = []; + for (i = 0; i < data.length; i++) { + position = data[i]; + point = ol.proj.fromLonLat([ + position.get('longitude'), + position.get('latitude') + ]); + if (i === 0 || data[i].get('deviceId') !== data[i - 1].get('deviceId')) { + this.reportRoute.push(new ol.Feature({ + geometry: new ol.geom.LineString([]) + })); + this.reportRoute[this.reportRoute.length - 1].setStyle(this.getRouteStyle(data[i].get('deviceId'))); + this.getView().getRouteSource().addFeature(this.reportRoute[this.reportRoute.length - 1]); + } + this.reportRoute[this.reportRoute.length - 1].getGeometry().appendCoordinate(point); } - this.reportRoute[this.reportRoute.length - 1].getGeometry().appendCoordinate(point); - } - this.getView().getMapView().fit(this.reportRoute[0].getGeometry(), this.getView().getMap().getSize()); + this.getView().getMapView().fit(this.reportRoute[0].getGeometry(), this.getView().getMap().getSize()); + } }, addReportMarkers: function (store, data) { diff --git a/web/app/view/ReportController.js b/web/app/view/ReportController.js index 50775ace..f8a01bc6 100644 --- a/web/app/view/ReportController.js +++ b/web/app/view/ReportController.js @@ -197,12 +197,10 @@ Ext.define('Traccar.view.ReportController', { loadEvents: function (store, data) { var i, eventObject, positionIds = []; Ext.getStore('ReportRoute').removeAll(); - if (data.length > 0) { - for (i = 0; i < data.length; i++) { - eventObject = data[i]; - if (eventObject.get('positionId')) { - positionIds.push(eventObject.get('positionId')); - } + for (i = 0; i < data.length; i++) { + eventObject = data[i]; + if (eventObject.get('positionId')) { + positionIds.push(eventObject.get('positionId')); } } if (positionIds.length > 0) { -- cgit v1.2.3