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/app/view') 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