Skip to content

Commit

Permalink
Create gmf profile module
Browse files Browse the repository at this point in the history
  • Loading branch information
ger-benjamin committed Jan 9, 2018
1 parent 235b97c commit 49f621a
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 51 deletions.
7 changes: 3 additions & 4 deletions contribs/gmf/examples/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ goog.require('gmf.Snapping');
/** @suppress {extraRequire} */
goog.require('gmf.mapDirective');
/** @suppress {extraRequire} */
goog.require('gmf.profileComponent');
goog.require('gmf.profile.module');
goog.require('ngeo.map.module');
/** @suppress {extraRequire} */
goog.require('ngeo.proj.EPSG21781');
goog.require('ol.Collection');
Expand All @@ -19,12 +20,10 @@ goog.require('ol.source.OSM');
goog.require('ol.style.Stroke');
goog.require('ol.style.Style');

goog.require('ngeo.map.module');


/** @type {!angular.Module} **/
gmfapp.module = angular.module('gmfapp', [
gmf.module.name, // Change me when gmf.Theme and other dependencies are in a module
gmf.profile.module.name,
ngeo.map.module.name // for ngeo.map.FeatureOverlay, perhaps remove me
]);

Expand Down
6 changes: 3 additions & 3 deletions contribs/gmf/src/controllers/AbstractDesktopController.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ goog.require('gmf.mousepositionComponent');
/** @suppress {extraRequire} */
goog.require('gmf.print.component');
/** @suppress {extraRequire} */
goog.require('gmf.profileComponent');
goog.require('gmf.profile.component');
/** @suppress {extraRequire} */
goog.require('gmf.raster.component');
goog.require('gmf.profile.drawLineComponent');
/** @suppress {extraRequire} */
goog.require('gmf.drawprofilelineDirective');
goog.require('gmf.raster.component');
/** @suppress {extraRequire} */
goog.require('gmf.TimeSliderDirective');
/** @suppress {extraRequire} */
Expand Down
2 changes: 2 additions & 0 deletions contribs/gmf/src/profile/.eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
extends:
- ../.eslintrc-googshift.yaml
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
goog.provide('gmf.profileComponent');
goog.provide('gmf.profile.component');

goog.require('gmf');
goog.require('ol.events');
goog.require('ol.Feature');
goog.require('ol.Observable');
goog.require('ol.Overlay');
goog.require('ol.geom.LineString');
goog.require('ol.geom.Point');
goog.require('ol.obj');
goog.require('ol.style.Circle');
goog.require('ol.style.Fill');
goog.require('ol.style.Style');

/** @suppress {extraRequire} */
goog.require('ngeo.download.Csv');
goog.require('ngeo.map.FeatureOverlayMgr');
/** @suppress {extraRequire} */
goog.require('ngeo.profile.elevationComponent');


// In the future module declaration, don't forget to require:
// - ngeo.map.FeatureOverlayMgr.module.name
// - ngeo.download.Csv.module.name
// - ngeo.profile.elevationComponent.name
/**
* @type {!angular.Module}
*/
gmf.profile.component = angular.module('gmfProfile', [
ngeo.download.Csv.module.name,
ngeo.map.FeatureOverlayMgr.module.name,
ngeo.profile.elevationComponent.name,
]);

gmf.module.requires.push(gmf.profile.component.name);

