Skip to content

Commit

Permalink
Even more typecheck fixes for gmf
Browse files Browse the repository at this point in the history
  • Loading branch information
adube committed Feb 5, 2019
1 parent 8d3d66c commit 8a4d6fc
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 34 deletions.
4 changes: 3 additions & 1 deletion contribs/gmf/src/datasource/OGC.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ngeoDatasourceOGC from 'ngeo/datasource/OGC.js';
*/


export default class extends ngeoDatasourceOGC {
class gmfDatasourceOGC extends ngeoDatasourceOGC {

/**
* A `gmf.datasource.OGC` extends a `ngeo.datasource.OGC` and
Expand Down Expand Up @@ -42,3 +42,5 @@ export default class extends ngeoDatasourceOGC {
}

}

export default gmfDatasourceOGC;
6 changes: 3 additions & 3 deletions contribs/gmf/src/import/importdatasourceComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,15 @@ class Controller {
return datumTokenizers;
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
identify: false,
local: serverUrls
});
}

// Register input[type=file] onchange event, use HTML5 File api
this.fileInput_.on('change', () => {
this.file = this.fileInput_[0].files && this.fileInput_[0].files[0] ?
this.fileInput_[0].files[0] : undefined;
const fileInput = /** @type HTMLInputElement */ (this.fileInput_[0]);
const files = fileInput.files;
this.file = files && files[0] ? files[0] : undefined;
this.scope_.$apply();
});
}
Expand Down
2 changes: 1 addition & 1 deletion contribs/gmf/src/import/wmsCapabilityLayertreeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class Controller {

/**
* @param {!Object} layer WMS Capability Layer object
* @return {number} Unique id for the Capability Layer.
* @return {string} Unique id for the Capability Layer.
* @export
*/
getUid(layer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Controller {

/**
* @param {!Object} layer WMTS Capability Layer object
* @return {number} Unique id for the Capability Layer.
* @return {string} Unique id for the Capability Layer.
* @export
*/
getUid(layer) {
Expand Down
8 changes: 5 additions & 3 deletions contribs/gmf/src/layertree/SyncLayertreeMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function SyncLayertreeMap($rootScope, ngeoLayerHelper, ngeoWMSTime, gmfTh
});

$rootScope.$on('ngeo-layertree-state', (map, treeCtrl, firstParent) => {
this.sync_(/** @type import("ol/Map.js").default */ (map), firstParent);
this.sync_(firstParent);
});
}

Expand Down Expand Up @@ -94,14 +94,14 @@ SyncLayertreeMap.prototype.createLayer = function(treeCtrl, map, dataLayerGroup,
/**
* Synchronise the state of each layers corresponding to the given tree and
* all its children.
* @param {import("ol/Map.js").default} map A map that contains the layers.
* @param {import("ngeo/layertree/Controller.js").LayertreeController} treeCtrl ngeo layertree controller.
* @private
*/
SyncLayertreeMap.prototype.sync_ = function(map, treeCtrl) {
SyncLayertreeMap.prototype.sync_ = function(treeCtrl) {
treeCtrl.traverseDepthFirst((treeCtrl) => {
if (treeCtrl.layer && !treeCtrl.node.mixed) {
this.updateLayerState_(/** @type import("ol/layer/Image.js").default|import("ol/layer/Tile.js").default */ (treeCtrl.layer), treeCtrl);
return LayertreeVisitorDecision.STOP;
}
});
};
Expand All @@ -127,6 +127,7 @@ SyncLayertreeMap.prototype.updateLayerState_ = function(layer, treeCtrl) {
names.push(treeCtrl.node.layers);
const style = (treeCtrl.node.style !== undefined) ? treeCtrl.node.style : '';
styles.push(style);
return LayertreeVisitorDecision.STOP;
}
});
if (names.length === 0) {
Expand Down Expand Up @@ -231,6 +232,7 @@ SyncLayertreeMap.prototype.createLayerFromGroup_ = function(treeCtrl,
ctrl.setState('on', false);
this.updateLayerState_(/** @type {import("ol/layer/Image.js").default} */ (layer), ctrl);
hasActiveChildren = true;
return LayertreeVisitorDecision.STOP;
}
});
layer.setVisible(hasActiveChildren);
Expand Down
30 changes: 18 additions & 12 deletions contribs/gmf/src/layertree/TreeManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ LayertreeTreeManager.prototype.addFirstLevelGroups = function(firstLevelGroups,
* @private
*/
LayertreeTreeManager.prototype.updateTreeGroupsState_ = function(groups) {
const treeGroupsParam = {};
const treeGroupsParam = /** @type Object.<string, string> */ ({});
treeGroupsParam[PermalinkParam.TREE_GROUPS] = groups.map(node => node.name).join(',');
this.ngeoStateManager_.updateState(treeGroupsParam);
if (this.$injector_.has('gmfPermalink')) {
Expand Down Expand Up @@ -286,11 +286,13 @@ LayertreeTreeManager.prototype.addFirstLevelGroup_ = function(group) {
* @private
*/
LayertreeTreeManager.prototype.manageExclusiveGroupSingleChecked_ = function(node, found) {
const children = node.children;
const groupNode = /** @type import('gmf/themes.js').GmfGroup */ (node);
const children = groupNode.children;
if (children) {
for (const child of children) {
if (child.children) {
found = this.manageExclusiveGroupSingleChecked_(child, found);
const childGroup = /** @type import('gmf/themes.js').GmfGroup */ (child);
if (childGroup.children) {
found = this.manageExclusiveGroupSingleChecked_(childGroup, found);
} else {
if (child.metadata.isChecked) {
if (found) {
Expand Down Expand Up @@ -342,7 +344,7 @@ LayertreeTreeManager.prototype.addGroupByLayerName = function(layerName, opt_add
console.warn('Tree controller not found, unable to add the group');
return;
}
let treeCtrlToActive;
let treeCtrlToActive = /** @type import("ngeo/layertree/Controller.js").LayertreeController */ (null);
treeCtrl.traverseDepthFirst((treeCtrl) => {
if (treeCtrl.node.name === layerName) {
treeCtrlToActive = treeCtrl;
Expand Down Expand Up @@ -423,12 +425,15 @@ LayertreeTreeManager.prototype.cloneGroupNode_ = function(group, names) {
* @private
*/
LayertreeTreeManager.prototype.toggleNodeCheck_ = function(node, names) {
if (!node.children) {
const groupNode = /** @type import('gmf/themes.js').GmfGroup */ (node);
if (!groupNode.children) {
return;
}
node.children.forEach((childNode) => {
if (childNode.children) {
this.toggleNodeCheck_(childNode, names);
groupNode.children.forEach((childNode) => {
const childGroupNode = /** @type import('gmf/themes.js').GmfGroup */ (
childNode);
if (childGroupNode.children) {
this.toggleNodeCheck_(childGroupNode, names);
} else if (childNode.metadata) {
childNode.metadata.isChecked = names.includes(childNode.name);
}
Expand Down Expand Up @@ -557,7 +562,7 @@ LayertreeTreeManager.prototype.refreshFirstLevelGroups_ = function(themes) {
* @private
*/
LayertreeTreeManager.prototype.getFirstLevelGroupFullState_ = function(treeCtrl) {
const children = {};
const children = /** @type Object.<string, TreeManagerFullState>} */ ({});
// Get the state of the treeCtrl children recursively.
treeCtrl.children.map((child) => {
children[child.node.name] = this.getFirstLevelGroupFullState_(child);
Expand Down Expand Up @@ -610,8 +615,9 @@ LayertreeTreeManager.prototype.setNodeMetadataFromFullState_ = function(node, fu
}

// Set the metadata of the node children recursively.
if (node.children) {
node.children.map((child) => {
const groupNode = /** @type import('gmf/themes.js').GmfGroup */ (node);
if (groupNode.children) {
groupNode.children.map((child) => {
this.setNodeMetadataFromFullState_(child, fullState.children[child.name]);
});
}
Expand Down
30 changes: 20 additions & 10 deletions contribs/gmf/src/layertree/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import ngeoDatasourceOGC, {ServerType} from 'ngeo/datasource/OGC.js';

import ngeoLayertreeComponent from 'ngeo/layertree/component.js';

import ngeoLayertreeController from 'ngeo/layertree/Controller.js';
import ngeoLayertreeController, {
LayertreeVisitorDecision
} from 'ngeo/layertree/Controller.js';
import ngeoMapLayerHelper from 'ngeo/map/LayerHelper.js';
import ngeoMiscSyncArrays from 'ngeo/misc/syncArrays.js';
import ngeoMiscWMSTime from 'ngeo/misc/WMSTime.js';
Expand Down Expand Up @@ -173,8 +175,9 @@ module.component('gmfLayertree', component);
* @ngdoc controller
* @ngname gmfLayertreeController
*/
function Controller($element, $scope, ngeoLayerHelper, gmfDataSourceBeingFiltered,
gmfExternalDataSourcesManager, gmfPermalink, gmfTreeManager, gmfSyncLayertreeMap, ngeoWMSTime, gmfThemes) {
function Controller($element, $scope, ngeoLayerHelper,
gmfDataSourceBeingFiltered, gmfExternalDataSourcesManager, gmfPermalink,
gmfTreeManager, gmfSyncLayertreeMap, ngeoWMSTime, gmfThemes) {

/**
* @type {?import("ol/Map.js").default}
Expand Down Expand Up @@ -319,7 +322,11 @@ Controller.prototype.updateDimensions_ = function(treeCtrl) {
if (ctrl.node.dimensions) {
const layer = ctrl.layer;
console.assert(layer instanceof olLayerLayer);
this.updateLayerDimensions_(layer, /** @type import('gmf/themes.js').GmfGroup|import('gmf/themes.js').GmfLayer */ (ctrl.node));
this.updateLayerDimensions_(
/** @type olLayerLayer */ (layer),
/** @type import('gmf/themes.js').GmfGroup|import('gmf/themes.js').GmfLayer */ (ctrl.node)
);
return LayertreeVisitorDecision.STOP;
}
});
};
Expand Down Expand Up @@ -458,7 +465,8 @@ Controller.prototype.updateWMSTimeLayerState = function(layertreeCtrl, time) {
if (!time) {
return;
}
const dataSource = layertreeCtrl.getDataSource();
const dataSource = /** @type {?import("ngeo/datasource/OGC").default} */ (
layertreeCtrl.getDataSource());
if (dataSource) {
console.assert(dataSource instanceof ngeoDatasourceOGC);
dataSource.timeRangeValue = time;
Expand Down Expand Up @@ -521,7 +529,7 @@ Controller.prototype.getLegendIconURL = function(treeCtrl) {
* @export
*/
Controller.prototype.getLegendsObject = function(treeCtrl) {
const legendsObject = {};
const legendsObject = /** @type {Object.<string, string>} */ ({});
if (/** @type import('gmf/themes.js').GmfGroup */ (treeCtrl.node).children !== undefined) {
return null;
}
Expand All @@ -536,7 +544,8 @@ Controller.prototype.getLegendsObject = function(treeCtrl) {
const layer = treeCtrl.layer;
if (gmfLayer.type === 'WMTS') {
console.assert(layer instanceof olLayerTile);
const wmtsLegendURL = this.layerHelper_.getWMTSLegendURL(layer);
const wmtsLegendURL = this.layerHelper_.getWMTSLegendURL(
/** @type {import("ol/layer/Tile.js").default} */ (layer));
legendsObject[gmfLayerDefaultName] = wmtsLegendURL;
return wmtsLegendURL ? legendsObject : null;
} else {
Expand All @@ -546,12 +555,13 @@ Controller.prototype.getLegendsObject = function(treeCtrl) {
const scale = this.getScale_();
// QGIS can handle multiple layers natively. Use Multiple URLs for other map
// servers
let layerNamesList;
if (gmfOgcServer.type === ServerType.QGISSERVER) {
layersNames = [layersNames];
layerNamesList = [layersNames];
} else {
layersNames = layersNames.split(',');
layerNamesList = layersNames.split(',');
}
layersNames.forEach((layerName) => {
layerNamesList.forEach((layerName) => {
legendsObject[layerName] = this.layerHelper_.getWMSLegendURL(gmfOgcServer.url, layerName, scale);
});
return legendsObject;
Expand Down
18 changes: 17 additions & 1 deletion src/datasource/OGC.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class OGC extends ngeoDatasourceDataSource {
* The filter condition to apply to the filter rules (if any).
* @type {string}
*/
this.filterCondition = options.filterCondition || ngeoFilterCondition.AND;
this.filterCondition_ = options.filterCondition || ngeoFilterCondition.AND;

/**
* A list of filter rules to apply to this data source using the filter
Expand Down Expand Up @@ -476,6 +476,22 @@ class OGC extends ngeoDatasourceDataSource {
return this.dimensions_;
}

/**
* @return {string} Filter condition
* @export
*/
get filterCondition() {
return this.filterCondition_;
}

/**
* @param {string} filterCondition Filter condition
* @export
*/
set filterCondition(filterCondition) {
this.filterCondition_ = filterCondition;
}

/**
* @return {?TimeRange} Time range value
* @export
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"src/**/*.js",
"api/src/**/*.js",
"contribs/gmf/src/**/*.js",
"test/spec/**/*.js",
"contribs/gmf/test/spec/**/*.js",
//"test/spec/**/*.js",
//"contribs/gmf/test/spec/**/*.js",
"examples/*.js",
"contribs/gmf/examples/*.js",
]
Expand Down

0 comments on commit 8a4d6fc

Please sign in to comment.