Skip to content

Commit

Permalink
Merge pull request #4969 from camptocamp/remove-cast
Browse files Browse the repository at this point in the history
Remove unneeded cast
  • Loading branch information
sbrunner authored Jun 25, 2019
2 parents eb1329c + a20f9e0 commit 2bb4020
Show file tree
Hide file tree
Showing 51 changed files with 367 additions and 208 deletions.
8 changes: 5 additions & 3 deletions api/src/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,11 @@ class Map {
selectObject(id, table = false) {
const feature = this.vectorSource_.getFeatureById(id);
if (feature) {
const coordinates = /** @type {import('ol/geom/Point.js').default} */(
feature.getGeometry()
).getCoordinates();
const point = feature.getGeometry();
if (!(point instanceof Point)) {
throw new Error('Wrong geometry type');
}
const coordinates = point.getCoordinates();
const properties = feature.getProperties();
let contentHTML = '';
if (table) {
Expand Down
2 changes: 1 addition & 1 deletion contribs/gmf/examples/editfeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ MainController.prototype.insertFeature = function() {
throw new Error('Missing resolution');
}
const buffer = resolution * -50; // 50 pixel buffer inside the extent
const size = /** @type {number[]} */ (map.getSize());
const size = map.getSize();
const extent = olExtent.buffer(
view.calculateExtent(size),
buffer
Expand Down
1 change: 0 additions & 1 deletion contribs/gmf/examples/featurestyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ MainController.prototype.handleMapSingleClick_ = function(evt) {
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
29 changes: 15 additions & 14 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,10 +259,9 @@ export class DatasourceManager {

const dataSources = this.dataSources_.getArray();
for (const dataSource of dataSources) {
const gmfOGCDataSource = /** @type {import('gmf/datasource/OGC').default} */(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 @@ -364,7 +364,7 @@ export class DatasourceManager {
const visitor = (treeCtrl) => {
const node = /** @type {import('gmf/themes.js').GmfGroup|!import('gmf/themes.js').GmfLayer} */ (
treeCtrl.node);
const groupNode = /** @type {import('gmf/themes.js').GmfGroup} */ (node);
const groupNode = /** @type {import('gmf/themes.js').GmfGroup} */(node);
const children = groupNode.children;
if (!children) {
newTreeCtrls.push(treeCtrl);
Expand Down Expand Up @@ -434,7 +434,7 @@ export class DatasourceManager {
*/
createDataSource_(firstLevelGroup, node, ogcServers) {

const groupNode = /** @type {import('gmf/themes.js').GmfGroup} */ (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 Down Expand Up @@ -472,7 +472,7 @@ export class DatasourceManager {

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

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

// Common options for WMS
maxResolution = gmfLayerWMS.maxResolutionHint;
Expand Down Expand Up @@ -831,11 +831,10 @@ export class DatasourceManager {
* @hidden
*/
getDataSourceLayer_(dataSource) {
const gmfOGCDataSource = /** @type {import("gmf/datasource/OGC.js").default} */ (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 @@ -880,13 +879,15 @@ export class DatasourceManager {
if (dsLayer == undefined) {
continue;
}
const gmfOGCDataSource = /** @type {import('gmf/datasource/OGC.js').default} */(dataSource);
const gmfLayerWMS = /** @type {import('gmf/themes.js').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
12 changes: 6 additions & 6 deletions contribs/gmf/src/editing/Snapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,19 +288,19 @@ EditingSnappingService.prototype.unregisterAllTreeCtrl_ = function() {
* @private
*/
EditingSnappingService.prototype.getOGCServer_ = function(treeCtrl) {
const gmfLayer = /** @type {import('gmf/themes.js').GmfLayer} */ (treeCtrl.node);
const gmfLayer = /** @type {import('gmf/themes.js').GmfLayer} */(treeCtrl.node);
if (gmfLayer.type !== ThemeNodeType.WMS) {
return null;
}
const gmfLayerWMS = /** @type {import('gmf/themes.js').GmfLayerWMS} */ (gmfLayer);
const gmfLayerWMS = /** @type {import('gmf/themes.js').GmfLayerWMS} */(gmfLayer);

let ogcServerName;
const gmfGroup = /** @type {import('gmf/themes.js').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);
const firstNode = /** @type {import('gmf/themes.js').GmfGroup} */ (firstTreeCtrl.node);
const firstNode = /** @type {import('gmf/themes.js').GmfGroup} */(firstTreeCtrl.node);
ogcServerName = firstNode.ogcServer;
}
if (!ogcServerName) {
Expand Down Expand Up @@ -337,14 +337,14 @@ EditingSnappingService.prototype.getWFSConfig_ = function(treeCtrl) {
return null;
}

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

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

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

// (3)
const featureTypes = [];
Expand Down
17 changes: 12 additions & 5 deletions contribs/gmf/src/layertree/SyncLayertreeMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ngeoMiscWMSTime from 'ngeo/misc/WMSTime.js';
import {getUid as olUtilGetUid} from 'ol/util.js';
import olLayerImage from 'ol/layer/Image.js';
import olLayerTile from 'ol/layer/Tile.js';
import Group from 'ol/layer/Group.js';

/**
* Service to create layer based on a ngeo.layertree.Controller with a
Expand Down Expand Up @@ -177,7 +178,7 @@ SyncLayertreeMap.prototype.updateLayerState_ = function(layer, treeCtrl) {
*/
SyncLayertreeMap.prototype.createGroup_ = function(treeCtrl, map,
dataLayerGroup, opt_position) {
const groupNode = /** @type {import('gmf/themes.js').GmfGroup} */ (treeCtrl.node);
const groupNode = /** @type {import('gmf/themes.js').GmfGroup} */(treeCtrl.node);
let layer = null;
const isFirstLevelGroup = treeCtrl.parent.isRoot;

Expand All @@ -196,7 +197,10 @@ SyncLayertreeMap.prototype.createGroup_ = function(treeCtrl, map,
const inAMixedGroup = !this.isOneParentNotMixed_(treeCtrl);
if (inAMixedGroup) {
layer = this.createLayerFromGroup_(treeCtrl, true);
const layerGroup = /** @type {import("ol/layer/Group.js").default} */ (getLayer(treeCtrl.parent));
const layerGroup = getLayer(treeCtrl.parent);
if (!(layerGroup instanceof Group)) {
throw new Error('Wrong layerGroup type');
}
layerGroup.getLayers().insertAt(0, layer);
}
}
Expand All @@ -220,7 +224,7 @@ SyncLayertreeMap.prototype.createGroup_ = function(treeCtrl, map,
SyncLayertreeMap.prototype.createLayerFromGroup_ = function(treeCtrl, mixed) {
/** @type {import("ol/layer/Image.js").default|import("ol/layer/Group.js").default} */
let layer;
const groupNode = /** @type {import('gmf/themes.js').GmfGroup} */ (treeCtrl.node);
const groupNode = /** @type {import('gmf/themes.js').GmfGroup} */(treeCtrl.node);
if (mixed) { // Will be one ol.layer per each node.
layer = this.layerHelper_.createBasicGroup();
} else { // Will be one ol.layer for multiple WMS nodes.
Expand Down Expand Up @@ -323,10 +327,13 @@ SyncLayertreeMap.prototype.createLeafInAMixedGroup_ = function(treeCtrl, map) {
* @private
*/
SyncLayertreeMap.prototype.initGmfLayerInANotMixedGroup_ = function(treeCtrl, map) {
const leafNode = /** @type {import('gmf/themes.js').GmfLayer} */ (treeCtrl.node);
const leafNode = /** @type {import('gmf/themes.js').GmfLayer} */(treeCtrl.node);
const firstLevelGroup = this.getFirstLevelGroupCtrl_(treeCtrl);
console.assert(firstLevelGroup);
const layer = /** @type {import("ol/layer/Image.js").default} */ (firstLevelGroup.layer);
const layer = firstLevelGroup.layer;
if (!(layer instanceof olLayerImage)) {
throw new Error('Wrong layer type');
}
console.assert(layer instanceof olLayerImage);
// Update layer information and tree state.
this.updateLayerReferences_(leafNode, layer);
Expand Down
10 changes: 8 additions & 2 deletions contribs/gmf/src/layertree/TreeManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,10 @@ LayertreeTreeManager.prototype.removeAll = function() {
* @private
*/
LayertreeTreeManager.prototype.cloneGroupNode_ = function(group, names) {
const clone = /** @type {import('gmf/themes.js').GmfGroup} */ (Object.assign({}, group));
/**
* @type {import('gmf/themes.js').GmfGroup}
*/
const clone = Object.assign({}, group);
this.toggleNodeCheck_(clone, names);
return clone;
};
Expand Down Expand Up @@ -582,7 +585,10 @@ LayertreeTreeManager.prototype.refreshFirstLevelGroups_ = function(themes) {
* @private
*/
LayertreeTreeManager.prototype.getFirstLevelGroupFullState_ = function(treeCtrl) {
const children = /** @type {Object<string, TreeManagerFullState>} */({});
/**
* @type {Object<string, TreeManagerFullState>}
*/
const children = {};
// Get the state of the treeCtrl children recursively.
treeCtrl.children.map((child) => {
children[child.node.name] = this.getFirstLevelGroupFullState_(child);
Expand Down
12 changes: 6 additions & 6 deletions contribs/gmf/src/layertree/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ Controller.prototype.getLegendsObject = function(treeCtrl) {
return null;
}

const gmfLayer = /** @type {import('gmf/themes.js').GmfLayer} */ (treeCtrl.node);
const gmfLayer = /** @type {import('gmf/themes.js').GmfLayer} */(treeCtrl.node);
const gmfLayerDefaultName = gmfLayer.name;
if (gmfLayer.metadata.legendImage) {
legendsObject[gmfLayerDefaultName] = gmfLayer.metadata.legendImage;
Expand All @@ -591,7 +591,7 @@ Controller.prototype.getLegendsObject = function(treeCtrl) {
}
return wmtsLegendURL ? legendsObject : null;
} else {
const gmfLayerWMS = /** @type {import('gmf/themes.js').GmfLayerWMS} */ (gmfLayer);
const gmfLayerWMS = /** @type {import('gmf/themes.js').GmfLayerWMS} */(gmfLayer);
const layersNames = gmfLayerWMS.layers;
const gmfOgcServer = this.gmfTreeManager_.getOgcServer(treeCtrl);
const scale = this.getScale_();
Expand Down Expand Up @@ -771,7 +771,7 @@ Controller.prototype.zoomToResolution = function(treeCtrl) {
if (!this.map) {
throw new Error('Missing map');
}
const gmfLayer = /** @type {import('gmf/themes.js').GmfLayerWMS} */ (treeCtrl.node);
const gmfLayer = /** @type {import('gmf/themes.js').GmfLayerWMS} */(treeCtrl.node);
const view = this.map.getView();
const resolution = view.getResolution();
if (resolution === undefined) {
Expand Down Expand Up @@ -854,7 +854,7 @@ Controller.prototype.supportsCustomization = function(treeCtrl) {
* legend being shown.
*/
Controller.prototype.supportsLegend = function(treeCtrl) {
const node = /** @type {import('gmf/themes.js').GmfGroup} */ (treeCtrl.node);
const node = /** @type {import('gmf/themes.js').GmfGroup} */(treeCtrl.node);
return !!node.metadata &&
!!node.metadata.legend &&
!!this.getLegendsObject(treeCtrl);
Expand All @@ -867,8 +867,8 @@ Controller.prototype.supportsLegend = function(treeCtrl) {
* layer opacity being changed or not.
*/
Controller.prototype.supportsOpacityChange = function(treeCtrl) {
const node = /** @type {import('gmf/themes.js').GmfGroup} */ (treeCtrl.node);
const parentNode = /** @type {import('gmf/themes.js').GmfGroup} */ (treeCtrl.parent.node);
const node = /** @type {import('gmf/themes.js').GmfGroup} */(treeCtrl.node);
const parentNode = /** @type {import('gmf/themes.js').GmfGroup} */(treeCtrl.parent.node);
return !!treeCtrl.layer &&
(
(
Expand Down
12 changes: 9 additions & 3 deletions contribs/gmf/src/layertree/timeSliderComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,15 @@ Controller.prototype.init = function() {
this.isModeRange = this.time.mode === 'range';
this.minValue = initialOptions_.minDate;
this.maxValue = initialOptions_.maxDate;
const values = /** @type {number[]} */(initialOptions_.values);
this.dates = this.isModeRange ? [values[0], values[1]] :
initialOptions_.values;
const values = initialOptions_.values;
if (this.isModeRange) {
if (!(Array.isArray(values))) {
throw new Error('Wrong Options values');
}
this.dates = [values[0], values[1]];
} else {
this.dates = initialOptions_.values;
}
this.sliderOptions = {
range: this.isModeRange,
min: this.minValue,
Expand Down
14 changes: 9 additions & 5 deletions contribs/gmf/src/lidarprofile/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,11 @@ export class LidarprofileManager {
} catch (e) {
if (!this.isPlotSetup_) {
const canvas = d3select('#gmf-lidarprofile-container .lidar-canvas');
const canvasEl = /** @type {HTMLCanvasElement} */ (canvas.node());
const ctx = /** @type {CanvasRenderingContext2D} */ (canvasEl.getContext('2d'));
const canvasEl = /** @type {HTMLCanvasElement} */(canvas.node());
const ctx = canvasEl.getContext('2d');
if (ctx === null) {
throw new Error('Missing ctx');
}
ctx.clearRect(0, 0, canvasEl.getBoundingClientRect().width, canvasEl.getBoundingClientRect().height);
canvas.selectAll('*').remove();
const errorTxt = this.getHTMLError_();
Expand Down Expand Up @@ -522,9 +525,10 @@ export class LidarprofileManager {
const clip = this.utils.clipLineByMeasure(this.config, map_resolution,
this.line_, domainX[0], domainX[1]);

const source = /** @type {olSourceVector<import("ol/geom/Geometry.js").default>} */(
this.lidarBuffer.getSource()
);
/**
* @type {olSourceVector<import("ol/geom/Geometry.js").default>}
*/
const source = this.lidarBuffer.getSource();
source.clear();
source.addFeature(clip.bufferGeom);
this.lidarBuffer.setStyle(clip.bufferStyle);
Expand Down
4 changes: 2 additions & 2 deletions contribs/gmf/src/lidarprofile/Measure.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ export default class {
throw new Error('Missing manager.plot');
}
const svg = d3select('#gmf-lidarprofile-container svg.lidar-svg');
const svgEl = /** @type {HTMLElement} */ (svg.node());
const svgEl = /** @type {HTMLElement} */(svg.node());
const canvas = d3select('#gmf-lidarprofile-container .lidar-canvas');
const canvasEl = /** @type {HTMLCanvasElement} */ (canvas.node());
const canvasEl = /** @type {HTMLCanvasElement} */(canvas.node());

const svgCoordinates = d3mouse(svgEl);
const canvasCoordinates = d3mouse(canvasEl);
Expand Down
Loading

0 comments on commit 2bb4020

Please sign in to comment.