Skip to content

Commit

Permalink
Move utility methods to check treeCtrl customization from NGEO to GMF
Browse files Browse the repository at this point in the history
  • Loading branch information
adube committed Sep 25, 2017
1 parent 5499cd9 commit b46f408
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 58 deletions.
62 changes: 62 additions & 0 deletions contribs/gmf/src/directives/layertree.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,68 @@ gmf.LayertreeController.prototype.isNodeLegendVisible = function(legendNodeId) {
};


/**
* Determines whether the layer tree controller supports being customized.
* For example, having its layer opacity changed, displaying its legend, etc.
*
* If any requirement is met, then the treeCtrl is considered supporting
* "customization", regardless of what it actually is.
*
* The requirements are:
*
* - must not be the root controller, any of the following:
* - it supports legend
* - it supports having the layer opacity being changed
*
* @param {!ngeo.LayertreeController} treeCtrl Ngeo tree controller.
* @return {boolean} Whether the layer tree controller supports being
* "customized" or not.
* @export
*/
gmf.LayertreeController.prototype.supportsCustomization = function(treeCtrl) {
return !treeCtrl.isRoot &&
(
this.supportsLegend(treeCtrl) ||
this.supportsOpacityChange(treeCtrl)
);
};


/**
* @param {!ngeo.LayertreeController} treeCtrl Ngeo tree controller.
* @return {boolean} Whether the layer tree controller supports having a
* legend being shown.
* @export
*/
gmf.LayertreeController.prototype.supportsLegend = function(treeCtrl) {
const node = /** @type {!gmfThemes.GmfGroup} */ (treeCtrl.node);
return node.metadata &&
node.metadata.legend &&
this.getLegendURL(treeCtrl);
};


/**
* @param {!ngeo.LayertreeController} treeCtrl Ngeo tree controller.
* @return {boolean} Whether the layer tree controller supports having its
* layer opacity being changed or not.
* @export
*/
gmf.LayertreeController.prototype.supportsOpacityChange = function(treeCtrl) {
const node = /** @type {!gmfThemes.GmfGroup} */ (treeCtrl.node);
const parentNode = /** @type {!gmfThemes.GmfGroup} */ (treeCtrl.parent.node);
return treeCtrl.layer &&
(
(
treeCtrl.depth === 1 && !node.mixed
) ||
(
treeCtrl.depth > 1 && parentNode.mixed
)
);
};


/**
* Get the snapping configuration object from a Layertree controller
*
Expand Down
8 changes: 4 additions & 4 deletions contribs/gmf/src/directives/partials/layertree.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<a
class="gmf-layertree-node-menu-btn"
href=""
ng-if="::layertreeCtrl.supportsCustomization()"
ng-if="::gmfLayertreeCtrl.supportsCustomization(layertreeCtrl)"
ng-click="::gmfLayertreeCtrl.toggleNodeLegend('#gmf-layertree-node-menu-' + layertreeCtrl.uid)">
<span class="fa fa-cog"></span>
</a>
Expand Down Expand Up @@ -192,9 +192,9 @@
class="gmf-layertree-node-menu"
id="gmf-layertree-node-menu-{{::layertreeCtrl.uid}}"
style="display:none;"
ng-if="::layertreeCtrl.supportsCustomization()">
ng-if="::gmfLayertreeCtrl.supportsCustomization(layertreeCtrl)">

<div ng-if="::layertreeCtrl.supportsOpacityChange()">
<div ng-if="::gmfLayertreeCtrl.supportsOpacityChange(layertreeCtrl)">
<i class="fa fa-tint fa-fw"></i>
<span for="layer-opactity">{{'Opacity'|translate}}</span>
<input
Expand All @@ -209,7 +209,7 @@

<a
class="gmf-layertree-node-menu-togglelegend"
ng-if="::gmfLayertreeCtrl.getLegendURL(layertreeCtrl) && layertreeCtrl.supportsLegend()"
ng-if="::gmfLayertreeCtrl.supportsLegend(layertreeCtrl)"
title="{{'Hide legend'|translate}}"
data-toggle="collapse"
ng-click="::gmfLayertreeCtrl.toggleNodeLegend('#gmf-layertree-node-' + layertreeCtrl.uid + '-legend')"
Expand Down
54 changes: 0 additions & 54 deletions src/directives/layertree.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,60 +438,6 @@ ngeo.LayertreeController.prototype.setDataSource = function(dataSource) {
};


/**
* Determines whether the layer tree controller supports being customized.
* For example, having its layer opacity changed, displaying its legend, etc.
*
* If any requirement is met, then the treeCtrl is considered supporting
* "customization", regardless of what it actually is.
*
* The requirements are:
*
* - must not be the root controller, any of the following:
* - it supports legend
* - it supports having the layer opacity being changed
*
* @return {boolean} Whether the layer tree controller supports being
* "customized" or not.
* @export
*/
ngeo.LayertreeController.prototype.supportsCustomization = function() {
return !this.isRoot &&
(
this.supportsLegend() ||
this.supportsOpacityChange()
);
};


/**
* @return {boolean} Whether the layer tree controller supports having a
* legend being shown.
* @export
*/
ngeo.LayertreeController.prototype.supportsLegend = function() {
return this.node.metadata && this.node.metadata.legend;
};


/**
* @return {boolean} Whether the layer tree controller supports having its
* layer opacity being changed or not.
* @export
*/
ngeo.LayertreeController.prototype.supportsOpacityChange = function() {
return this.layer &&
(
(
this.depth === 1 && !this.node['mixed']
) ||
(
this.depth > 1 && this.parent.node['mixed']
)
);
};


/**
* Get the "top level" layertree (one of the first level child under the root
* layertree). Can return itself.
Expand Down

0 comments on commit b46f408

Please sign in to comment.