Skip to content

Commit

Permalink
Refactor geolocation module
Browse files Browse the repository at this point in the history
fixes #233
refs #217
  • Loading branch information
raitisbe committed Jul 23, 2019
1 parent 17312e4 commit 28fb96b
Show file tree
Hide file tree
Showing 4 changed files with 375 additions and 368 deletions.
91 changes: 91 additions & 0 deletions components/geolocation/geolocation.controller.js
@@ -0,0 +1,91 @@
export default ['$scope', 'hs.geolocation.service', 'hs.map.service', 'Core', function ($scope, service, OlMap, Core) {
$scope.speed = null;
$scope.alt = null;
$scope.altitudeAccuracy = null;
$scope.accuracy = null;
$scope.Geolocation = service;

if (Core.isMobile()) {
$scope.switchGps = service.toggleGps;

/**
* Tracking info/starter, without argument return tracking status. With argument start tracking for mobile, with argument "True" start tracking for desktop
* @memberof hs.geolocation.controller
* @function gpsActive
* @param {Boolean} set_to Optional argument
*/
$scope.gpsActive = function (set_to) {
if (arguments.length === 0) {
return service.gpsStatus;
console.log('arguments = 0');
} else {
service.startGpsWatch();
console.log('Starting GPS.');
}
};
} else {
//Same as above, but for desktop version
$scope.gpsActive = function (set_to) {
if (arguments.length == 0)
return service.geolocation.getTracking();
else {
service.geolocation.setTracking(set_to);
}
};
}

/**
* Return which geolocation provider is currently used (Geolocation API / ol.Geolocation)
* @memberof hs.geolocation.controller
* @function getGeolocationProvider
*/
$scope.getGeolocationProvider = function () {
return service.geolocation;
};

/**
* State manager of following function. Without arguments returns following state in Boolean. With argument change following state.
* @memberof hs.geolocation.controller
* @function following
* @param {Boolean} set_to Optional - Desired following state
*/
$scope.following = function (set_to) {
if (arguments.length == 0)
return service.following;
else {
service.following = set_to;
if (console) console.log(service.last_location);
if (angular.isDefined(service.last_location)) {
if (set_to) OlMap.map.getView().setCenter(service.last_location.latlng);
if (Core.isMobile()) service.changed_handler();
} else {
if (console) console.log('last location not defined');
}
}
};

/**
* Change style of location layer
* @memberof hs.geolocation.controller
* @function setFeatureStyle
* @param {ol.style.Style} style New style of location layer
*/
$scope.setFeatureStyle = function (style) {
return service.style = style;
}

$scope.$on('geolocation.updated', function (event) {
$scope.speed = service.speed;
$scope.alt = service.altitude;
$scope.accuracy = service.accuracy;
$scope.altitudeAccuracy = service.altitudeAccuracy;
if (!$scope.$$phase) $scope.$digest();
});

$scope.$on('geolocation.switched', function (event) {
service.gpsSwitch = service.gpsStatus ? 'Stop GPS' : 'Start GPS';
if (!$scope.$$phase) $scope.$digest();
});

$scope.$emit('scope_loaded', "Geolocation");
}]
30 changes: 30 additions & 0 deletions components/geolocation/geolocation.directive.js
@@ -0,0 +1,30 @@
export default ['hs.map.service', 'hs.geolocation.service', 'Core', 'config', function (OlMap, Geolocation, Core, config) {
return {
template: Core.isMobile() ? require('components/geolocation/partials/geolocation_cordova.html') : require('components/geolocation/partials/geolocation.html'),
link: function link(scope, element, attrs) {
if (!Core.puremapApp) {
if (Core.isMobile()) {
document.querySelector("#menu").appendChild(element[0]);
} else {
document.querySelector(".ol-overlaycontainer-stopevent").appendChild(element[0]);
}
}
},
controller: ['$scope', function ($scope) {
$scope.collapsed = true;
$scope.blocateClick = function (e) {
//Checking target is needed because follow button is inside locate button (container)
//and because of that follow button triggers click on parent element
if (!e.target.classList.contains('locateToggler')) return;
$scope.collapsed = !$scope.collapsed;
Geolocation.toggleFeatures(!$scope.collapsed);
if (Core.isMobile()) {
Geolocation.toggleGps();
} else {
Geolocation.geolocation.setTracking(true);
}
}
}],
replace: true
};
}]

0 comments on commit 28fb96b

Please sign in to comment.