aboutsummaryrefslogtreecommitdiff
path: root/web/app
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-03-15 23:08:57 +1300
committerGitHub <noreply@github.com>2017-03-15 23:08:57 +1300
commitfd2207b15d98d8fdef306f3b94924a759c80a3d9 (patch)
treea50b36f4f3c5da83f8a13955331a4688c75e96b5 /web/app
parentd77cc1c9b2890224119d59b493597e47e3f1792f (diff)
parent7135682a0f262dc4b76f41bec2db4c022f88b17b (diff)
downloadtrackermap-web-fd2207b15d98d8fdef306f3b94924a759c80a3d9.tar.gz
trackermap-web-fd2207b15d98d8fdef306f3b94924a759c80a3d9.tar.bz2
trackermap-web-fd2207b15d98d8fdef306f3b94924a759c80a3d9.zip
Merge pull request #440 from Abyss777/zoom_to_all
Zoom to all devices on start
Diffstat (limited to 'web/app')
-rw-r--r--web/app/controller/Root.js18
-rw-r--r--web/app/view/MapController.js7
-rw-r--r--web/app/view/MapMarkerController.js48
3 files changed, 49 insertions, 24 deletions
diff --git a/web/app/controller/Root.js b/web/app/controller/Root.js
index 404fb7cc..b6e5f385 100644
--- a/web/app/controller/Root.js
+++ b/web/app/controller/Root.js
@@ -161,7 +161,8 @@ Ext.define('Traccar.controller.Root', {
self.updateDevices(data.devices);
}
if (data.positions) {
- self.updatePositions(data.positions);
+ self.updatePositions(data.positions, first);
+ first = false;
}
if (data.events) {
self.updateEvents(data.events);
@@ -185,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++) {
@@ -196,6 +197,9 @@ Ext.define('Traccar.controller.Root', {
store.add(Ext.create('Traccar.model.Position', array[i]));
}
}
+ if (first) {
+ this.zoomToAllDevices();
+ }
},
updateEvents: function (array) {
@@ -225,5 +229,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..57727f20 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,9 @@ Ext.define('Traccar.view.MapController', {
return true;
}, this);
}
+ },
+
+ zoomToAllDevices: function () {
+ this.zoomToAllPositions(Ext.getStore('LatestPositions').getData().items);
}
});
diff --git a/web/app/view/MapMarkerController.js b/web/app/view/MapMarkerController.js
index 27591c18..bb418704 100644
--- a/web/app/view/MapMarkerController.js
+++ b/web/app/view/MapMarkerController.js
@@ -311,32 +311,14 @@ Ext.define('Traccar.view.MapMarkerController', {
},
addReportMarkers: function (store, data) {
- var i, position, point, minx, miny, maxx, maxy;
+ var i;
this.clearReport();
for (i = 0; i < data.length; i++) {
- position = data[i];
- point = ol.proj.fromLonLat([
- position.get('longitude'),
- position.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 (store.showMarkers) {
- this.addReportMarker(position);
+ this.addReportMarker(data[i]);
}
}
- 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));
- }
+ this.zoomToAllPositions(data);
},
clearReport: function () {
@@ -482,5 +464,29 @@ Ext.define('Traccar.view.MapMarkerController', {
deselectFeature: function () {
this.selectMarker(null, false);
this.fireEvent('deselectfeature');
+ },
+
+ zoomToAllPositions: function (data) {
+ var i, point, minx, miny, maxx, maxy;
+ for (i = 0; i < data.length; i++) {
+ point = ol.proj.fromLonLat([
+ data[i].get('longitude'),
+ data[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));
+ }
}
});