Skip to content

Commit

Permalink
Fix the types
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Jun 25, 2019
1 parent bfe556b commit a20f9e0
Show file tree
Hide file tree
Showing 51 changed files with 247 additions and 575 deletions.
50 changes: 10 additions & 40 deletions api/src/Themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,17 @@ export function getBackgroundLayers() {
return getThemesPromise().then(themes => {
const promises = [];
for (const config of themes.background_layers) {
/**
* @type {import('gmf/themes.js').GmfLayer}
*/
const layerConfig = config;
const layerConfig = /** @type {import('gmf/themes.js').GmfLayer} */(config);
if (layerConfig.type === 'WMTS') {
/**
* @type {import('gmf/themes.js').GmfLayerWMTS}
*/
const layerWMTS = config;
const layerWMTS = /** @type {import('gmf/themes.js').GmfLayerWMTS} */(config);
promises.push(
createWMTSLayer(layerWMTS).then((layer) => {
layer.set('config.name', layerWMTS.name);
return layer;
})
);
} else if (layerConfig.type === 'WMS') {
/**
* @type {import('gmf/themes.js').GmfLayerWMS}
*/
const layerWMS = config;
const layerWMS = /** @type {import('gmf/themes.js').GmfLayerWMS} */(config);
const ogcServer = themes.ogcServers[config.ogcServer];
promises.push(
createWMSLayer(layerWMS, ogcServer).then((layer) => {
Expand All @@ -76,21 +67,12 @@ export function getBackgroundLayers() {

/** @type {Promise<TileLayer|ImageLayer>[]} */
const groupPromises = reversed.map(item => {
/**
* @type {import('gmf/themes.js').GmfLayer}
*/
const child = item;
const child = /** @type {import('gmf/themes.js').GmfLayer} */(item);
if (child.type === 'WMTS') {
/**
* @type {import('gmf/themes.js').GmfLayerWMTS}
*/
const layerWMTS = child;
const layerWMTS = /** @type {import('gmf/themes.js').GmfLayerWMTS} */(child);
return createWMTSLayer(layerWMTS);
} else if (child.type === 'WMS') {
/**
* @type {import('gmf/themes.js').GmfLayerWMS}
*/
const layerWMS = child;
const layerWMS = /** @type {import('gmf/themes.js').GmfLayerWMS} */(child);
return createWMSLayer(layerWMS, themes.ogcServers[child.ogcServer]);
}
throw new Error('Unknow layer type');
Expand Down Expand Up @@ -151,20 +133,14 @@ export function getOverlayDefs() {
* @hidden
*/
export function writeOverlayDefs(config, ogcServers, opt_ogcServer) {
/**
* @type {import('gmf/themes.js').GmfGroup}
*/
const group = config;
const group = /** @type {import('gmf/themes.js').GmfGroup} */(config);
const ogcServer = opt_ogcServer ? opt_ogcServer : ogcServers[group.ogcServer];
if (group.children) {
for (const childConfig of group.children) {
writeOverlayDefs(childConfig, ogcServers, ogcServer);
}
} else {
/**
* @type {import('gmf/themes.js').GmfLayer}
*/
const layer = config;
const layer = /** @type {import('gmf/themes.js').GmfLayer} */(config);
overlayDefs.set(
layer.name,
{
Expand Down Expand Up @@ -198,16 +174,10 @@ export function getOverlayLayers(layerNames) {
const ogcServer = overlayDef.ogcServer;

if (overlayDef.layer.type === 'WMTS') {
/**
* @type {import('gmf/themes.js').GmfLayerWMTS}
*/
const wmtsLayer = overlayDef.layer;
const wmtsLayer = /** @type {import('gmf/themes.js').GmfLayerWMTS} */(overlayDef.layer);
promises.push(createWMTSLayer(wmtsLayer));
} else if (overlayDef.layer.type === 'WMS' && ogcServer) {
/**
* @type {import('gmf/themes.js').GmfLayerWMS}
*/
const wmsLayer = overlayDef.layer;
const wmsLayer = /** @type {import('gmf/themes.js').GmfLayerWMS} */(overlayDef.layer);
promises.push(createWMSLayer(wmsLayer, ogcServer));
}
}
Expand Down
3 changes: 0 additions & 3 deletions contribs/gmf/examples/editfeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,6 @@ MainController.prototype.insertFeature = function() {
throw new Error('Missing resolution');
}
const buffer = resolution * -50; // 50 pixel buffer inside the extent
/**
* @type {number[]}
*/
const size = map.getSize();
const extent = olExtent.buffer(
view.calculateExtent(size),
Expand Down
7 changes: 3 additions & 4 deletions contribs/gmf/examples/featurestyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,9 @@ function MainController($scope, ngeoFeatureHelper) {
MainController.prototype.handleMapSingleClick_ = function(evt) {
const pixel = evt.pixel;

/**
* @type {olFeature<import("ol/geom/Geometry.js").default>}
*/
const feature = this.map.forEachFeatureAtPixel(pixel, feature => feature);
const feature = /** @type {olFeature<import("ol/geom/Geometry.js").default>} */(
this.map.forEachFeatureAtPixel(pixel, feature => feature)
);
if (this.selectedFeature) {
this.featureHelper_.setStyle(this.selectedFeature);
}
Expand Down
5 changes: 1 addition & 4 deletions contribs/gmf/examples/layertree.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,7 @@ function MainController(gmfTreeManager, gmfThemes, gmfThemeManager, ngeoLocation
});
});
flatNodes.forEach((node) => {
/**
* @type {import('gmf/themes.js').GmfGroup}
*/
const groupNode = node;
const groupNode = /** @type {import('gmf/themes.js').GmfGroup} */(node);
// Get an array of all layers
if (groupNode.children === undefined) {
this.layers.push(/** @type {import('gmf/themes.js').GmfLayer} */(node));
Expand Down
5 changes: 1 addition & 4 deletions contribs/gmf/examples/layertreeadd.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,7 @@ function MainController(gmfTreeManager, gmfThemes, gmfThemeManager, ngeoLocation
});
});
flatNodes.forEach((node) => {
/**
* @type {import('gmf/themes.js').GmfGroup}
*/
const groupNode = node;
const groupNode = /** @type {import('gmf/themes.js').GmfGroup} */(node);
// Get an array of all layers
if (groupNode.children === undefined) {
this.layers.push(/** @type {import('gmf/themes.js').GmfLayer} */(node));
Expand Down
5 changes: 1 addition & 4 deletions contribs/gmf/examples/xsdattributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@ function MainController($timeout, gmfThemes, gmfXSDAttributes) {
});
});
flatNodes.forEach((node) => {
/**
* @type {import('gmf/themes.js').GmfGroup}
*/
const groupNode = node;
const groupNode = /** @type {import('gmf/themes.js').GmfGroup} */(node);
// Get an array of all layers
if (groupNode.children === undefined && layerNames.indexOf(node.name) !== -1) {
this.layers.push(/** @type {import('gmf/themes.js').GmfLayer} */(node));
Expand Down
5 changes: 1 addition & 4 deletions contribs/gmf/src/controllers/AbstractMobileController.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,7 @@ export class AbstractMobileController extends AbstractAppController {
openNavMenu(target) {
const navElements = document.getElementsByClassName('gmf-mobile-nav-button');
for (let i = 0; i < navElements.length; i++) {
/**
* @type {HTMLElement}
*/
const element = navElements[i];
const element = /** @type {HTMLElement} */(navElements[i]);
if (element.dataset && element.dataset.target === target) {
element.click();
}
Expand Down
63 changes: 17 additions & 46 deletions contribs/gmf/src/datasource/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import gmfDatasourceWFSAliases from 'gmf/datasource/WFSAliases.js';
import gmfLayertreeSyncLayertreeMap, {getLayer} from 'gmf/layertree/SyncLayertreeMap.js';
import gmfLayertreeTreeManager from 'gmf/layertree/TreeManager.js';
import gmfThemeThemes, {ThemeNodeType} from 'gmf/theme/Themes.js';
import gmfOGC from 'gmf/datasource/OGC.js';

import OGC, {ServerType, WFSOutputFormat, Type} from 'ngeo/datasource/OGC.js';
import ngeoDatasourceDataSources from 'ngeo/datasource/DataSources.js';
Expand Down Expand Up @@ -258,13 +259,9 @@ export class DatasourceManager {

const dataSources = this.dataSources_.getArray();
for (const dataSource of dataSources) {
/**
* @type {import('gmf/datasource/OGC').default}
*/
const gmfOGCDataSource = dataSource;
if (gmfOGCDataSource.dimensionsFiltersConfig) {
for (const key in gmfOGCDataSource.dimensionsFiltersConfig) {
if (gmfOGCDataSource.dimensionsFiltersConfig[key].value === null) {
if (dataSource instanceof gmfOGC && dataSource.dimensionsFiltersConfig) {
for (const key in dataSource.dimensionsFiltersConfig) {
if (dataSource.dimensionsFiltersConfig[key].value === null) {
const layer = this.getDataSourceLayer_(dataSource);
if (layer == undefined) {
return;
Expand Down Expand Up @@ -367,10 +364,7 @@ export class DatasourceManager {
const visitor = (treeCtrl) => {
const node = /** @type {import('gmf/themes.js').GmfGroup|!import('gmf/themes.js').GmfLayer} */ (
treeCtrl.node);
/**
* @type {import('gmf/themes.js').GmfGroup}
*/
const groupNode = node;
const groupNode = /** @type {import('gmf/themes.js').GmfGroup} */(node);
const children = groupNode.children;
if (!children) {
newTreeCtrls.push(treeCtrl);
Expand Down Expand Up @@ -440,10 +434,7 @@ export class DatasourceManager {
*/
createDataSource_(firstLevelGroup, node, ogcServers) {

/**
* @type {import('gmf/themes.js').GmfGroup}
*/
const groupNode = node;
const groupNode = /** @type {import('gmf/themes.js').GmfGroup} */(node);
const children = groupNode.children;

// (1) Group node (node that has children). Loop in the children
Expand All @@ -458,10 +449,7 @@ export class DatasourceManager {
}

// From there on, the node is a layer node.
/**
* @type {import('gmf/themes.js').GmfLayer}
*/
const gmfLayer = node;
const gmfLayer = /** @type {import('gmf/themes.js').GmfLayer} */(node);

// (2) Skip layer node if a data source with the same id exists
const id = Number(olUtilGetUid(gmfLayer));
Expand All @@ -484,10 +472,7 @@ export class DatasourceManager {

if (ogcType === ThemeNodeType.WMTS) {
// (3) Manage WMTS
/**
* @type {import('gmf/themes.js').GmfLayerWMTS}
*/
const gmfLayerWMTS = gmfLayer;
const gmfLayerWMTS = /** @type {import('gmf/themes.js').GmfLayerWMTS} */(gmfLayer);

// Common options for WMTS
wmtsLayer = gmfLayerWMTS.layer;
Expand Down Expand Up @@ -521,10 +506,7 @@ export class DatasourceManager {
ogcImageType = gmfLayerWMTS.imageType;
} else if (ogcType === ThemeNodeType.WMS) {
// (4) Manage WMS
/**
* @type {import('gmf/themes.js').GmfLayerWMS}
*/
const gmfLayerWMS = gmfLayer;
const gmfLayerWMS = /** @type {import('gmf/themes.js').GmfLayerWMS} */(gmfLayer);

// Common options for WMS
maxResolution = gmfLayerWMS.maxResolutionHint;
Expand Down Expand Up @@ -849,14 +831,10 @@ export class DatasourceManager {
* @hidden
*/
getDataSourceLayer_(dataSource) {
/**
* @type {import("gmf/datasource/OGC.js").default}
*/
const gmfOGCDataSource = dataSource;
if (gmfOGCDataSource.gmfLayer == undefined) {
if (!(dataSource instanceof gmfOGC) || dataSource.gmfLayer == undefined) {
return;
}
const id = olUtilGetUid(gmfOGCDataSource.gmfLayer);
const id = olUtilGetUid(dataSource.gmfLayer);
if (id == undefined) {
return;
}
Expand Down Expand Up @@ -901,19 +879,15 @@ export class DatasourceManager {
if (dsLayer == undefined) {
continue;
}
/**
* @type {import('gmf/datasource/OGC.js').default}
*/
const gmfOGCDataSource = dataSource;
/**
* @type {import('gmf/themes.js').GmfLayerWMS}
*/
const gmfLayerWMS = gmfOGCDataSource.gmfLayer;
if (!(dataSource instanceof gmfOGC)) {
throw new Error('Wrong dataSource type');
}
const gmfLayerWMS = /** @type {import('gmf/themes.js').GmfLayerWMS} */(dataSource.gmfLayer);
if (olUtilGetUid(dsLayer) == olUtilGetUid(layer) &&
layer.get('querySourceIds').indexOf(String(dataSource.id)) >= 0 &&
gmfLayerWMS.layers.split(',').indexOf(wmsLayerName) >= 0) {

const id = olUtilGetUid(gmfOGCDataSource.gmfLayer);
const id = olUtilGetUid(dataSource.gmfLayer);
const item = this.treeCtrlCache_[id];
console.assert(item);
const treeCtrl = item.treeCtrl;
Expand Down Expand Up @@ -1032,10 +1006,7 @@ export class DatasourceManager {
* @hidden
*/
handleNgeoBackgroundLayerChange_(evt) {
/**
* @type {import('ngeo/map/BackgroundLayerMgr.js').BackgroundEvent}
*/
const event = evt;
const event = /** @type {import('ngeo/map/BackgroundLayerMgr.js').BackgroundEvent} */(evt);
const previousBackgroundLayer = event.detail.previous;
const currentBackgroundLayer = event.detail.current;
const cache = this.dataSourcesCache_;
Expand Down
35 changes: 7 additions & 28 deletions contribs/gmf/src/editing/Snapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,7 @@ EditingSnappingService.prototype.registerTreeCtrl_ = function(treeCtrl) {

// Skip any Layertree controller that has a node that is not a leaf
let node = /** @type {import('gmf/themes.js').GmfGroup|import('gmf/themes.js').GmfLayer} */ (treeCtrl.node);
/**
* @type {import('gmf/themes.js').GmfGroup}
*/
const groupNode = node;
const groupNode = /** @type {import('gmf/themes.js').GmfGroup} */(node);
if (groupNode.children) {
return;
}
Expand Down Expand Up @@ -291,31 +288,19 @@ EditingSnappingService.prototype.unregisterAllTreeCtrl_ = function() {
* @private
*/
EditingSnappingService.prototype.getOGCServer_ = function(treeCtrl) {
/**
* @type {import('gmf/themes.js').GmfLayer}
*/
const gmfLayer = treeCtrl.node;
const gmfLayer = /** @type {import('gmf/themes.js').GmfLayer} */(treeCtrl.node);
if (gmfLayer.type !== ThemeNodeType.WMS) {
return null;
}
/**
* @type {import('gmf/themes.js').GmfLayerWMS}
*/
const gmfLayerWMS = gmfLayer;
const gmfLayerWMS = /** @type {import('gmf/themes.js').GmfLayerWMS} */(gmfLayer);

let ogcServerName;
/**
* @type {import('gmf/themes.js').GmfGroup}
*/
const gmfGroup = treeCtrl.parent.node;
const gmfGroup = /** @type {import('gmf/themes.js').GmfGroup} */(treeCtrl.parent.node);
if (gmfGroup.mixed) {
ogcServerName = gmfLayerWMS.ogcServer;
} else {
const firstTreeCtrl = getFirstParentTree(treeCtrl);
/**
* @type {import('gmf/themes.js').GmfGroup}
*/
const firstNode = firstTreeCtrl.node;
const firstNode = /** @type {import('gmf/themes.js').GmfGroup} */(firstTreeCtrl.node);
ogcServerName = firstNode.ogcServer;
}
if (!ogcServerName) {
Expand Down Expand Up @@ -352,20 +337,14 @@ EditingSnappingService.prototype.getWFSConfig_ = function(treeCtrl) {
return null;
}

/**
* @type {import('gmf/themes.js').GmfLayer}
*/
const gmfLayer = treeCtrl.node;
const gmfLayer = /** @type {import('gmf/themes.js').GmfLayer} */(treeCtrl.node);

// (2)
if (gmfLayer.type !== ThemeNodeType.WMS) {
return null;
}

/**
* @type {import('gmf/themes.js').GmfLayerWMS}
*/
const gmfLayerWMS = gmfLayer;
const gmfLayerWMS = /** @type {import('gmf/themes.js').GmfLayerWMS} */(gmfLayer);

// (3)
const featureTypes = [];
Expand Down
5 changes: 1 addition & 4 deletions contribs/gmf/src/editing/editFeatureSelectorComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,7 @@ function Controller($scope, $timeout, gmfThemes, gmfTreeManager) {
throw new Error('Missing gmfTreeManager_.rootCtrl');
}
this.gmfTreeManager_.rootCtrl.traverseDepthFirst((treeCtrl) => {
/**
* @type {import('gmf/themes.js').GmfLayer}
*/
const gmfLayer = treeCtrl.node;
const gmfLayer = /** @type {import('gmf/themes.js').GmfLayer} */(treeCtrl.node);
if (gmfLayer.editable) {
console.assert(treeCtrl.children.length === 0);
editables.push(treeCtrl);
Expand Down
Loading

0 comments on commit a20f9e0

Please sign in to comment.