From 8523cf92c8ef566ec28b9a759c81f4a86957c11e Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Wed, 29 Mar 2017 11:46:40 +0500 Subject: Fit to edited geofence or main Map --- web/app/view/map/GeofenceMap.js | 8 +++----- web/app/view/map/GeofenceMapController.js | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) (limited to 'web/app') diff --git a/web/app/view/map/GeofenceMap.js b/web/app/view/map/GeofenceMap.js index 37d3be7..d16e6ca 100644 --- a/web/app/view/map/GeofenceMap.js +++ b/web/app/view/map/GeofenceMap.js @@ -68,11 +68,9 @@ Ext.define('Traccar.view.map.GeofenceMap', { if (this.area !== '') { geometry = Traccar.GeofenceConverter.wktToGeometry(this.mapView, this.area); this.features.push(new ol.Feature(geometry)); - if (geometry instanceof ol.geom.Circle) { - this.mapView.setCenter(geometry.getCenter()); - } else if (geometry instanceof ol.geom.Polygon) { - this.mapView.setCenter(geometry.getCoordinates()[0][0]); - } + this.mapView.fit(geometry); + } else { + this.controller.fireEvent('mapstaterequest'); } fillColor = ol.color.asArray(Traccar.Style.mapGeofenceColor); fillColor[3] = Traccar.Style.mapGeofenceOverlayOpacity; diff --git a/web/app/view/map/GeofenceMapController.js b/web/app/view/map/GeofenceMapController.js index ffafb7f..f075ac9 100644 --- a/web/app/view/map/GeofenceMapController.js +++ b/web/app/view/map/GeofenceMapController.js @@ -23,6 +23,16 @@ Ext.define('Traccar.view.map.GeofenceMapController', { 'Traccar.GeofenceConverter' ], + config: { + listen: { + controller: { + '*': { + mapstate: 'setMapState' + } + } + } + }, + onSaveClick: function (button) { var geometry, projection; if (this.getView().getFeatures().getLength() > 0) { @@ -40,5 +50,10 @@ Ext.define('Traccar.view.map.GeofenceMapController', { onTypeSelect: function (combo) { this.getView().removeInteraction(); this.getView().addInteraction(combo.getValue()); + }, + + setMapState: function (lat, lon, zoom) { + this.getView().getMapView().setCenter(ol.proj.fromLonLat([lon, lat])); + this.getView().getMapView().setZoom(zoom); } }); -- cgit v1.2.3