diff --git a/contribs/gmf/apps/desktop_alt/Controller.js b/contribs/gmf/apps/desktop_alt/Controller.js index 4467b8891190..612491e8f58c 100644 --- a/contribs/gmf/apps/desktop_alt/Controller.js +++ b/contribs/gmf/apps/desktop_alt/Controller.js @@ -117,7 +117,7 @@ class Controller extends AbstractDesktopController { const fill = new Fill({color: [255, 255, 255, 0.6]}); const stroke = new Stroke({color: [255, 0, 0, 1], width: 2}); const image = new Circle({fill, radius, stroke}); - const default_search_style = new Style({ + const defaultSearchStyle = new Style({ fill, image, stroke @@ -128,7 +128,7 @@ class Controller extends AbstractDesktopController { * @export */ this.searchStyles = { - 'default': default_search_style + 'default': defaultSearchStyle }; // Allow angular-gettext-tools to collect the strings to translate diff --git a/contribs/gmf/examples/objecteditinghub.js b/contribs/gmf/examples/objecteditinghub.js index afe6db8e8281..b8d16b0abf38 100644 --- a/contribs/gmf/examples/objecteditinghub.js +++ b/contribs/gmf/examples/objecteditinghub.js @@ -424,7 +424,7 @@ MainController.appendParams = function(uri, params) { // remove any trailing ? or & uri = uri.replace(/[?&]$/, ''); // append ? or & depending on whether uri has existing parameters - uri = uri.indexOf('?') === -1 ? `${uri}?` : `${uri}&`; + uri = uri.includes('?') ? `${uri}&` : `${uri}?`; return uri + qs; }; diff --git a/contribs/gmf/examples/xsdattributes.js b/contribs/gmf/examples/xsdattributes.js index fe6b7d236648..32de5f8c1856 100644 --- a/contribs/gmf/examples/xsdattributes.js +++ b/contribs/gmf/examples/xsdattributes.js @@ -83,7 +83,7 @@ function MainController($timeout, gmfThemes, gmfXSDAttributes) { flatNodes.forEach((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) { + if (groupNode.children === undefined && layerNames.includes(node.name)) { this.layers.push(/** @type {import('gmf/themes.js').GmfLayer} */(node)); } }); diff --git a/contribs/gmf/src/authentication/Service.js b/contribs/gmf/src/authentication/Service.js index e70aeee8f1fa..904c7a7e4473 100644 --- a/contribs/gmf/src/authentication/Service.js +++ b/contribs/gmf/src/authentication/Service.js @@ -189,7 +189,7 @@ export class AuthenticationService extends olEventsEventTarget { * @return {angular.IPromise} Promise. */ logout() { - const noReload = this.noReloadRole_ ? this.getRolesNames().indexOf(this.noReloadRole_) !== -1 : false; + const noReload = this.noReloadRole_ ? this.getRolesNames().includes(this.noReloadRole_) : false; const url = `${this.baseUrl_}/${RouteSuffix.LOGOUT}`; return this.$http_.get(url, {withCredentials: true}).then(() => { this.resetUser_(noReload); diff --git a/contribs/gmf/src/controllers/AbstractMobileController.js b/contribs/gmf/src/controllers/AbstractMobileController.js index f3d467dd39b8..6ba6d2e11ad7 100644 --- a/contribs/gmf/src/controllers/AbstractMobileController.js +++ b/contribs/gmf/src/controllers/AbstractMobileController.js @@ -182,6 +182,7 @@ export class AbstractMobileController extends AbstractAppController { */ openNavMenu(target) { const navElements = document.getElementsByClassName('gmf-mobile-nav-button'); + // eslint-disable-next-line @typescript-eslint/prefer-for-of for (let i = 0; i < navElements.length; i++) { const element = /** @type {HTMLElement} */(navElements[i]); if (element.dataset && element.dataset.target === target) { diff --git a/contribs/gmf/src/controllers/bootstrap.js b/contribs/gmf/src/controllers/bootstrap.js index daab64b7226d..ad536f660af5 100644 --- a/contribs/gmf/src/controllers/bootstrap.js +++ b/contribs/gmf/src/controllers/bootstrap.js @@ -12,7 +12,7 @@ import angular from 'angular'; function bootstrap(module) { // Hack to make the bootstrap type check working with polyfill.io const oldObjectToString = Object.prototype.toString; - if (oldObjectToString.toString().indexOf('[native code]') < 0) { + if (!oldObjectToString.toString().includes('[native code]')) { Object.prototype.toString = function() { if (this === null) { return '[object Null]'; diff --git a/contribs/gmf/src/datasource/Manager.js b/contribs/gmf/src/datasource/Manager.js index 1724006f4a86..2d2e7a06b347 100644 --- a/contribs/gmf/src/datasource/Manager.js +++ b/contribs/gmf/src/datasource/Manager.js @@ -1,5 +1,5 @@ import angular from 'angular'; -import gmfDatasourceOGC from 'gmf/datasource/OGC.js'; +import GmfDatasourceOGC from 'gmf/datasource/OGC.js'; import gmfDatasourceWFSAliases from 'gmf/datasource/WFSAliases.js'; import gmfLayertreeSyncLayertreeMap, {getLayer} from 'gmf/layertree/SyncLayertreeMap.js'; import gmfLayertreeTreeManager from 'gmf/layertree/TreeManager.js'; @@ -21,6 +21,7 @@ import {clear as clearObject} from 'ol/obj.js'; import olLayerImage from 'ol/layer/Image.js'; import olSourceImageWMS from 'ol/source/ImageWMS.js'; import olSourceTileWMS from 'ol/source/TileWMS.js'; +import BaseLayer from 'ol/layer/Base.js'; /** @@ -254,7 +255,13 @@ export class DatasourceManager { handleDimensionsChange_() { // Create a layer list to update each one only once + /** + * @type {BaseLayer[]} + */ const layers = []; + /** + * @type {string[]} + */ const layerIds = []; const dataSources = this.dataSources_.getArray(); @@ -267,7 +274,7 @@ export class DatasourceManager { return; } const id = olUtilGetUid(layer); - if (layerIds.indexOf(id) == -1) { + if (!layerIds.includes(id)) { layers.push(layer); layerIds.push(id); } @@ -667,7 +674,7 @@ export class DatasourceManager { options.wmtsUrl = wmtsUrl; } // Create the data source and add it to the cache - this.dataSourcesCache_[id] = new gmfDatasourceOGC(options); + this.dataSourcesCache_[id] = new GmfDatasourceOGC(options); } /** @@ -884,8 +891,8 @@ export class DatasourceManager { } 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) { + layer.get('querySourceIds').includes(String(dataSource.id)) && + gmfLayerWMS.layers.split(',').includes(wmsLayerName)) { const id = olUtilGetUid(dataSource.gmfLayer); const item = this.treeCtrlCache_[id]; diff --git a/contribs/gmf/src/datasource/OGC.js b/contribs/gmf/src/datasource/OGC.js index 806f8946f0d2..3cc408fce4c0 100644 --- a/contribs/gmf/src/datasource/OGC.js +++ b/contribs/gmf/src/datasource/OGC.js @@ -80,7 +80,7 @@ import ngeoDatasourceOGC from 'ngeo/datasource/OGC.js'; * @private * @hidden */ -class gmfDatasourceOGC extends ngeoDatasourceOGC { +class GmfDatasourceOGC extends ngeoDatasourceOGC { /** * A `gmf.datasource.OGC` extends a `ngeo.datasource.OGC` and @@ -113,4 +113,4 @@ class gmfDatasourceOGC extends ngeoDatasourceOGC { } -export default gmfDatasourceOGC; +export default GmfDatasourceOGC; diff --git a/contribs/gmf/src/disclaimer/component.js b/contribs/gmf/src/disclaimer/component.js index bfd1ad907eef..955189c6a421 100644 --- a/contribs/gmf/src/disclaimer/component.js +++ b/contribs/gmf/src/disclaimer/component.js @@ -298,7 +298,7 @@ DisclaimerController.prototype.$onDestroy = function() { DisclaimerController.prototype.showDisclaimerMessage_ = function(msg) { msg = this.gettextCatalog_.getString(msg); if (this.external) { - if (this.msgs_.indexOf(msg) < 0) { + if (!this.msgs_.includes(msg)) { this.msgs_.push(msg); } this.msg = `${this.sce_.trustAsHtml(this.msgs_.join('
'))}`; diff --git a/contribs/gmf/src/editing/editFeatureComponent.js b/contribs/gmf/src/editing/editFeatureComponent.js index f1d0936a9c5f..0d46936402a8 100644 --- a/contribs/gmf/src/editing/editFeatureComponent.js +++ b/contribs/gmf/src/editing/editFeatureComponent.js @@ -710,8 +710,13 @@ Controller.prototype.save = function() { if (attribute.format) { if (this.feature.get(attribute.name)) { const name = this.feature.get(attribute.name); - console.assert(typeof name == 'string'); + if (typeof name == 'string') { + throw new Error('Wrong name type'); + } const value = dateFormatter.parseDate(name, attribute.format); + if (value === null) { + throw new Error('Missing date'); + } let jsonFormat = 'Y-m-d\\TH:i:s'; if (attribute.type === 'date') { jsonFormat = 'Y-m-d'; diff --git a/contribs/gmf/src/filters/filterselectorComponent.js b/contribs/gmf/src/filters/filterselectorComponent.js index 084cb1704b6e..534e2e9bb738 100644 --- a/contribs/gmf/src/filters/filterselectorComponent.js +++ b/contribs/gmf/src/filters/filterselectorComponent.js @@ -6,7 +6,7 @@ import gmfDatasourceDataSourceBeingFiltered from 'gmf/datasource/DataSourceBeing import gmfDatasourceHelper from 'gmf/datasource/Helper.js'; -import gmfDatasourceOGC from 'gmf/datasource/OGC.js'; +import GmfDatasourceOGC from 'gmf/datasource/OGC.js'; import gmfFiltersSavedFilters from 'gmf/filters/SavedFilters.js'; import ngeoMessageModalComponent from 'ngeo/message/modalComponent.js'; @@ -410,7 +410,7 @@ class FilterSelectorController { handleDataSourcesAdd_(evt) { if (evt instanceof CollectionEvent) { const dataSource = evt.element; - if (dataSource instanceof gmfDatasourceOGC) { + if (dataSource instanceof GmfDatasourceOGC) { this.registerDataSource_(dataSource); } } @@ -429,7 +429,7 @@ class FilterSelectorController { handleDataSourcesRemove_(evt) { if (evt instanceof CollectionEvent) { const dataSource = evt.element; - if (dataSource instanceof gmfDatasourceOGC) { + if (dataSource instanceof GmfDatasourceOGC) { this.unregisterDataSource_(dataSource); } } diff --git a/contribs/gmf/src/lidarprofile/Manager.js b/contribs/gmf/src/lidarprofile/Manager.js index d8ac60f682f7..d5896e8b5941 100644 --- a/contribs/gmf/src/lidarprofile/Manager.js +++ b/contribs/gmf/src/lidarprofile/Manager.js @@ -236,8 +236,8 @@ export class LidarprofileManager { const domain = this.plot.updateScaleX.domain(); pytreeLinestring = ''; - for (let i = 0; i < clippedLine.length; i++) { - pytreeLinestring += `{${clippedLine[i][0]},${clippedLine[i][1]}},`; + for (const clipped of clippedLine) { + pytreeLinestring += `{${clipped[0]},${clipped[1]}},`; } pytreeLinestring = pytreeLinestring.substr(0, pytreeLinestring.length - 1); maxLODWith = this.utils.getNiceLOD(domain[1] - domain[0], max_levels); @@ -364,8 +364,8 @@ export class LidarprofileManager { const uInt8header = new Uint8Array(profile, 4, headerSize); let strHeaderLocal = ''; - for (let i = 0; i < uInt8header.length; i++) { - strHeaderLocal += String.fromCharCode(uInt8header[i]); + for (const header of uInt8header) { + strHeaderLocal += String.fromCharCode(header); } try { @@ -403,11 +403,14 @@ export class LidarprofileManager { const attr = jHeader.pointAttributes; const attributes = []; - for (let j = 0; j < attr.length; j++) { - if (this.config.serverConfig.point_attributes[attr[j]] != undefined) { - attributes.push(this.config.serverConfig.point_attributes[attr[j]]); + for (const att of attr) { + if (this.config.serverConfig.point_attributes[att] != undefined) { + attributes.push(this.config.serverConfig.point_attributes[att]); } } + /** + * @type {number} + */ const scale = jHeader.scale; if (jHeader.points < 3) { @@ -422,41 +425,52 @@ export class LidarprofileManager { const byteOffset = bytesPerPoint * i; const view = new DataView(buffer, byteOffset, bytesPerPoint); let aoffset = 0; - for (let k = 0; k < attributes.length; k++) { - - if (attributes[k].value == 'POSITION_PROJECTED_PROFILE') { + for (const attribute of attributes) { + if (attribute.value == 'POSITION_PROJECTED_PROFILE') { const udist = view.getUint32(aoffset, true); const dist = udist * scale; points.distance.push(Math.round(100 * (distanceOffset + dist)) / 100); this.profilePoints.distance.push(Math.round(100 * (distanceOffset + dist)) / 100); - } else if (attributes[k].value == 'CLASSIFICATION') { + } else if (attribute.value == 'CLASSIFICATION') { const classif = view.getUint8(aoffset); points.classification.push(classif); this.profilePoints.classification.push(classif); - } else if (attributes[k].value == 'INTENSITY') { + } else if (attribute.value == 'INTENSITY') { const intensity = view.getUint8(aoffset); points.intensity.push(intensity); this.profilePoints.intensity.push(intensity); - } else if (attributes[k].value == 'COLOR_PACKED') { + } else if (attribute.value == 'COLOR_PACKED') { const r = view.getUint8(aoffset); const g = view.getUint8(aoffset + 1); const b = view.getUint8(aoffset + 2); points.color_packed.push([r, g, b]); this.profilePoints.color_packed.push([r, g, b]); - } else if (attributes[k].value == 'POSITION_CARTESIAN') { - const x = view.getInt32(aoffset, true) * scale + jHeader.boundingBox.lx; - const y = view.getInt32(aoffset + 4, true) * scale + jHeader.boundingBox.ly; - const z = view.getInt32(aoffset + 8, true) * scale + jHeader.boundingBox.lz; + } else if (attribute.value == 'POSITION_CARTESIAN') { + const lx = jHeader.boundingBox.lx; + if (typeof lx != 'number') { + throw new Error('Wrong lx type'); + } + const ly = jHeader.boundingBox.ly; + if (typeof ly != 'number') { + throw new Error('Wrong ly type'); + } + const lz = jHeader.boundingBox.lz; + if (typeof lz != 'number') { + throw new Error('Wrong lz type'); + } + const x = view.getInt32(aoffset, true) * scale + lx; + const y = view.getInt32(aoffset + 4, true) * scale + ly; + const z = view.getInt32(aoffset + 8, true) * scale + lz; points.coords.push([x, y]); points.altitude.push(z); this.profilePoints.altitude.push(z); this.profilePoints.coords.push([x, y]); } - aoffset = aoffset + attributes[k].bytes; + aoffset = aoffset + attribute.bytes; } } diff --git a/contribs/gmf/src/lidarprofile/Plot.js b/contribs/gmf/src/lidarprofile/Plot.js index d3892328a289..547cc76a17c4 100644 --- a/contribs/gmf/src/lidarprofile/Plot.js +++ b/contribs/gmf/src/lidarprofile/Plot.js @@ -42,9 +42,9 @@ export default class { /** * d3.scaleLinear X scale. - * @type {Function} + * @type {function(number): number} */ - this.updateScaleX = () => undefined; + this.updateScaleX = (x) => x; /** * d3.scaleLinear Y scale. @@ -54,9 +54,9 @@ export default class { /** * d3.scaleLinear Y scale. - * @type {Function} + * @type {function(number): number} */ - this.updateScaleY = () => undefined; + this.updateScaleY = (y) => y; /** * The material used for the drawing process. Initialized in the setup @@ -309,11 +309,11 @@ export default class { const yAxis = d3axisLeft(this.scaleY) .tickSize(-this.width_); - const new_scaleX = tr.rescaleX(this.scaleX); - const new_scaleY = tr.rescaleY(this.scaleY); + const newScaleX = tr.rescaleX(this.scaleX); + const newScaleY = tr.rescaleY(this.scaleY); - svg.select('.x.axis').call(/** @type {any} */ (xAxis.scale(new_scaleX))); - svg.select('.y.axis').call(/** @type {any} */ (yAxis.scale(new_scaleY))); + svg.select('.x.axis').call(/** @type {any} */ (xAxis.scale(newScaleX))); + svg.select('.y.axis').call(/** @type {any} */ (yAxis.scale(newScaleY))); const canvas = d3select('#gmf-lidarprofile-container .lidar-canvas'); const canvasEl = /** @type {HTMLCanvasElement} */(canvas.node()); @@ -327,8 +327,8 @@ export default class { .style('opacity', '0.5') .style('stroke', '#b7cff7'); - this.updateScaleX = new_scaleX; - this.updateScaleY = new_scaleY; + this.updateScaleX = newScaleX; + this.updateScaleY = newScaleY; } diff --git a/contribs/gmf/src/lidarprofile/Utils.js b/contribs/gmf/src/lidarprofile/Utils.js index bfa64922cd51..1f801f31cfeb 100644 --- a/contribs/gmf/src/lidarprofile/Utils.js +++ b/contribs/gmf/src/lidarprofile/Utils.js @@ -350,9 +350,9 @@ export default class { */ arrayMin(array) { let minVal = Infinity; - for (let i = 0; i < array.length; i++) { - if (array[i] < minVal) { - minVal = array[i]; + for (const element of array) { + if (element < minVal) { + minVal = element; } } return minVal; @@ -367,9 +367,9 @@ export default class { getPytreeLinestring(line) { const coords = line.getCoordinates(); let pytreeLineString = ''; - for (let i = 0; i < coords.length; i++) { - const px = coords[i][0]; - const py = coords[i][1]; + for (const coord of coords) { + const px = coord[0]; + const py = coord[1]; pytreeLineString += `{${Math.round(100 * px) / 100}, ${Math.round(100 * py) / 100}},`; } return pytreeLineString.substr(0, pytreeLineString.length - 1); diff --git a/contribs/gmf/src/permalink/Permalink.js b/contribs/gmf/src/permalink/Permalink.js index 05e8818d8614..be49b273d0bf 100644 --- a/contribs/gmf/src/permalink/Permalink.js +++ b/contribs/gmf/src/permalink/Permalink.js @@ -580,7 +580,7 @@ export function PermalinkService( } } ); - newState[ParamPrefix.TREE_GROUP_LAYERS + firstParent.node.name] = gmfLayerNames.join(','); + newState[`${ParamPrefix.TREE_GROUP_LAYERS}${firstParent.node.name}`] = gmfLayerNames.join(','); } this.ngeoStateManager_.updateState(newState); }); @@ -588,9 +588,9 @@ export function PermalinkService( /** @type {Object} */ const newState = {}; const opacity = treeCtrl.layer.getOpacity(); - const stateName = (treeCtrl.parent.node.mixed ? + const stateName = `${(treeCtrl.parent.node.mixed ? ParamPrefix.TREE_OPACITY : ParamPrefix.TREE_GROUP_OPACITY - ) + treeCtrl.node.name; + )}${treeCtrl.node.name}`; newState[stateName] = opacity; this.ngeoStateManager_.updateState(newState); }); @@ -847,8 +847,7 @@ PermalinkService.prototype.getFeatures = function() { PermalinkService.prototype.setDimensions = function(dimensions) { // apply initial state const keys = this.ngeoLocation_.getParamKeysWithPrefix(ParamPrefix.DIMENSIONS); - for (let i = 0; i < keys.length; i++) { - const key = keys[i]; + for (const key of keys) { const value = this.ngeoLocation_.getParam(key); if (!value) { throw new Error('Missing value'); @@ -1439,7 +1438,7 @@ PermalinkService.prototype.getWfsPermalinkData_ = function() { // filter groups are used, e.g. '?wfs_layer=osm_scale&wfs_ngroups=2&wfs_0_ele=380& // wfs_0_highway=bus_stop&&wfs_1_name=Grand-Pont' for (let i = 0; i < numGroups; i++) { - filterGroup = this.createFilterGroup_(`${ParamPrefix.WFS + i}_`, paramKeys); + filterGroup = this.createFilterGroup_(`${ParamPrefix.WFS}${i}_`, paramKeys); if (filterGroup !== null) { filterGroups.push(filterGroup); } @@ -1476,7 +1475,7 @@ PermalinkService.prototype.createFilterGroup_ = function(prefix, paramKeys) { paramKeys.forEach((paramKey) => { if (paramKey == PermalinkParam.WFS_LAYER || paramKey == PermalinkParam.WFS_SHOW_FEATURES || - paramKey == PermalinkParam.WFS_NGROUPS || paramKey.indexOf(prefix) != 0) { + paramKey == PermalinkParam.WFS_NGROUPS || !paramKey.startsWith(prefix)) { return; } const value = this.ngeoLocation_.getParam(paramKey); diff --git a/contribs/gmf/src/print/component.js b/contribs/gmf/src/print/component.js index 63c1ea4e2736..074a3f2eb3b6 100644 --- a/contribs/gmf/src/print/component.js +++ b/contribs/gmf/src/print/component.js @@ -778,7 +778,7 @@ export class PrintController { this.updateCustomFields_(); - const hasLegend = this.layoutInfo.attributes.indexOf('legend') >= 0; + const hasLegend = this.layoutInfo.attributes.includes('legend'); if (hasLegend) { this.fieldValues.legend = this.fieldValues.legend; } else { @@ -997,7 +997,7 @@ export class PrintController { /** @type {Object} */ const customAttributes = {}; - if (this.layoutInfo.attributes.indexOf('datasource') >= 0) { + if (this.layoutInfo.attributes.includes('datasource')) { customAttributes.datasource = datasource; } diff --git a/contribs/gmf/src/profile/component.js b/contribs/gmf/src/profile/component.js index c51a5ec77800..4e8560f0e011 100644 --- a/contribs/gmf/src/profile/component.js +++ b/contribs/gmf/src/profile/component.js @@ -546,10 +546,10 @@ ProfileController.prototype.getTooltipHTML_ = function() { innerHTML.push(`${this.profileLabels_.xAxis} ${separator} ${value} ${this.currentPoint.xUnits}`); for (elevationName in this.currentPoint.elevations) { translatedElevationName = gettextCatalog.getString(elevationName); - const int_value = this.currentPoint.elevations[elevationName]; - const value = int_value === null ? + const intValue = this.currentPoint.elevations[elevationName]; + const value = intValue === null ? gettextCatalog.getString('no value') : - `${number(int_value, 0)} ${this.currentPoint.yUnits}`; + `${number(intValue, 0)} ${this.currentPoint.yUnits}`; innerHTML.push(`${translatedElevationName} ${separator} ${value}`); } return innerHTML.join('
'); diff --git a/contribs/gmf/src/query/gridComponent.js b/contribs/gmf/src/query/gridComponent.js index 06bcc3af3252..6ed2e70c759a 100644 --- a/contribs/gmf/src/query/gridComponent.js +++ b/contribs/gmf/src/query/gridComponent.js @@ -615,7 +615,7 @@ QueryGridController.prototype.collectData_ = function(source) { if (properties !== undefined) { // Keeps distinct geometry names to remove theme later. featureGeometryName = feature.getGeometryName(); - if (featureGeometriesNames.indexOf(featureGeometryName) === -1) { + if (!featureGeometriesNames.includes(featureGeometryName)) { featureGeometriesNames.push(featureGeometryName); } @@ -678,7 +678,7 @@ QueryGridController.prototype.removeEmptyColumnsFn_ = function(allProperties) { allProperties.forEach((properties) => { keyToRemove = []; for (key in properties) { - if (keysToKeep.indexOf(key) === -1) { + if (!keysToKeep.includes(key)) { keyToRemove.push(key); } } @@ -705,7 +705,7 @@ QueryGridController.prototype.makeGrid_ = function(data, source) { return false; } } - if (this.loadedGridSources.indexOf(sourceLabel) == -1) { + if (!this.loadedGridSources.includes(sourceLabel)) { this.loadedGridSources.push(sourceLabel); } this.gridSources[sourceLabel] = { diff --git a/contribs/gmf/src/query/windowComponent.js b/contribs/gmf/src/query/windowComponent.js index 39a1364cc3b5..415e7973bc60 100644 --- a/contribs/gmf/src/query/windowComponent.js +++ b/contribs/gmf/src/query/windowComponent.js @@ -442,8 +442,7 @@ QueryWindowController.prototype.next = function() { QueryWindowController.prototype.updateQueryResult_ = function(queryResult) { this.ngeoQueryResult.total = 0; this.ngeoQueryResult.sources.length = 0; - for (let i = 0; i < queryResult.sources.length; i++) { - const source = queryResult.sources[i]; + for (const source of queryResult.sources) { source.features = source.features.filter((feature) => { console.assert(feature); return !isEmpty(getFilteredFeatureValues(feature)); @@ -518,15 +517,14 @@ QueryWindowController.prototype.animate_ = function(isNext) { QueryWindowController.prototype.collectFeatures_ = function() { const sources = this.ngeoQueryResult.sources; this.features_.clear(); - for (let i = 0; i < sources.length; i++) { - const source = sources[i]; + for (const source of sources) { if (this.selectedSource !== null && this.selectedSource !== source) { // when filtering on a source, only add features of the selected source continue; } const features = source.features; - for (let ii = 0; ii < features.length; ii++) { - this.features_.push(features[ii]); + for (const feature of features) { + this.features_.push(feature); } } }; diff --git a/contribs/gmf/src/raster/component.js b/contribs/gmf/src/raster/component.js index 6bf25d89acc5..ae1f8e69b842 100644 --- a/contribs/gmf/src/raster/component.js +++ b/contribs/gmf/src/raster/component.js @@ -109,6 +109,7 @@ function rasterComponent() { 'layer': ' { // @ts-ignore: scope... const ctrl = scope.ctrl; @@ -234,6 +235,7 @@ Controller.prototype.toggleActive_ = function(active) { * @param {Event|import("ol/events/Event.js").default} event The event * @return {void} */ + // @ts-ignore const listen = (event) => { this.scope_.$apply(() => { this.inViewport_ = true; @@ -295,7 +297,11 @@ Controller.prototype.getRasterSuccess_ = function(resp) { const separator = postfix.length > 0 ? (options.hasOwnProperty('separator') ? options.separator : '\u00a0') : ''; const args = Array.prototype.concat([value], custom_args); - this.elevation = this.filter_(filter)(...args) + separator + postfix; + const elevation = this.filter_(filter)(...args); + if (typeof elevation != 'string') { + throw new Error('Wrong elevation type'); + } + this.elevation = elevation + separator + postfix; } else { const gettextCatalog = this.gettextCatalog; this.elevation = gettextCatalog.getString('No value'); diff --git a/contribs/gmf/src/search/component.js b/contribs/gmf/src/search/component.js index 4e5be6a6bae8..7646e353f780 100644 --- a/contribs/gmf/src/search/component.js +++ b/contribs/gmf/src/search/component.js @@ -573,9 +573,7 @@ class SearchController { throw new Error('Missing map'); } const gettextCatalog = this.gettextCatalog_; - for (let i = 0; i < this.datasources.length; i++) { - const datasource = this.datasources[i]; - + for (const datasource of this.datasources) { /** @type {string[]} */ const groupValues = datasource.groupValues !== undefined ? datasource.groupValues : []; /** @type {gmfSearchAction[]} */ diff --git a/contribs/gmf/src/theme/Themes.js b/contribs/gmf/src/theme/Themes.js index faf451d876e8..9aa418cb33c6 100644 --- a/contribs/gmf/src/theme/Themes.js +++ b/contribs/gmf/src/theme/Themes.js @@ -518,8 +518,8 @@ function getFlatInternalNodes(node, nodes) { const children = node.children; if (children !== undefined) { nodes.push(node); - for (let i = 0; i < children.length; i++) { - getFlatInternalNodes(children[i], nodes); + for (const child of children) { + getFlatInternalNodes(child, nodes); } } } @@ -536,8 +536,8 @@ export function getFlatNodes(node, nodes) { // @ts-ignore: children only on GmfGroup const children = node.children; if (children !== undefined) { - for (let i = 0; i < children.length; i++) { - getFlatNodes(children[i], nodes); + for (const child of children) { + getFlatNodes(child, nodes); } } else { nodes.push(node); diff --git a/examples/animation.js b/examples/animation.js index de7cc2d2ec62..80b390602423 100644 --- a/examples/animation.js +++ b/examples/animation.js @@ -69,9 +69,8 @@ function MainController($timeout) { // But we need to do it asynchronously in order to have the `resizemap` // directive working. If we don't, the `ng-class` directive doesn't fire the // animation hooks. - const self = this; $timeout(() => { - self.open = true; + this.open = true; }, 0); } diff --git a/examples/layerorder.js b/examples/layerorder.js index d2dd0e7ff962..83ce940b0185 100644 --- a/examples/layerorder.js +++ b/examples/layerorder.js @@ -144,7 +144,7 @@ function MainController($scope) { */ MainController.prototype.toggleRoadsLayer = function(val) { if (val === undefined) { - return this.map.getLayers().getArray().indexOf(this.roads_) >= 0; + return this.map.getLayers().getArray().includes(this.roads_); } else { if (val) { this.map.addLayer(this.roads_); diff --git a/examples/mapfishprint.js b/examples/mapfishprint.js index cf6eb20fe0a6..c9513ff6ca9d 100644 --- a/examples/mapfishprint.js +++ b/examples/mapfishprint.js @@ -237,9 +237,8 @@ MainController.prototype.handleGetStatusSuccess_ = function(ref, resp) { window.location.href = this.print_.getReportUrl(ref); } else { // The report is not ready yet. Check again in 1s. - const that = this; this.$timeout_(() => { - that.getStatus_(ref); + this.getStatus_(ref); }, 1000, false); } }; diff --git a/src/WFSDescribeFeatureType.js b/src/WFSDescribeFeatureType.js index 92087c0adf60..43de34052e3c 100644 --- a/src/WFSDescribeFeatureType.js +++ b/src/WFSDescribeFeatureType.js @@ -102,9 +102,6 @@ const SEQUENCE_PARSERS_ = makeStructureNS( * @hidden */ class WFSDescribeFeatureType extends olFormatXML { - constructor() { - super(); - } } diff --git a/src/download/Csv.js b/src/download/Csv.js index d2f37a50473e..61aae38f661a 100644 --- a/src/download/Csv.js +++ b/src/download/Csv.js @@ -118,7 +118,7 @@ DownloadCsvService.prototype.getRow_ = function(values) { if (value !== undefined && value !== null) { value = `${value}`; // wrap each value into quotes and escape quotes with double quotes - return this.quote_ + value.replace(matchAllQuotesRegex, doubleQuote) + this.quote_; + return `${this.quote_}${value.replace(matchAllQuotesRegex, doubleQuote)}${this.quote_}`; } else { return ''; } diff --git a/src/format/FeatureHash.js b/src/format/FeatureHash.js index 5355993b720e..67d8e4120a5e 100644 --- a/src/format/FeatureHash.js +++ b/src/format/FeatureHash.js @@ -273,7 +273,7 @@ class FeatureHash extends olFormatTextFeature { readFeatureFromText(text, opt_options) { console.assert(text.length > 2); console.assert(text[1] === '('); - console.assert(text[text.length - 1] === ')'); + console.assert(text.endsWith(')')); let splitIndex = text.indexOf('~'); const geometryText = splitIndex >= 0 ? `${text.substring(0, splitIndex)})` : text; @@ -288,8 +288,8 @@ class FeatureHash extends olFormatTextFeature { attributesAndStylesText; if (attributesText != '') { const parts = attributesText.split('\''); - for (let i = 0; i < parts.length; ++i) { - const part = decodeURIComponent(parts[i]); + for (const encodedPart of parts) { + const part = decodeURIComponent(encodedPart); const keyVal = part.split('*'); console.assert(keyVal.length === 2); let key = keyVal[0]; @@ -321,7 +321,7 @@ class FeatureHash extends olFormatTextFeature { * @override */ readFeaturesFromText(text, opt_options) { - console.assert(text[0] === 'F'); + console.assert(text.startsWith('F')); this.prevX_ = 0; this.prevY_ = 0; /** @type {Array>} */ @@ -383,7 +383,7 @@ class FeatureHash extends olFormatTextFeature { if (encodedGeometry.length > 0) { // remove the final bracket - console.assert(encodedGeometry[encodedGeometry.length - 1] === ')'); + console.assert(encodedGeometry.endsWith(')')); encodedGeometry = encodedGeometry.substring(0, encodedGeometry.length - 1); encodedParts.push(encodedGeometry); } @@ -542,8 +542,7 @@ function encodeNumber_(num) { function encodeStyles_(styles, geometryType, encodedStyles) { const styleType = StyleTypes_[geometryType]; console.assert(styleType !== undefined); - for (let i = 0; i < styles.length; ++i) { - const style = styles[i]; + for (const style of styles) { const fillStyle = style.getFill(); const imageStyle = style.getImage(); const strokeStyle = style.getStroke(); @@ -715,8 +714,8 @@ function encodeStyleText_(textStyle, encodedStyles) { * @this {FeatureHash} */ function readLineStringGeometry_(text) { - console.assert(text.substring(0, 2) === 'l('); - console.assert(text[text.length - 1] == ')'); + console.assert(text.startsWith('l(')); + console.assert(text.endsWith(')')); text = text.substring(2, text.length - 1); const flatCoordinates = this.decodeCoordinates_(text); return new olGeomLineString(flatCoordinates, olGeomGeometryLayout.XY); @@ -732,8 +731,8 @@ function readLineStringGeometry_(text) { * @this {FeatureHash} */ function readMultiLineStringGeometry_(text) { - console.assert(text.substring(0, 2) === 'L('); - console.assert(text[text.length - 1] == ')'); + console.assert(text.startsWith('L(')); + console.assert(text.endsWith(')')); text = text.substring(2, text.length - 1); /** @type {number[]} */ let flatCoordinates = []; @@ -756,8 +755,8 @@ function readMultiLineStringGeometry_(text) { * @this {FeatureHash} */ function readPointGeometry_(text) { - console.assert(text.substring(0, 2) === 'p('); - console.assert(text[text.length - 1] == ')'); + console.assert(text.startsWith('p(')); + console.assert(text.endsWith(')')); text = text.substring(2, text.length - 1); const flatCoordinates = this.decodeCoordinates_(text); console.assert(flatCoordinates.length === 2); @@ -774,8 +773,8 @@ function readPointGeometry_(text) { * @this {FeatureHash} */ function readMultiPointGeometry_(text) { - console.assert(text.substring(0, 2) === 'P('); - console.assert(text[text.length - 1] == ')'); + console.assert(text.startsWith('P(')); + console.assert(text.endsWith(')')); text = text.substring(2, text.length - 1); const flatCoordinates = this.decodeCoordinates_(text); return new olGeomMultiPoint(flatCoordinates, olGeomGeometryLayout.XY); @@ -791,8 +790,8 @@ function readMultiPointGeometry_(text) { * @this {FeatureHash} */ function readPolygonGeometry_(text) { - console.assert(text.substring(0, 2) === 'a('); - console.assert(text[text.length - 1] == ')'); + console.assert(text.startsWith('a(')); + console.assert(text.endsWith(')')); text = text.substring(2, text.length - 1); /** @type {number[]} */ let flatCoordinates = []; @@ -823,8 +822,8 @@ function readPolygonGeometry_(text) { * @this {FeatureHash} */ function readMultiPolygonGeometry_(text) { - console.assert(text.substring(0, 2) === 'A('); - console.assert(text[text.length - 1] == ')'); + console.assert(text.startsWith('A(')); + console.assert(text.endsWith(')')); text = text.substring(2, text.length - 1); /** @type {number[]} */ let flatCoordinates = []; @@ -974,7 +973,7 @@ function setStyleProperties_(text, feature) { throw new Error('Wrong fontSizeStr type'); } let fontSize = parseFloat(fontSizeStr); - if (fontSizeStr.indexOf('px') !== -1) { + if (fontSizeStr.includes('px')) { fontSize = Math.round(fontSize / 1.333333); } properties.fontSize = fontSize; @@ -1051,8 +1050,8 @@ function getStyleProperties_(text, feature) { /** @type {Object} */ const properties = {}; - for (let i = 0; i < parts.length; ++i) { - const part = decodeURIComponent(parts[i]); + for (const encodedPart of parts) { + const part = decodeURIComponent(encodedPart); const keyVal = part.split('*'); console.assert(keyVal.length === 2); const key = keyVal[0]; diff --git a/src/format/XSDAttribute.js b/src/format/XSDAttribute.js index 63f9ddced5ef..6a562030b19f 100644 --- a/src/format/XSDAttribute.js +++ b/src/format/XSDAttribute.js @@ -25,10 +25,6 @@ export const FormatNumberType = { * @hidden */ class XSDAttribute extends olFormatXML { - constructor() { - super(); - } - /** * @param {Document|Element|string} source Source. * @return {Array} The parsed result. diff --git a/src/grid/component.js b/src/grid/component.js index d42033831d42..3b5b4acd8799 100644 --- a/src/grid/component.js +++ b/src/grid/component.js @@ -256,8 +256,8 @@ GridController.prototype.selectRange_ = function(attributes) { // find the selected row which is the closest to the clicked row let distance = Infinity; let posClosestRow = posSelectedRows[0]; - for (let j = 0; j < posSelectedRows.length; j++) { - const currentPos = posSelectedRows[j]; + for (const posSelectedRow of posSelectedRows) { + const currentPos = posSelectedRow; const currentDistance = Math.abs(currentPos - posClickedRow); if (distance > currentDistance) { distance = currentDistance; diff --git a/src/interaction/ModifyRectangle.js b/src/interaction/ModifyRectangle.js index efc48b1a1cfc..24a5d1e82c86 100644 --- a/src/interaction/ModifyRectangle.js +++ b/src/interaction/ModifyRectangle.js @@ -263,9 +263,9 @@ class ModifyRectangle extends olInteractionPointer { const uid = olUtilGetUid(feature); const item = this.cache_[uid]; const corners = item.corners; - for (let i = 0; i < corners.length; i++) { + for (const corner of corners) { /** @type {olSourceVector} */(this.vectorPoints_.getSource()) - .removeFeature(corners[i]); + .removeFeature(corner); } this.feature_ = null; corners.length = 0; diff --git a/src/layertree/Controller.js b/src/layertree/Controller.js index 4817870db915..54985b8f13ea 100644 --- a/src/layertree/Controller.js +++ b/src/layertree/Controller.js @@ -327,7 +327,7 @@ LayertreeController.prototype.getSetActive = function(val) { map.addLayer(layer); } } else { - return map.getLayers().getArray().indexOf(layer) >= 0; + return map.getLayers().getArray().includes(layer); } }; @@ -397,8 +397,7 @@ LayertreeController.prototype.traverseDepthFirst = function(visitor) { case LayertreeVisitorDecision.SKIP: return false; // continue traversing but skip current branch case LayertreeVisitorDecision.DESCEND: - for (let i = 0; i < this.children.length; ++i) { - const child = this.children[i]; + for (const child of this.children) { const stop = child.traverseDepthFirst(visitor); if (stop) { return true; // stop traversing diff --git a/src/map/LayerHelper.js b/src/map/LayerHelper.js index 87113615130a..d442debc3157 100644 --- a/src/map/LayerHelper.js +++ b/src/map/LayerHelper.js @@ -333,7 +333,7 @@ LayerHelper.prototype.getFlatLayers_ = function(layer, array, computedOpacity) { this.getFlatLayers_(l, array, computedOpacity); }); } else if (layer instanceof olLayerLayer) { - if (array.indexOf(layer) < 0) { + if (!array.includes(layer)) { layer.set('inheritedOpacity', computedOpacity, true); array.push(layer); } diff --git a/src/message/Message.js b/src/message/Message.js index bb2716c4034f..c12925b75e3f 100644 --- a/src/message/Message.js +++ b/src/message/Message.js @@ -43,8 +43,6 @@ export const MessageType = { * @hidden */ export default class { - constructor() {} - /** * Show the message. * diff --git a/src/misc/File.js b/src/misc/File.js index 8f8d02dbaece..ea20d99cdf7c 100644 --- a/src/misc/File.js +++ b/src/misc/File.js @@ -29,21 +29,21 @@ export function FileService($q, $http, gettext) { * @param {string} fileContent */ this.isWmtsGetCap = function(fileContent) { - return //.test(fileContent); + return fileContent.includes(''); }; /** * @param {string} fileContent */ this.isGpx = function(fileContent) { - return //.test(fileContent); + return fileContent.includes(''); }; /** @type {?FileReader} */ diff --git a/src/misc/ToolActivateMgr.js b/src/misc/ToolActivateMgr.js index 684a9aa99856..774d17e30628 100644 --- a/src/misc/ToolActivateMgr.js +++ b/src/misc/ToolActivateMgr.js @@ -116,8 +116,8 @@ ToolActivateMgr.prototype.unregisterTool = function(groupName, tool) { ToolActivateMgr.prototype.unregisterGroup = function(groupName) { const entries = this.groups_[groupName]; if (entries) { - for (let i = 0; i < entries.length; i++) { - entries[i].unlisten(); + for (const entry of entries) { + entry.unlisten(); } delete this.groups_[groupName]; } @@ -151,9 +151,9 @@ ToolActivateMgr.prototype.deactivateTool = function(tool) { */ ToolActivateMgr.prototype.deactivateTools_ = function(groupName, tool) { const entries = this.groups_[groupName]; - for (let i = 0; i < entries.length; i++) { - if (tool != entries[i].tool) { - entries[i].tool.setActive(false); + for (const entry of entries) { + if (tool != entry.tool) { + entry.tool.setActive(false); } } }; @@ -170,11 +170,11 @@ ToolActivateMgr.prototype.activateDefault_ = function(groupName) { let defaultTool = null; let hasActiveTool = false; - for (let i = 0; i < entries.length; i++) { - hasActiveTool = hasActiveTool || entries[i].tool.getActive(); + for (const entry of entries) { + hasActiveTool = hasActiveTool || entry.tool.getActive(); - if (entries[i].defaultTool) { - defaultTool = entries[i].tool; + if (entry.defaultTool) { + defaultTool = entry.tool; } } diff --git a/src/misc/debounce.js b/src/misc/debounce.js index d16c8aeb1b3f..5ca7cfc4395a 100644 --- a/src/misc/debounce.js +++ b/src/misc/debounce.js @@ -34,10 +34,9 @@ export function debounce(func, wait, invokeApply, $timeout) { * @this {any} The context */ function(...args) { - const context = this; - const later = function() { + const later = () => { timeout = null; - func.apply(context, args); + func.apply(this, args); }; if (timeout !== null) { $timeout.cancel(timeout); diff --git a/src/misc/filters.js b/src/misc/filters.js index 0acf3b0d9cdf..0dca6a63aed1 100644 --- a/src/misc/filters.js +++ b/src/misc/filters.js @@ -163,7 +163,7 @@ function NumberFilter($locale) { str_number = `0${str_number}`; } decimal = str_number.substring(str_number.length - nb_decimal); - while (decimal[decimal.length - 1] === '0') { + while (decimal.endsWith('0')) { decimal = decimal.substring(0, decimal.length - 1); } } @@ -209,6 +209,7 @@ module.filter('ngeoNumber', NumberFilter); * @ngname ngeoUnitPrefix */ function UnitPrefixFilter($filter) { + /** @type {function(number, number=): string} */ const numberFilter = $filter('ngeoNumber'); const standardPrefix = ['', 'k', 'M', 'G', 'T', 'P']; const binaryPrefix = ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi']; diff --git a/src/misc/php-date-formatter.js b/src/misc/php-date-formatter.js index 5869463e30c7..c4770cb8954b 100644 --- a/src/misc/php-date-formatter.js +++ b/src/misc/php-date-formatter.js @@ -23,6 +23,8 @@ /* eslint default-case: 0 */ /* eslint prefer-rest-params: 0 */ /* eslint prefer-template: 0 */ +/* eslint @typescript-eslint/no-this-alias: 0 */ +/* eslint @typescript-eslint/restrict-plus-operands: 0 */ "use strict"; @@ -161,6 +163,12 @@ export default class DateFormatter { } return i; } + /** + * + * @param {Date|string|number} vDate + * @param {?string} vFormat + * @returns {?Date} + */ parseDate(vDate, vFormat) { // @ts-ignore: not checked file const self = this, vSettings = self.dateSettings, @@ -237,8 +245,8 @@ export default class DateFormatter { break; case 'g': case 'h': - const vMeriIndex = (vFormatParts.indexOf('a') > -1) ? vFormatParts.indexOf('a') : - (vFormatParts.indexOf('A') > -1) ? vFormatParts.indexOf('A') : -1; + const vMeriIndex = (vFormatParts.includes('a')) ? vFormatParts.indexOf('a') : + (vFormatParts.includes('A')) ? vFormatParts.indexOf('A') : -1; const mer = vDateParts[vMeriIndex]; if (vMeriIndex !== -1) { const vMeriOffset = _compare(mer, vSettings.meridiem[0]) ? 0 : diff --git a/src/offline/Configuration.js b/src/offline/Configuration.js index bfab27aafde9..4c403af3a552 100644 --- a/src/offline/Configuration.js +++ b/src/offline/Configuration.js @@ -22,7 +22,7 @@ import localforage from 'localforage/src/localforage.js'; /** * @implements {ngeox.OfflineOnTileDownload} */ -const exports = class extends olObservable { +export default class extends olObservable { /** * @ngInject @@ -334,14 +334,13 @@ const exports = class extends olObservable { * @return {function(import("ol/ImageTile.js").default, string)} the tile function */ createTileLoadFunction_(offlineLayer) { - const that = this; /** * Load the tile from persistent storage. * @param {import("ol/ImageTile.js").default} imageTile The image tile * @param {string} src The tile URL */ - const tileLoadFunction = function(imageTile, src) { - that.getItem(normalizeURL(src)).then((content) => { + const tileLoadFunction = (imageTile, src) => { + this.getItem(normalizeURL(src)).then((content) => { if (!content) { // use a transparent 1x1 image to make the map consistent /* eslint-disable-next-line */ @@ -375,7 +374,4 @@ const exports = class extends olObservable { getMaxNumberOfParallelDownloads() { return 11; } -}; - - -export default exports; +} diff --git a/src/offline/Downloader.js b/src/offline/Downloader.js index 1a5574d4e7db..79dfbf7c0cc0 100644 --- a/src/offline/Downloader.js +++ b/src/offline/Downloader.js @@ -13,7 +13,7 @@ import angular from 'angular'; function magnitude2(a, b) { let magnitudeSquared = 0; for (let i = 0; i < a.length; ++i) { - magnitudeSquared += Math.pow(a[1] - b[1], 2); + magnitudeSquared += Math.pow(a[i] - b[i], 2); } return magnitudeSquared; } @@ -77,7 +77,15 @@ const Downloader = class { /** * @type {number} */ - let minY, maxX, maxY; + let minY; + /** + * @type {number} + */ + let maxX; + /** + * @type {number} + */ + let maxY; tileGrid.forEachTileCoord(extent, z, (coord) => { maxX = coord[1]; maxY = coord[2]; @@ -145,7 +153,7 @@ const Downloader = class { layerItem.extentByZoom.forEach(obj => { const zoom = obj.zoom; - if (zooms.indexOf(zoom) < 0) { + if (!zooms.includes(zoom)) { zooms.push(zoom); } }); diff --git a/src/print/Utils.js b/src/print/Utils.js index 454f35863b63..3f1ae91620fb 100644 --- a/src/print/Utils.js +++ b/src/print/Utils.js @@ -54,13 +54,11 @@ export const DOTS_PER_INCH = 72; * listener. */ PrintUtils.prototype.createPrintMaskPostcompose = function(getSize, getScale, opt_rotation) { - const self = this; - return ( /** * @param {Event|import('ol/events/Event.js').default} evt Postcompose event. */ - function(evt) { + (evt) => { if (evt instanceof RenderEvent && evt.context && evt.frameState) { const context = evt.context; const frameState = evt.frameState; @@ -81,10 +79,10 @@ PrintUtils.prototype.createPrintMaskPostcompose = function(getSize, getScale, op const ipm = INCHES_PER_METER; const extentHalfWidth = (((width / ppi) / ipm) * scale / resolution) / 2; - self.extentHalfHorizontalDistance_ = (((size[0] / ppi) / ipm) * scale) / 2; + this.extentHalfHorizontalDistance_ = (((size[0] / ppi) / ipm) * scale) / 2; const extentHalfHeight = (((height / ppi) / ipm) * scale / resolution) / 2; - self.extentHalfVerticalDistance_ = (((size[1] / ppi) / ipm) * scale) / 2; + this.extentHalfVerticalDistance_ = (((size[1] / ppi) / ipm) * scale) / 2; // Draw a mask on the whole map. context.beginPath(); @@ -97,11 +95,11 @@ PrintUtils.prototype.createPrintMaskPostcompose = function(getSize, getScale, op // Draw the print zone if (!opt_rotation) { - self.drawPrintZone_(context, center, extentHalfWidth, + this.drawPrintZone_(context, center, extentHalfWidth, extentHalfHeight); } else { const rotation = toRadians(opt_rotation()); - self.drawPrintZoneWithRotation_(context, center, extentHalfWidth, + this.drawPrintZoneWithRotation_(context, center, extentHalfWidth, extentHalfHeight, rotation); } diff --git a/src/profile/d3Elevation.js b/src/profile/d3Elevation.js index 06445c024e3d..b153aa0c41b4 100644 --- a/src/profile/d3Elevation.js +++ b/src/profile/d3Elevation.js @@ -657,7 +657,7 @@ function d3Elevation(options) { /** * @param {void} d */ - d => pe.sort(d) + (light ? '' : (` - ${pe.title(d)}`)) + d => `${pe.sort(d)}${(light ? '' : (` - ${pe.title(d)}`))}` ); poiEnterG.selectAll('line') diff --git a/src/statemanager/Location.js b/src/statemanager/Location.js index 29b0c1019bb8..d4fd4d3609e2 100644 --- a/src/statemanager/Location.js +++ b/src/statemanager/Location.js @@ -112,7 +112,7 @@ StatemanagerLocation.prototype.getUriString = function() { } if (this.path_) { - if (this.domain_ && this.path_.charAt(0) !== '/') { + if (this.domain_ && !this.path_.startsWith('/')) { out.push('/'); } out.push(this.path_); @@ -258,7 +258,7 @@ StatemanagerLocation.prototype.getFragmentParamKeys = function() { StatemanagerLocation.prototype.getParamKeysWithPrefix = function(prefix) { const keys = []; for (const key in this.queryData_) { - if (key.indexOf(prefix) == 0) { + if (key.startsWith(prefix)) { keys.push(key); } } @@ -275,7 +275,7 @@ StatemanagerLocation.prototype.getParamKeysWithPrefix = function(prefix) { StatemanagerLocation.prototype.getFragmentParamKeysWithPrefix = function(prefix) { const keys = []; for (const key in this.fragment_) { - if (key.indexOf(prefix) == 0) { + if (key.startsWith(prefix)) { keys.push(key); } } diff --git a/src/utils.js b/src/utils.js index af9978fb75dc..7f21ed69f54b 100644 --- a/src/utils.js +++ b/src/utils.js @@ -17,7 +17,7 @@ export function getBrowserLanguage(availableLanguages) { browserLanguages = browserLanguages.map(item => item.substring(0, 2)); // remove duplicated language codes browserLanguages = browserLanguages.filter((item, index, arr) => arr.indexOf(item) == index); - const supportedLanguages = browserLanguages.filter(item => availableLanguages.indexOf(item) != -1); + const supportedLanguages = browserLanguages.filter(item => availableLanguages.includes(item)); return supportedLanguages[0]; } @@ -56,7 +56,7 @@ export function toMulti(geometry) { * @hidden */ export function isSafari() { - return navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Chrome') == -1; + return navigator.userAgent.includes('Safari') && !navigator.userAgent.includes('Chrome'); } /** diff --git a/test/spec/ol-ext/format/featurehash.spec.js b/test/spec/ol-ext/format/featurehash.spec.js index 1d51ff9fe8c4..e364f96b70cd 100644 --- a/test/spec/ol-ext/format/featurehash.spec.js +++ b/test/spec/ol-ext/format/featurehash.spec.js @@ -505,7 +505,7 @@ describe('ngeo.format.FeatureHash', () => { fhFormat = new ngeoFormatFeatureHash({ accuracy: 1, properties(feature) { - return {foobar: feature.get('foo') + feature.get('bar')}; + return {foobar: `${feature.get('foo')}${feature.get('bar')}`}; } }); const feature = new olFeature(new olGeomPoint([1, 1]));