Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mouse position translation #3360

Merged
merged 3 commits into from
Jan 10, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
65 changes: 49 additions & 16 deletions contribs/gmf/src/directives/mouseposition.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,16 @@ gmf.module.component('gmfMouseposition', gmf.mousepositionComponent);

/**
* @param {!angular.JQLite} $element Element.
* @param {!angular.$filter} $filter Angular filter
* @param {!angular.$filter} $filter Angular filter.
* @param {!angular.Scope} $scope Angular scope.
* @param {!angularGettext.Catalog} gettextCatalog Gettext catalog.
* @constructor
* @private
* @ngInject
* @ngdoc controller
* @ngname gmfMousepositionController
*/
gmf.MousepositionController = function($element, $filter, gettextCatalog) {
gmf.MousepositionController = function($element, $filter, $scope, gettextCatalog) {
/**
* @type {!ol.Map}
* @export
Expand All @@ -64,32 +65,64 @@ gmf.MousepositionController = function($element, $filter, gettextCatalog) {
*/
this.projection;

/**
* @type {angular.Scope}
* @private
*/
this.$scope_ = $scope;

/**
* @type {angularGettext.Catalog}
* @private
*/
this.gettextCatalog_ = gettextCatalog;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, you can mark it protected and remove the trailing underscore. Then there is no need to alias it in the code below.


/**
* @type {angular.JQLite}
* @private
*/
this.$element_ = $element;

/**
* @type {angular.$filter}
* @private
*/
this.$filter_ = $filter;
};


/**
* Initialise the controller.
*/
gmf.MousepositionController.prototype.$onInit = function() {
// function that apply the filter.
const formatFn = function(coordinates) {
const filterAndArgs = this.projection.filter.split(':');
const filter = $filter(filterAndArgs.shift());
const filter = this.$filter_(filterAndArgs.shift());
goog.asserts.assertFunction(filter);
const args = filterAndArgs;
args.unshift(coordinates);
return filter.apply(this, args);
};

this.control = new ol.control.MousePosition({
className: 'gmf-mouseposition-control',
coordinateFormat: formatFn.bind(this),
target: angular.element('.gmf-mouseposition-control-target', $element)[0],
undefinedHTML: gettextCatalog.getString('Coordinates')
});
};
this.control = null;
this.$scope_.$on('gettextLanguageChanged', () => {
if (this.control !== null) {
this.map.removeControl(this.control);
}

const gettextCatalog = this.gettextCatalog_;
this.control = new ol.control.MousePosition({
className: 'gmf-mouseposition-control',
coordinateFormat: formatFn.bind(this),
target: angular.element('.gmf-mouseposition-control-target', this.$element_)[0],
undefinedHTML: gettextCatalog.getString('Coordinates')
});

/**
* Initialise the controller.
*/
gmf.MousepositionController.prototype.$onInit = function() {
this.setProjection(this.projections[0]);
this.setProjection(this.projections[0]);

this.map.addControl(this.control);
this.map.addControl(this.control);
});
};


Expand Down