aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--web/app/view/MapController.js23
-rw-r--r--web/app/view/MapMarkerController.js48
2 files changed, 28 insertions, 43 deletions
diff --git a/web/app/view/MapController.js b/web/app/view/MapController.js
index 1a2a9c13..57727f20 100644
--- a/web/app/view/MapController.js
+++ b/web/app/view/MapController.js
@@ -102,27 +102,6 @@ Ext.define('Traccar.view.MapController', {
},
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));
- }
+ 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));
+ }
}
});