diff options
author | Abyss777 <abyss@fox5.ru> | 2017-03-15 09:38:12 +0500 |
---|---|---|
committer | Abyss777 <abyss@fox5.ru> | 2017-03-15 09:38:12 +0500 |
commit | b93d36f154d6e5b16769ddec07bb8936512f8bb1 (patch) | |
tree | dc62fa48dd2e8df692aa56a6ee626693ef0ceee6 /web/app | |
parent | d77cc1c9b2890224119d59b493597e47e3f1792f (diff) | |
download | trackermap-web-b93d36f154d6e5b16769ddec07bb8936512f8bb1.tar.gz trackermap-web-b93d36f154d6e5b16769ddec07bb8936512f8bb1.tar.bz2 trackermap-web-b93d36f154d6e5b16769ddec07bb8936512f8bb1.zip |
Zoom to all devices on launch
Diffstat (limited to 'web/app')
-rw-r--r-- | web/app/controller/Root.js | 17 | ||||
-rw-r--r-- | web/app/view/MapController.js | 28 |
2 files changed, 44 insertions, 1 deletions
diff --git a/web/app/controller/Root.js b/web/app/controller/Root.js index 404fb7cc..94f0705f 100644 --- a/web/app/controller/Root.js +++ b/web/app/controller/Root.js @@ -167,6 +167,9 @@ Ext.define('Traccar.controller.Root', { self.updateEvents(data.events); } }; + if (first) { + this.first = true; + } }, updateDevices: function (array) { @@ -196,6 +199,10 @@ Ext.define('Traccar.controller.Root', { store.add(Ext.create('Traccar.model.Position', array[i])); } } + if (this.first) { + this.zoomToAllDevices(); + this.first = false; + } }, updateEvents: function (array) { @@ -225,5 +232,15 @@ Ext.define('Traccar.controller.Root', { Ext.toast(text, device.get('name'), 'br'); } } + }, + + zoomToAllDevices: function () { + var lat, lon, zoom; + lat = Traccar.app.getPreference('latitude', 0); + lon = Traccar.app.getPreference('longitude', 0); + zoom = Traccar.app.getPreference('zoom', 0); + if (lat === 0 && lon === 0 && zoom === 0) { + this.fireEvent('zoomtoalldevices'); + } } }); 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)); + } } }); |