From b93d36f154d6e5b16769ddec07bb8936512f8bb1 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Wed, 15 Mar 2017 09:38:12 +0500 Subject: Zoom to all devices on launch --- web/app/view/MapController.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'web/app/view') diff --git a/web/app/view/MapController.js b/web/app/view/MapController.js index 95296f14..1a2a9c13 100644 --- a/web/app/view/MapController.js +++ b/web/app/view/MapController.js @@ -28,7 +28,8 @@ Ext.define('Traccar.view.MapController', { controller: { '*': { mapstaterequest: 'getMapState', - togglestaterequest: 'getToggleState' + togglestaterequest: 'getToggleState', + zoomtoalldevices: 'zoomToAllDevices' } }, store: { @@ -98,5 +99,30 @@ Ext.define('Traccar.view.MapController', { return true; }, this); } + }, + + zoomToAllDevices: function () { + var data, i, point, minx, miny, maxx, maxy; + data = Ext.getStore('LatestPositions').getData(); + for (i = 0; i < data.items.length; i++) { + point = ol.proj.fromLonLat([ + data.items[i].get('longitude'), + data.items[i].get('latitude') + ]); + if (i === 0) { + minx = maxx = point[0]; + miny = maxy = point[1]; + } else { + minx = Math.min(point[0], minx); + miny = Math.min(point[1], miny); + maxx = Math.max(point[0], maxx); + maxy = Math.max(point[1], maxy); + } + } + if (minx !== maxx || miny !== maxy) { + this.getView().getMapView().fit([minx, miny, maxx, maxy]); + } else if (point) { + this.getView().getMapView().fit(new ol.geom.Point(point)); + } } }); -- cgit v1.2.3