Skip to content

Commit

Permalink
Enable turning on/off geolocation
Browse files Browse the repository at this point in the history
fixes #239
  • Loading branch information
raitisbe committed Jul 23, 2019
1 parent 28fb96b commit a005171
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 83 deletions.
6 changes: 5 additions & 1 deletion components/geolocation/geolocation.directive.js
Expand Up @@ -10,7 +10,7 @@ export default ['hs.map.service', 'hs.geolocation.service', 'Core', 'config', fu
} }
} }
}, },
controller: ['$scope', function ($scope) { controller: ['$scope', 'config', function ($scope, config) {
$scope.collapsed = true; $scope.collapsed = true;
$scope.blocateClick = function (e) { $scope.blocateClick = function (e) {
//Checking target is needed because follow button is inside locate button (container) //Checking target is needed because follow button is inside locate button (container)
Expand All @@ -24,6 +24,10 @@ export default ['hs.map.service', 'hs.geolocation.service', 'Core', 'config', fu
Geolocation.geolocation.setTracking(true); Geolocation.geolocation.setTracking(true);
} }
} }

$scope.geolocationVisible = function () {
return (angular.isUndefined(config.locationButtonVisible) || config.locationButtonVisible);
}
}], }],
replace: true replace: true
}; };
Expand Down
2 changes: 1 addition & 1 deletion components/geolocation/partials/geolocation.html
@@ -1,4 +1,4 @@
<div class="locate ol-unselectable ol-control locateToggler" ng-click="blocateClick($event)" ng-class="{'ol-collapsed': collapsed}" <div class="locate ol-unselectable ol-control locateToggler" ng-show="geolocationVisible()" ng-click="blocateClick($event)" ng-class="{'ol-collapsed': collapsed}"
ng-controller="hs.geolocation.controller"> ng-controller="hs.geolocation.controller">


<ul> <ul>
Expand Down
162 changes: 81 additions & 81 deletions components/map/map.controller.js
Expand Up @@ -2,100 +2,100 @@ import mapDirective from './map.directive';
import { transform } from 'ol/proj'; import { transform } from 'ol/proj';