ngeo.module.value('gmfProfileTemplateUrl',

gmf.profile.component.value('gmfProfileTemplateUrl',
/**
* @param {!angular.JQLite} $element Element.
* @param {!angular.Attributes} $attrs Attributes.
Expand All @@ -33,7 +39,7 @@ ngeo.module.value('gmfProfileTemplateUrl',
($element, $attrs) => {
const templateUrl = $attrs['gmfProfileTemplateurl'];
return templateUrl !== undefined ? templateUrl :
`${gmf.baseTemplateUrl}/profile.html`;
`${gmf.baseModuleTemplateUrl}/profile/component.html`;
});


Expand Down Expand Up @@ -88,7 +94,7 @@ function gmfProfileTemplateUrl($element, $attrs, gmfProfileTemplateUrl) {
* @ngdoc component
* @ngname gmfProfile
*/
gmf.profileComponent = {
gmf.profile.component.component_ = {
controller: 'GmfProfileController as ctrl',
bindings: {
'active': '=gmfProfileActive',
Expand All @@ -102,8 +108,7 @@ gmf.profileComponent = {
templateUrl: gmfProfileTemplateUrl
};


gmf.module.component('gmfProfile', gmf.profileComponent);
gmf.profile.component.component('gmfProfile', gmf.profile.component.component_);


/**
Expand All @@ -122,7 +127,7 @@ gmf.module.component('gmfProfile', gmf.profileComponent);
* @ngdoc controller
* @ngname GmfProfileController
*/
gmf.ProfileController = function($scope, $http, $element, $filter,
gmf.profile.component.Controller_ = function($scope, $http, $element, $filter,
gettextCatalog, ngeoFeatureOverlayMgr, gmfProfileJsonUrl,
ngeoCsvDownload) {

Expand Down Expand Up @@ -310,7 +315,7 @@ gmf.ProfileController = function($scope, $http, $element, $filter,
/**
* Init the controller
*/
gmf.ProfileController.prototype.$onInit = function() {
gmf.profile.component.Controller_.prototype.$onInit = function() {
this.map_ = this['getMapFn'] ? this['getMapFn']() : null;
this.nbPoints_ = this['getNbPointsFn'] ? this['getNbPointsFn']() : 100;

Expand Down Expand Up @@ -364,7 +369,7 @@ gmf.ProfileController.prototype.$onInit = function() {
/**
* @private
*/
gmf.ProfileController.prototype.update_ = function() {
gmf.profile.component.Controller_.prototype.update_ = function() {
this.isErrored = false;
if (this.line) {
this.getJsonProfile_();
Expand All @@ -378,7 +383,7 @@ gmf.ProfileController.prototype.update_ = function() {
/**
* @private
*/
gmf.ProfileController.prototype.updateEventsListening_ = function() {
gmf.profile.component.Controller_.prototype.updateEventsListening_ = function() {
if (this.active && this.map_ !== null) {
this.pointerMoveKey_ = ol.events.listen(this.map_, 'pointermove',
this.onPointerMove_.bind(this));
Expand All @@ -392,7 +397,7 @@ gmf.ProfileController.prototype.updateEventsListening_ = function() {
* @param {ol.MapBrowserPointerEvent} e An ol map browser pointer event.
* @private
*/
gmf.ProfileController.prototype.onPointerMove_ = function(e) {
gmf.profile.component.Controller_.prototype.onPointerMove_ = function(e) {
if (e.dragging || !this.line) {
return;
}
Expand Down Expand Up @@ -420,7 +425,7 @@ gmf.ProfileController.prototype.onPointerMove_ = function(e) {
* @return {number} A distance.
* @private
*/
gmf.ProfileController.prototype.getDistanceOnALine_ = function(pointOnLine,
gmf.profile.component.Controller_.prototype.getDistanceOnALine_ = function(pointOnLine,
line) {
let segment;
let distOnLine = 0;
Expand Down Expand Up @@ -455,7 +460,7 @@ gmf.ProfileController.prototype.getDistanceOnALine_ = function(pointOnLine,
* @param {string} yUnits Y units label.
* @private
*/
gmf.ProfileController.prototype.hoverCallback_ = function(point, dist, xUnits,
gmf.profile.component.Controller_.prototype.hoverCallback_ = function(point, dist, xUnits,
elevationsRef, yUnits) {
// Update information point.
let ref;
Expand All @@ -480,7 +485,7 @@ gmf.ProfileController.prototype.hoverCallback_ = function(point, dist, xUnits,
/**
* @private
*/
gmf.ProfileController.prototype.outCallback_ = function() {
gmf.profile.component.Controller_.prototype.outCallback_ = function() {
// Reset information point.
this.currentPoint.coordinate = undefined;
this.currentPoint.distance = undefined;
Expand All @@ -498,7 +503,7 @@ gmf.ProfileController.prototype.outCallback_ = function() {
* @return {string} A texte formatted to a tooltip.
* @private
*/
gmf.ProfileController.prototype.getTooltipHTML_ = function() {
gmf.profile.component.Controller_.prototype.getTooltipHTML_ = function() {
const separator = ' : ';
let elevationName, translatedElevationName;
const innerHTML = [];
Expand Down Expand Up @@ -528,7 +533,7 @@ gmf.ProfileController.prototype.getTooltipHTML_ = function() {
* Creates a new 'hover' tooltip
* @private
*/
gmf.ProfileController.prototype.createMeasureTooltip_ = function() {
gmf.profile.component.Controller_.prototype.createMeasureTooltip_ = function() {
this.removeMeasureTooltip_();
this.measureTooltipElement_ = document.createElement('div');
this.measureTooltipElement_.className += 'tooltip ngeo-tooltip-measure';
Expand All @@ -545,7 +550,7 @@ gmf.ProfileController.prototype.createMeasureTooltip_ = function() {
* Destroy the 'hover' tooltip
* @private
*/
gmf.ProfileController.prototype.removeMeasureTooltip_ = function() {
gmf.profile.component.Controller_.prototype.removeMeasureTooltip_ = function() {
if (this.measureTooltipElement_ !== null) {
this.measureTooltipElement_.parentNode.removeChild(
this.measureTooltipElement_);
Expand All @@ -561,7 +566,7 @@ gmf.ProfileController.prototype.removeMeasureTooltip_ = function() {
* @return {string|undefined} A HEX color or undefined is nothing is found.
* @export
*/
gmf.ProfileController.prototype.getColor = function(layerName) {
gmf.profile.component.Controller_.prototype.getColor = function(layerName) {
const lineConfiguration = this.linesConfiguration_[layerName];
if (!lineConfiguration) {
return undefined;
Expand All @@ -575,7 +580,7 @@ gmf.ProfileController.prototype.getColor = function(layerName) {
* @return {Array.<string>} The names of layers.
* @export
*/
gmf.ProfileController.prototype.getLayersNames = function() {
gmf.profile.component.Controller_.prototype.getLayersNames = function() {
return this.layersNames_.slice(0);
};

Expand All @@ -585,7 +590,7 @@ gmf.ProfileController.prototype.getLayersNames = function() {
* @return {function(Object):number} Z extractor function.
* @private
*/
gmf.ProfileController.prototype.getZFactory_ = function(layerName) {
gmf.profile.component.Controller_.prototype.getZFactory_ = function(layerName) {
/**
* Generic GMF extractor for the 'given' value in 'values' in profileData.
* @param {Object} item The item.
Expand All @@ -608,7 +613,7 @@ gmf.ProfileController.prototype.getZFactory_ = function(layerName) {
* @return {number} The distance.
* @private
*/
gmf.ProfileController.prototype.getDist_ = function(item) {
gmf.profile.component.Controller_.prototype.getDist_ = function(item) {
if ('dist' in item) {
return item['dist'];
}
Expand All @@ -620,7 +625,7 @@ gmf.ProfileController.prototype.getDist_ = function(item) {
* Request the profile.
* @private
*/
gmf.ProfileController.prototype.getJsonProfile_ = function() {
gmf.profile.component.Controller_.prototype.getJsonProfile_ = function() {
const geom = {
'type': 'LineString',
'coordinates': this.line.getCoordinates()
Expand Down Expand Up @@ -651,7 +656,7 @@ gmf.ProfileController.prototype.getJsonProfile_ = function() {
* @param {!angular.$http.Response} resp Response.
* @private
*/
gmf.ProfileController.prototype.getProfileDataSuccess_ = function(resp) {
gmf.profile.component.Controller_.prototype.getProfileDataSuccess_ = function(resp) {
const profileData = resp.data['profile'];
if (profileData instanceof Array) {
this.profileData = profileData;
Expand All @@ -663,7 +668,7 @@ gmf.ProfileController.prototype.getProfileDataSuccess_ = function(resp) {
* @param {!angular.$http.Response} resp Response.
* @private
*/
gmf.ProfileController.prototype.getProfileDataError_ = function(resp) {
gmf.profile.component.Controller_.prototype.getProfileDataError_ = function(resp) {
this.isErrored = true;
console.error('Can not get JSON profile.');
};
Expand All @@ -673,7 +678,7 @@ gmf.ProfileController.prototype.getProfileDataError_ = function(resp) {
* Request the csv profile with the current profile data.
* @export
*/
gmf.ProfileController.prototype.downloadCsv = function() {
gmf.profile.component.Controller_.prototype.downloadCsv = function() {
if (this.profileData.length === 0) {
return;
}
Expand Down Expand Up @@ -714,4 +719,4 @@ gmf.ProfileController.prototype.downloadCsv = function() {
};


gmf.module.controller('GmfProfileController', gmf.ProfileController);
gmf.profile.component.controller('GmfProfileController', gmf.profile.component.Controller_);
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
goog.provide('gmf.drawprofilelineDirective');
goog.provide('gmf.profile.drawLineComponent');

goog.require('gmf');
goog.require('ol.Collection');
goog.require('ol.geom.LineString');
goog.require('ol.interaction.Draw');
goog.require('ol.Map');
goog.require('ol.style.Style');
goog.require('ol.style.Stroke');
goog.require('ngeo.map.FeatureOverlayMgr');
goog.require('ngeo.misc.decorate');

goog.require('ngeo.map.FeatureOverlayMgr');

/**
* @type {!angular.Module}
*/
gmf.profile.drawLineComponent = angular.module('gmfDrawProfileLine', [
ngeo.map.FeatureOverlayMgr.module.name,
]);

// In the future module declaration, don't forget to require:
// - ngeo.map.FeatureOverlayMgr.module.name
gmf.module.requires.push(gmf.profile.drawLineComponent.name);


/**
Expand All @@ -39,7 +44,7 @@ goog.require('ngeo.map.FeatureOverlayMgr');
* @ngdoc directive
* @ngname gmfDrawprofileline
*/
gmf.drawprofilelineDirective = function() {
gmf.profile.drawLineComponent.directive_ = function() {
return {
scope: true,
controller: 'GmfDrawprofilelineController as ctrl',
Expand All @@ -63,7 +68,8 @@ gmf.drawprofilelineDirective = function() {
};


gmf.module.directive('gmfDrawprofileline', gmf.drawprofilelineDirective);
gmf.profile.drawLineComponent.directive('gmfDrawprofileline',
gmf.profile.drawLineComponent.directive_);

/**
* @param {!angular.Scope} $scope Scope.
Expand All @@ -77,7 +83,7 @@ gmf.module.directive('gmfDrawprofileline', gmf.drawprofilelineDirective);
* @ngdoc controller
* @ngname gmfDrawprofilelineController
*/
gmf.DrawprofilelineController = function($scope, $element, $timeout,
gmf.profile.drawLineComponent.Controller_ = function($scope, $element, $timeout,
ngeoFeatureOverlayMgr) {

/**
Expand Down Expand Up @@ -172,10 +178,11 @@ gmf.DrawprofilelineController = function($scope, $element, $timeout,
);
};


/**
* Initialise the controller.
*/
gmf.DrawprofilelineController.prototype.init = function() {
gmf.profile.drawLineComponent.Controller_.prototype.init = function() {
const map = this['getMapFn']();
goog.asserts.assertInstanceof(map, ol.Map);
this.map_ = map;
Expand All @@ -187,11 +194,11 @@ gmf.DrawprofilelineController.prototype.init = function() {
* Clear the overlay and profile line.
* @private
*/
gmf.DrawprofilelineController.prototype.clear_ = function() {
gmf.profile.drawLineComponent.Controller_.prototype.clear_ = function() {
this.features_.clear();
this.line = null;
};


gmf.module.controller('GmfDrawprofilelineController',
gmf.DrawprofilelineController);
gmf.profile.drawLineComponent.controller('GmfDrawprofilelineController',
gmf.profile.drawLineComponent.Controller_);
13 changes: 13 additions & 0 deletions contribs/gmf/src/profile/module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
goog.provide('gmf.profile.module');

goog.require('gmf.profile.component');
goog.require('gmf.profile.drawLineComponent');


/**
* @type {!angular.Module}
*/
gmf.profile.module = angular.module('gmfProifleModule', [
gmf.profile.component.name,
gmf.profile.drawLineComponent.name,
]);
2 changes: 1 addition & 1 deletion contribs/gmf/test/spec/directives/profile.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
goog.require('gmf.profileComponent');
goog.require('gmf.profile.component');


describe('gmf.GmfProfileController', () => {
Expand Down

0 comments on commit 49f621a

Please sign in to comment.