From 914abce63e9f85d13d0b6ee53ea55eb70643d71e Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 26 Jul 2016 13:03:48 +1200 Subject: Handle correctly empty report --- web/app/view/MapController.js | 50 ++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 24 deletions(-) (limited to 'web') diff --git a/web/app/view/MapController.js b/web/app/view/MapController.js index eee74099f..6ef9f91e6 100644 --- a/web/app/view/MapController.js +++ b/web/app/view/MapController.js @@ -147,37 +147,39 @@ Ext.define('Traccar.view.MapController', { this.clearReport(store); - this.reportRoute = new ol.Feature({ - geometry: new ol.geom.LineString([]) - }); - this.reportRoute.setStyle(this.getRouteStyle()); - this.getView().getRouteSource().addFeature(this.reportRoute); + if (data.length > 0) { + this.reportRoute = new ol.Feature({ + geometry: new ol.geom.LineString([]) + }); + this.reportRoute.setStyle(this.getRouteStyle()); + this.getView().getRouteSource().addFeature(this.reportRoute); - for (i = 0; i < data.length; i++) { - position = data[i]; + 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); - 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); - marker = new ol.Feature(geometry); - marker.set('record', position); - this.reportMarkers[position.get('id')] = marker; - this.getView().getReportSource().addFeature(marker); + style = this.getReportMarker(); + style.getImage().setRotation(position.get('course') * Math.PI / 180); + /*style.getText().setText( + Ext.Date.format(position.get('fixTime'), Traccar.Style.dateTimeFormat24));*/ - style = this.getReportMarker(); - style.getImage().setRotation(position.get('course') * Math.PI / 180); - /*style.getText().setText( - Ext.Date.format(position.get('fixTime'), Traccar.Style.dateTimeFormat24));*/ + marker.setStyle(style); - marker.setStyle(style); + this.reportRoute.getGeometry().appendCoordinate(point); + } - this.reportRoute.getGeometry().appendCoordinate(point); + this.getView().getMapView().fit(this.reportRoute.getGeometry(), this.getView().getMap().getSize()); } - - this.getView().getMapView().fit(this.reportRoute.getGeometry(), this.getView().getMap().getSize()); }, clearReport: function (store) { -- cgit v1.2.3