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/controller/Root.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'web/app/controller') diff --git a/web/app/controller/Root.js b/web/app/controller/Root.js index 404fb7c..94f0705 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'); + } } }); -- cgit v1.2.3 From ccc2f0bd4387d7117a1c9b629be2d22edccb18d9 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Wed, 15 Mar 2017 14:06:51 +0500 Subject: Use local variable --- web/app/controller/Root.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'web/app/controller') diff --git a/web/app/controller/Root.js b/web/app/controller/Root.js index 94f0705..8a9b0d9 100644 --- a/web/app/controller/Root.js +++ b/web/app/controller/Root.js @@ -124,7 +124,7 @@ Ext.define('Traccar.controller.Root', { }, asyncUpdate: function (first) { - var self = this, protocol, pathname, socket; + var self = this, protocol, pathname, socket, firstPositions = first; protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; pathname = window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/') + 1); socket = new WebSocket(protocol + '//' + window.location.host + pathname + 'api/socket'); @@ -161,15 +161,13 @@ Ext.define('Traccar.controller.Root', { self.updateDevices(data.devices); } if (data.positions) { - self.updatePositions(data.positions); + self.updatePositions(data.positions, firstPositions); + firstPositions = false; } if (data.events) { self.updateEvents(data.events); } }; - if (first) { - this.first = true; - } }, updateDevices: function (array) { @@ -188,7 +186,7 @@ Ext.define('Traccar.controller.Root', { } }, - updatePositions: function (array) { + updatePositions: function (array, first) { var i, store, entity; store = Ext.getStore('LatestPositions'); for (i = 0; i < array.length; i++) { @@ -199,9 +197,8 @@ Ext.define('Traccar.controller.Root', { store.add(Ext.create('Traccar.model.Position', array[i])); } } - if (this.first) { + if (first) { this.zoomToAllDevices(); - this.first = false; } }, -- cgit v1.2.3 From 7135682a0f262dc4b76f41bec2db4c022f88b17b Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Wed, 15 Mar 2017 14:38:04 +0500 Subject: Remove intermediate variable --- web/app/controller/Root.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'web/app/controller') diff --git a/web/app/controller/Root.js b/web/app/controller/Root.js index 8a9b0d9..b6e5f38 100644 --- a/web/app/controller/Root.js +++ b/web/app/controller/Root.js @@ -124,7 +124,7 @@ Ext.define('Traccar.controller.Root', { }, asyncUpdate: function (first) { - var self = this, protocol, pathname, socket, firstPositions = first; + var self = this, protocol, pathname, socket; protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; pathname = window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/') + 1); socket = new WebSocket(protocol + '//' + window.location.host + pathname + 'api/socket'); @@ -161,8 +161,8 @@ Ext.define('Traccar.controller.Root', { self.updateDevices(data.devices); } if (data.positions) { - self.updatePositions(data.positions, firstPositions); - firstPositions = false; + self.updatePositions(data.positions, first); + first = false; } if (data.events) { self.updateEvents(data.events); -- cgit v1.2.3