export default ['$scope', 'hs.map.service', 'config', 'hs.permalink.urlService', 'Core', '$rootScope', export default ['$scope', 'hs.map.service', 'config', 'hs.permalink.urlService', 'Core', '$rootScope',
function ($scope, OlMap, config, permalink, Core, $rootScope) { function ($scope, OlMap, config, permalink, Core, $rootScope) {


var map = OlMap.map; var map = OlMap.map;


/** /**
* @ngdoc method * @ngdoc method
* @name hs.map.controller#setTargetDiv * @name hs.map.controller#setTargetDiv
* @public * @public
* @description Sets div element of the map * @description Sets div element of the map
* @param {string} div_id ID pf the container element * @param {string} div_id ID pf the container element
* @returns {ol.Map} * @returns {ol.Map}
*/ */
$scope.setTargetDiv = function (div_id) { $scope.setTargetDiv = function (div_id) {
OlMap.map.setTarget(div_id); OlMap.map.setTarget(div_id);
} }

/**
* @ngdoc method
* @name hs.map.controller#findLayerByTitle
* @public
* @param {string} title Title of the layer (from layer creation)
* @returns {Ol.layer} Ol.layer object
* @description Find layer object by title of layer
*/
$scope.findLayerByTitle = OlMap.findLayerByTitle;


$scope.hs_map = OlMap; /**
* @ngdoc method
* @name hs.map.controller#findLayerByTitle
* @public
* @param {string} title Title of the layer (from layer creation)
* @returns {Ol.layer} Ol.layer object
* @description Find layer object by title of layer
*/
$scope.findLayerByTitle = OlMap.findLayerByTitle;


// $scope.hs_map = OlMap;
$scope.showFeaturesWithAttrHideRest = function (source, attribute, value, attr_to_change, invisible_value, visible_value) {


} //
$scope.showFeaturesWithAttrHideRest = function (source, attribute, value, attr_to_change, invisible_value, visible_value) {


/**
* @ngdoc method
* @name hs.map.controller#init
* @public
* @description Initialization of map object, initialize map and map state from permalink.
*/
$scope.init = function () {
if (permalink.getParamValue('visible_layers')) {
OlMap.visible_layers = permalink.getParamValue('visible_layers').split(';');
}
OlMap.init();
let hs_x = permalink.getParamValue('hs_x');
let hs_y = permalink.getParamValue('hs_y');
let hs_z = permalink.getParamValue('hs_z');
if (hs_x && hs_x != 'NaN' && hs_y && hs_y != 'NaN' && hs_z && hs_z != 'NaN') {
OlMap.moveToAndZoom(parseFloat(hs_x), parseFloat(hs_y), parseInt(hs_z));
} }


if (permalink.getParamValue("puremap")) { /**
Core.puremapApp = true; * @ngdoc method
OlMap.puremap(); * @name hs.map.controller#init
* @public
* @description Initialization of map object, initialize map and map state from permalink.
*/
$scope.init = function () {
if (permalink.getParamValue('visible_layers')) {
OlMap.visible_layers = permalink.getParamValue('visible_layers').split(';');
}
OlMap.init();
let hs_x = permalink.getParamValue('hs_x');
let hs_y = permalink.getParamValue('hs_y');
let hs_z = permalink.getParamValue('hs_z');
if (hs_x && hs_x != 'NaN' && hs_y && hs_y != 'NaN' && hs_z && hs_z != 'NaN') {
OlMap.moveToAndZoom(parseFloat(hs_x), parseFloat(hs_y), parseInt(hs_z));
}

if (permalink.getParamValue("puremap")) {
Core.puremapApp = true;
OlMap.puremap();
}
} }
}


/** /**
* @ngdoc method * @ngdoc method
* @name hs.map.controller#onCenterSync * @name hs.map.controller#onCenterSync
* @private * @private
* @param {array} data Coordinates in lon/lat and resolution * @param {array} data Coordinates in lon/lat and resolution
* @description This gets called from Cesium map, to synchronize center and resolution between Ol and Cesium maps * @description This gets called from Cesium map, to synchronize center and resolution between Ol and Cesium maps
*/ */
function onCenterSync(event, data) { function onCenterSync(event, data) {
if (angular.isUndefined(data) || data == null) return; if (angular.isUndefined(data) || data == null) return;
var transformed_cords = transform([data[0], data[1]], 'EPSG:4326', OlMap.map.getView().getProjection()); var transformed_cords = transform([data[0], data[1]], 'EPSG:4326', OlMap.map.getView().getProjection());
OlMap.moveToAndZoom(transformed_cords[0], transformed_cords[1], zoomForResolution(data[2])); OlMap.moveToAndZoom(transformed_cords[0], transformed_cords[1], zoomForResolution(data[2]));
} }


$rootScope.$on('map.sync_center', onCenterSync); $rootScope.$on('map.sync_center', onCenterSync);


/** /**
* @ngdoc method * @ngdoc method
* @name hs.map.controller#zoomForResolution * @name hs.map.controller#zoomForResolution
* @private * @private
* @param {number} resolution Resolution * @param {number} resolution Resolution
* @description Calculates zoom level for a given resolution * @description Calculates zoom level for a given resolution
*/ */
function zoomForResolution(resolution) { function zoomForResolution(resolution) {
var zoom = 0; var zoom = 0;
resolution = Math.abs(resolution); //Sometimes resolution is under 0. Ratis resolution = Math.abs(resolution); //Sometimes resolution is under 0. Ratis
var r = 156543.03390625; // resolution for zoom 0 var r = 156543.03390625; // resolution for zoom 0
while (resolution < r) { while (resolution < r) {
r /= 2.0; r /= 2.0;
zoom++; zoom++;
if (resolution > r) { if (resolution > r) {
return zoom; return zoom;
}
} }
return zoom; // resolution was greater than 156543.03390625 so return 0
} }
return zoom; // resolution was greater than 156543.03390625 so return 0
}


$scope.init(); $scope.init();
$scope.$emit('scope_loaded', "Map"); $scope.$emit('scope_loaded', "Map");
} }
] ]
4 changes: 4 additions & 0 deletions wiki/config.txt
Expand Up @@ -315,6 +315,10 @@ DEPRECATED. Array of layers to be crossfilterable. Each element is an object whi
}] }]
``` ```


**locationButtonVisible**

Show or hide geolocation button on map. Possible values: true/false

**queryPoint** **queryPoint**


How to display point clicked on the map. Possible values are: hidden, notWithin How to display point clicked on the map. Possible values are: hidden, notWithin
Expand Down

0 comments on commit a005171

Please sign in to comment.