From 4c5ca75ca6f852cdd04ad1eadeebf97681e02b13 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Wed, 17 Jan 2018 09:05:39 +0100 Subject: [PATCH] Better variables scoping --- src/ol/Object.js | 3 +- src/ol/PluggableMap.js | 10 ++--- src/ol/color.js | 3 +- src/ol/format/TopoJSON.js | 13 +++---- src/ol/geom/Circle.js | 11 ++---- src/ol/geom/Point.js | 6 +-- src/ol/geom/Polygon.js | 14 +++---- src/ol/geom/flat/area.js | 9 ++--- src/ol/geom/flat/interpolate.js | 9 ++--- src/ol/geom/flat/orient.js | 12 ++---- src/ol/geom/flat/transform.js | 8 ++-- src/ol/interaction/Snap.js | 58 +++++++++++++--------------- src/ol/render/canvas/ReplayGroup.js | 3 +- src/ol/render/webgl/PolygonReplay.js | 16 +++----- src/ol/render/webgl/TextReplay.js | 15 +++---- src/ol/renderer/Map.js | 6 +-- src/ol/renderer/webgl/TileLayer.js | 7 ++-- src/ol/source/Vector.js | 22 +++++------ src/ol/source/Zoomify.js | 3 +- src/ol/style/IconImageCache.js | 5 +-- src/ol/webgl/Context.js | 7 ++-- 21 files changed, 93 insertions(+), 147 deletions(-) diff --git a/src/ol/Object.js b/src/ol/Object.js index 4d07db7b78..5e664fb51f 100644 --- a/src/ol/Object.js +++ b/src/ol/Object.js @@ -169,8 +169,7 @@ BaseObject.prototype.set = function(key, value, opt_silent) { * @api */ BaseObject.prototype.setProperties = function(values, opt_silent) { - let key; - for (key in values) { + for (const key in values) { this.set(key, values[key], opt_silent); } }; diff --git a/src/ol/PluggableMap.js b/src/ol/PluggableMap.js index 187d1b1fdf..564dabeff1 100644 --- a/src/ol/PluggableMap.js +++ b/src/ol/PluggableMap.js @@ -916,9 +916,8 @@ PluggableMap.prototype.handleMapBrowserEvent = function(mapBrowserEvent) { this.focus_ = mapBrowserEvent.coordinate; mapBrowserEvent.frameState = this.frameState_; const interactionsArray = this.getInteractions().getArray(); - let i; if (this.dispatchEvent(mapBrowserEvent) !== false) { - for (i = interactionsArray.length - 1; i >= 0; i--) { + for (let i = interactionsArray.length - 1; i >= 0; i--) { const interaction = interactionsArray[i]; if (!interaction.getActive()) { continue; @@ -970,8 +969,7 @@ PluggableMap.prototype.handlePostRender = function() { } const postRenderFunctions = this.postRenderFunctions_; - let i, ii; - for (i = 0, ii = postRenderFunctions.length; i < ii; ++i) { + for (let i = 0, ii = postRenderFunctions.length; i < ii; ++i) { postRenderFunctions[i](this, frameState); } postRenderFunctions.length = 0; @@ -1191,7 +1189,7 @@ PluggableMap.prototype.removeOverlay = function(overlay) { * @private */ PluggableMap.prototype.renderFrame_ = function(time) { - let i, ii, viewState; + let viewState; const size = this.getSize(); const view = this.getView(); @@ -1203,7 +1201,7 @@ PluggableMap.prototype.renderFrame_ = function(time) { const viewHints = view.getHints(this.frameState_ ? this.frameState_.viewHints : undefined); const layerStatesArray = this.getLayerGroup().getLayerStatesArray(); const layerStates = {}; - for (i = 0, ii = layerStatesArray.length; i < ii; ++i) { + for (let i = 0, ii = layerStatesArray.length; i < ii; ++i) { layerStates[getUid(layerStatesArray[i].layer)] = layerStatesArray[i]; } viewState = view.getState(); diff --git a/src/ol/color.js b/src/ol/color.js index 2a5cf1f6f6..b4af534557 100644 --- a/src/ol/color.js +++ b/src/ol/color.js @@ -91,8 +91,7 @@ export const fromString = ( } else { if (cacheSize >= MAX_CACHE_SIZE) { let i = 0; - let key; - for (key in cache) { + for (const key in cache) { if ((i++ & 3) === 0) { delete cache[key]; --cacheSize; diff --git a/src/ol/format/TopoJSON.js b/src/ol/format/TopoJSON.js index 5e07f9e591..35a9cf83a7 100644 --- a/src/ol/format/TopoJSON.js +++ b/src/ol/format/TopoJSON.js @@ -312,8 +312,8 @@ TopoJSON.prototype.readFeaturesFromObject = function( const features = []; const topoJSONFeatures = topoJSONTopology.objects; const property = this.layerName_; - let objectName, feature; - for (objectName in topoJSONFeatures) { + let feature; + for (const objectName in topoJSONFeatures) { if (this.layers_ && this.layers_.indexOf(objectName) == -1) { continue; } @@ -343,8 +343,7 @@ TopoJSON.prototype.readFeaturesFromObject = function( * @param {Array.} translate Translation for each dimension. */ function transformArcs(arcs, scale, translate) { - let i, ii; - for (i = 0, ii = arcs.length; i < ii; ++i) { + for (let i = 0, ii = arcs.length; i < ii; ++i) { transformArc(arcs[i], scale, translate); } } @@ -360,10 +359,8 @@ function transformArcs(arcs, scale, translate) { function transformArc(arc, scale, translate) { let x = 0; let y = 0; - let vertex; - let i, ii; - for (i = 0, ii = arc.length; i < ii; ++i) { - vertex = arc[i]; + for (let i = 0, ii = arc.length; i < ii; ++i) { + const vertex = arc[i]; x += vertex[0]; y += vertex[1]; vertex[0] = x; diff --git a/src/ol/geom/Circle.js b/src/ol/geom/Circle.js index d41591cdcd..9c6de67a51 100644 --- a/src/ol/geom/Circle.js +++ b/src/ol/geom/Circle.js @@ -50,16 +50,15 @@ Circle.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistanc const dy = y - flatCoordinates[1]; const squaredDistance = dx * dx + dy * dy; if (squaredDistance < minSquaredDistance) { - let i; if (squaredDistance === 0) { - for (i = 0; i < this.stride; ++i) { + for (let i = 0; i < this.stride; ++i) { closestPoint[i] = flatCoordinates[i]; } } else { const delta = this.getRadius() / Math.sqrt(squaredDistance); closestPoint[0] = flatCoordinates[0] + delta * dx; closestPoint[1] = flatCoordinates[1] + delta * dy; - for (i = 2; i < this.stride; ++i) { + for (let i = 2; i < this.stride; ++i) { closestPoint[i] = flatCoordinates[i]; } } @@ -168,8 +167,7 @@ Circle.prototype.setCenter = function(center) { const radius = this.flatCoordinates[stride] - this.flatCoordinates[0]; const flatCoordinates = center.slice(); flatCoordinates[stride] = flatCoordinates[0] + radius; - let i; - for (i = 1; i < stride; ++i) { + for (let i = 1; i < stride; ++i) { flatCoordinates[stride + i] = center[i]; } this.setFlatCoordinates(this.layout, flatCoordinates); @@ -197,8 +195,7 @@ Circle.prototype.setCenterAndRadius = function(center, radius, opt_layout) { let offset = _ol_geom_flat_deflate_.coordinate( flatCoordinates, 0, center, this.stride); flatCoordinates[offset++] = flatCoordinates[0] + radius; - let i, ii; - for (i = 1, ii = this.stride; i < ii; ++i) { + for (let i = 1, ii = this.stride; i < ii; ++i) { flatCoordinates[offset++] = flatCoordinates[i]; } flatCoordinates.length = offset; diff --git a/src/ol/geom/Point.js b/src/ol/geom/Point.js index 82bf02a4df..931ac44f69 100644 --- a/src/ol/geom/Point.js +++ b/src/ol/geom/Point.js @@ -45,12 +45,10 @@ Point.prototype.clone = function() { */ Point.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistance) { const flatCoordinates = this.flatCoordinates; - const squaredDistance = squaredDx( - x, y, flatCoordinates[0], flatCoordinates[1]); + const squaredDistance = squaredDx(x, y, flatCoordinates[0], flatCoordinates[1]); if (squaredDistance < minSquaredDistance) { const stride = this.stride; - let i; - for (i = 0; i < stride; ++i) { + for (let i = 0; i < stride; ++i) { closestPoint[i] = flatCoordinates[i]; } closestPoint.length = stride; diff --git a/src/ol/geom/Polygon.js b/src/ol/geom/Polygon.js index 3990e629ed..47cddbf8c5 100644 --- a/src/ol/geom/Polygon.js +++ b/src/ol/geom/Polygon.js @@ -264,8 +264,7 @@ Polygon.prototype.getLinearRings = function() { const ends = this.ends_; const linearRings = []; let offset = 0; - let i, ii; - for (i = 0, ii = ends.length; i < ii; ++i) { + for (let i = 0, ii = ends.length; i < ii; ++i) { const end = ends[i]; const linearRing = new LinearRing(null); linearRing.setFlatCoordinates(layout, flatCoordinates.slice(offset, end)); @@ -386,14 +385,12 @@ export function circular(center, radius, opt_n, opt_sphereRadius) { const n = opt_n ? opt_n : 32; /** @type {Array.} */ const flatCoordinates = []; - let i; - for (i = 0; i < n; ++i) { + for (let i = 0; i < n; ++i) { extend(flatCoordinates, sphereOffset(center, radius, 2 * Math.PI * i / n, opt_sphereRadius)); } flatCoordinates.push(flatCoordinates[0], flatCoordinates[1]); const polygon = new Polygon(null); - polygon.setFlatCoordinates( - GeometryLayout.XY, flatCoordinates, [flatCoordinates.length]); + polygon.setFlatCoordinates(GeometryLayout.XY, flatCoordinates, [flatCoordinates.length]); return polygon; } @@ -459,10 +456,9 @@ export function makeRegular(polygon, center, radius, opt_angle) { const ends = polygon.getEnds(); const sides = flatCoordinates.length / stride - 1; const startAngle = opt_angle ? opt_angle : 0; - let angle, offset; for (let i = 0; i <= sides; ++i) { - offset = i * stride; - angle = startAngle + (modulo(i, sides) * 2 * Math.PI / sides); + const offset = i * stride; + const angle = startAngle + (modulo(i, sides) * 2 * Math.PI / sides); flatCoordinates[offset] = center[0] + (radius * Math.cos(angle)); flatCoordinates[offset + 1] = center[1] + (radius * Math.sin(angle)); } diff --git a/src/ol/geom/flat/area.js b/src/ol/geom/flat/area.js index 10291e6496..6188d58524 100644 --- a/src/ol/geom/flat/area.js +++ b/src/ol/geom/flat/area.js @@ -35,8 +35,7 @@ _ol_geom_flat_area_.linearRing = function(flatCoordinates, offset, end, stride) */ _ol_geom_flat_area_.linearRings = function(flatCoordinates, offset, ends, stride) { let area = 0; - let i, ii; - for (i = 0, ii = ends.length; i < ii; ++i) { + for (let i = 0, ii = ends.length; i < ii; ++i) { const end = ends[i]; area += _ol_geom_flat_area_.linearRing(flatCoordinates, offset, end, stride); offset = end; @@ -54,11 +53,9 @@ _ol_geom_flat_area_.linearRings = function(flatCoordinates, offset, ends, stride */ _ol_geom_flat_area_.linearRingss = function(flatCoordinates, offset, endss, stride) { let area = 0; - let i, ii; - for (i = 0, ii = endss.length; i < ii; ++i) { + for (let i = 0, ii = endss.length; i < ii; ++i) { const ends = endss[i]; - area += - _ol_geom_flat_area_.linearRings(flatCoordinates, offset, ends, stride); + area += _ol_geom_flat_area_.linearRings(flatCoordinates, offset, ends, stride); offset = ends[ends.length - 1]; } return area; diff --git a/src/ol/geom/flat/interpolate.js b/src/ol/geom/flat/interpolate.js index 6deb41fea2..04d238fa83 100644 --- a/src/ol/geom/flat/interpolate.js +++ b/src/ol/geom/flat/interpolate.js @@ -32,8 +32,7 @@ _ol_geom_flat_interpolate_.lineString = function(flatCoordinates, offset, end, s let y1 = flatCoordinates[offset + 1]; let length = 0; const cumulativeLengths = [0]; - let i; - for (i = offset + stride; i < end; i += stride) { + for (let i = offset + stride; i < end; i += stride) { const x2 = flatCoordinates[i]; const y2 = flatCoordinates[i + 1]; length += Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); @@ -118,8 +117,7 @@ _ol_geom_flat_interpolate_.lineStringCoordinateAtM = function(flatCoordinates, o const m1 = flatCoordinates[(lo + 1) * stride - 1]; const t = (m - m0) / (m1 - m0); coordinate = []; - let i; - for (i = 0; i < stride - 1; ++i) { + for (let i = 0; i < stride - 1; ++i) { coordinate.push(lerp(flatCoordinates[(lo - 1) * stride + i], flatCoordinates[lo * stride + i], t)); } @@ -163,8 +161,7 @@ _ol_geom_flat_interpolate_.lineStringsCoordinateAtM = function( return null; } } - let i, ii; - for (i = 0, ii = ends.length; i < ii; ++i) { + for (let i = 0, ii = ends.length; i < ii; ++i) { const end = ends[i]; if (offset == end) { continue; diff --git a/src/ol/geom/flat/orient.js b/src/ol/geom/flat/orient.js index 0a4e8b88c4..60d449ec2c 100644 --- a/src/ol/geom/flat/orient.js +++ b/src/ol/geom/flat/orient.js @@ -44,8 +44,7 @@ _ol_geom_flat_orient_.linearRingIsClockwise = function(flatCoordinates, offset, */ _ol_geom_flat_orient_.linearRingsAreOriented = function(flatCoordinates, offset, ends, stride, opt_right) { const right = opt_right !== undefined ? opt_right : false; - let i, ii; - for (i = 0, ii = ends.length; i < ii; ++i) { + for (let i = 0, ii = ends.length; i < ii; ++i) { const end = ends[i]; const isClockwise = _ol_geom_flat_orient_.linearRingIsClockwise( flatCoordinates, offset, end, stride); @@ -78,8 +77,7 @@ _ol_geom_flat_orient_.linearRingsAreOriented = function(flatCoordinates, offset, * @return {boolean} Rings are correctly oriented. */ _ol_geom_flat_orient_.linearRingssAreOriented = function(flatCoordinates, offset, endss, stride, opt_right) { - let i, ii; - for (i = 0, ii = endss.length; i < ii; ++i) { + for (let i = 0, ii = endss.length; i < ii; ++i) { if (!_ol_geom_flat_orient_.linearRingsAreOriented( flatCoordinates, offset, endss[i], stride, opt_right)) { return false; @@ -104,8 +102,7 @@ _ol_geom_flat_orient_.linearRingssAreOriented = function(flatCoordinates, offset */ _ol_geom_flat_orient_.orientLinearRings = function(flatCoordinates, offset, ends, stride, opt_right) { const right = opt_right !== undefined ? opt_right : false; - let i, ii; - for (i = 0, ii = ends.length; i < ii; ++i) { + for (let i = 0, ii = ends.length; i < ii; ++i) { const end = ends[i]; const isClockwise = _ol_geom_flat_orient_.linearRingIsClockwise( flatCoordinates, offset, end, stride); @@ -135,8 +132,7 @@ _ol_geom_flat_orient_.orientLinearRings = function(flatCoordinates, offset, ends * @return {number} End. */ _ol_geom_flat_orient_.orientLinearRingss = function(flatCoordinates, offset, endss, stride, opt_right) { - let i, ii; - for (i = 0, ii = endss.length; i < ii; ++i) { + for (let i = 0, ii = endss.length; i < ii; ++i) { offset = _ol_geom_flat_orient_.orientLinearRings( flatCoordinates, offset, endss[i], stride, opt_right); } diff --git a/src/ol/geom/flat/transform.js b/src/ol/geom/flat/transform.js index f6896ba463..2493536971 100644 --- a/src/ol/geom/flat/transform.js +++ b/src/ol/geom/flat/transform.js @@ -16,8 +16,7 @@ const _ol_geom_flat_transform_ = {}; _ol_geom_flat_transform_.transform2D = function(flatCoordinates, offset, end, stride, transform, opt_dest) { const dest = opt_dest ? opt_dest : []; let i = 0; - let j; - for (j = offset; j < end; j += stride) { + for (let j = offset; j < end; j += stride) { const x = flatCoordinates[j]; const y = flatCoordinates[j + 1]; dest[i++] = transform[0] * x + transform[2] * y + transform[4]; @@ -109,11 +108,10 @@ _ol_geom_flat_transform_.scale = function(flatCoordinates, offset, end, stride, _ol_geom_flat_transform_.translate = function(flatCoordinates, offset, end, stride, deltaX, deltaY, opt_dest) { const dest = opt_dest ? opt_dest : []; let i = 0; - let j, k; - for (j = offset; j < end; j += stride) { + for (let j = offset; j < end; j += stride) { dest[i++] = flatCoordinates[j] + deltaX; dest[i++] = flatCoordinates[j + 1] + deltaY; - for (k = j + 2; k < j + stride; ++k) { + for (let k = j + 2; k < j + stride; ++k) { dest[i++] = flatCoordinates[k]; } } diff --git a/src/ol/interaction/Snap.js b/src/ol/interaction/Snap.js index e098282829..31da62b1ec 100644 --- a/src/ol/interaction/Snap.js +++ b/src/ol/interaction/Snap.js @@ -437,10 +437,9 @@ Snap.prototype.updateFeature_ = function(feature) { Snap.prototype.writeCircleGeometry_ = function(feature, geometry) { const polygon = fromCircle(geometry); const coordinates = polygon.getCoordinates()[0]; - let i, ii, segment, segmentData; - for (i = 0, ii = coordinates.length - 1; i < ii; ++i) { - segment = coordinates.slice(i, i + 2); - segmentData = /** @type {ol.SnapSegmentDataType} */ ({ + for (let i = 0, ii = coordinates.length - 1; i < ii; ++i) { + const segment = coordinates.slice(i, i + 2); + const segmentData = /** @type {ol.SnapSegmentDataType} */ ({ feature: feature, segment: segment }); @@ -472,10 +471,9 @@ Snap.prototype.writeGeometryCollectionGeometry_ = function(feature, geometry) { */ Snap.prototype.writeLineStringGeometry_ = function(feature, geometry) { const coordinates = geometry.getCoordinates(); - let i, ii, segment, segmentData; - for (i = 0, ii = coordinates.length - 1; i < ii; ++i) { - segment = coordinates.slice(i, i + 2); - segmentData = /** @type {ol.SnapSegmentDataType} */ ({ + for (let i = 0, ii = coordinates.length - 1; i < ii; ++i) { + const segment = coordinates.slice(i, i + 2); + const segmentData = /** @type {ol.SnapSegmentDataType} */ ({ feature: feature, segment: segment }); @@ -491,12 +489,11 @@ Snap.prototype.writeLineStringGeometry_ = function(feature, geometry) { */ Snap.prototype.writeMultiLineStringGeometry_ = function(feature, geometry) { const lines = geometry.getCoordinates(); - let coordinates, i, ii, j, jj, segment, segmentData; - for (j = 0, jj = lines.length; j < jj; ++j) { - coordinates = lines[j]; - for (i = 0, ii = coordinates.length - 1; i < ii; ++i) { - segment = coordinates.slice(i, i + 2); - segmentData = /** @type {ol.SnapSegmentDataType} */ ({ + for (let j = 0, jj = lines.length; j < jj; ++j) { + const coordinates = lines[j]; + for (let i = 0, ii = coordinates.length - 1; i < ii; ++i) { + const segment = coordinates.slice(i, i + 2); + const segmentData = /** @type {ol.SnapSegmentDataType} */ ({ feature: feature, segment: segment }); @@ -513,10 +510,9 @@ Snap.prototype.writeMultiLineStringGeometry_ = function(feature, geometry) { */ Snap.prototype.writeMultiPointGeometry_ = function(feature, geometry) { const points = geometry.getCoordinates(); - let coordinates, i, ii, segmentData; - for (i = 0, ii = points.length; i < ii; ++i) { - coordinates = points[i]; - segmentData = /** @type {ol.SnapSegmentDataType} */ ({ + for (let i = 0, ii = points.length; i < ii; ++i) { + const coordinates = points[i]; + const segmentData = /** @type {ol.SnapSegmentDataType} */ ({ feature: feature, segment: [coordinates, coordinates] }); @@ -532,14 +528,13 @@ Snap.prototype.writeMultiPointGeometry_ = function(feature, geometry) { */ Snap.prototype.writeMultiPolygonGeometry_ = function(feature, geometry) { const polygons = geometry.getCoordinates(); - let coordinates, i, ii, j, jj, k, kk, rings, segment, segmentData; - for (k = 0, kk = polygons.length; k < kk; ++k) { - rings = polygons[k]; - for (j = 0, jj = rings.length; j < jj; ++j) { - coordinates = rings[j]; - for (i = 0, ii = coordinates.length - 1; i < ii; ++i) { - segment = coordinates.slice(i, i + 2); - segmentData = /** @type {ol.SnapSegmentDataType} */ ({ + for (let k = 0, kk = polygons.length; k < kk; ++k) { + const rings = polygons[k]; + for (let j = 0, jj = rings.length; j < jj; ++j) { + const coordinates = rings[j]; + for (let i = 0, ii = coordinates.length - 1; i < ii; ++i) { + const segment = coordinates.slice(i, i + 2); + const segmentData = /** @type {ol.SnapSegmentDataType} */ ({ feature: feature, segment: segment }); @@ -572,12 +567,11 @@ Snap.prototype.writePointGeometry_ = function(feature, geometry) { */ Snap.prototype.writePolygonGeometry_ = function(feature, geometry) { const rings = geometry.getCoordinates(); - let coordinates, i, ii, j, jj, segment, segmentData; - for (j = 0, jj = rings.length; j < jj; ++j) { - coordinates = rings[j]; - for (i = 0, ii = coordinates.length - 1; i < ii; ++i) { - segment = coordinates.slice(i, i + 2); - segmentData = /** @type {ol.SnapSegmentDataType} */ ({ + for (let j = 0, jj = rings.length; j < jj; ++j) { + const coordinates = rings[j]; + for (let i = 0, ii = coordinates.length - 1; i < ii; ++i) { + const segment = coordinates.slice(i, i + 2); + const segmentData = /** @type {ol.SnapSegmentDataType} */ ({ feature: feature, segment: segment }); diff --git a/src/ol/render/canvas/ReplayGroup.js b/src/ol/render/canvas/ReplayGroup.js index 73d3613484..bdf2577fa1 100644 --- a/src/ol/render/canvas/ReplayGroup.js +++ b/src/ol/render/canvas/ReplayGroup.js @@ -260,8 +260,7 @@ CanvasReplayGroup.prototype.hasReplays = function(replays) { * FIXME empty description for jsdoc */ CanvasReplayGroup.prototype.finish = function() { - let zKey; - for (zKey in this.replaysByZIndex_) { + for (const zKey in this.replaysByZIndex_) { const replays = this.replaysByZIndex_[zKey]; for (const replayKey in replays) { replays[replayKey].finish(); diff --git a/src/ol/render/webgl/PolygonReplay.js b/src/ol/render/webgl/PolygonReplay.js index d127a26673..dabce0cb48 100644 --- a/src/ol/render/webgl/PolygonReplay.js +++ b/src/ol/render/webgl/PolygonReplay.js @@ -652,16 +652,14 @@ WebGLPolygonReplay.prototype.removeItem_ = function(s0, s1, list, rtree) { * @param {boolean=} opt_reflex Only include reflex points. * @return {Array.} Points in the triangle. */ -WebGLPolygonReplay.prototype.getPointsInTriangle_ = function(p0, p1, - p2, rtree, opt_reflex) { - let i, ii, j, p; +WebGLPolygonReplay.prototype.getPointsInTriangle_ = function(p0, p1, p2, rtree, opt_reflex) { const result = []; const segmentsInExtent = rtree.getInExtent([Math.min(p0.x, p1.x, p2.x), Math.min(p0.y, p1.y, p2.y), Math.max(p0.x, p1.x, p2.x), Math.max(p0.y, p1.y, p2.y)]); - for (i = 0, ii = segmentsInExtent.length; i < ii; ++i) { - for (j in segmentsInExtent[i]) { - p = segmentsInExtent[i][j]; + for (let i = 0, ii = segmentsInExtent.length; i < ii; ++i) { + for (const j in segmentsInExtent[i]) { + const p = segmentsInExtent[i][j]; if (typeof p === 'object' && (!opt_reflex || p.reflex)) { if ((p.x !== p0.x || p.y !== p0.y) && (p.x !== p1.x || p.y !== p1.y) && (p.x !== p2.x || p.y !== p2.y) && result.indexOf(p) === -1 && @@ -689,8 +687,7 @@ WebGLPolygonReplay.prototype.getIntersections_ = function(segment, rtree, opt_to const segmentsInExtent = rtree.getInExtent([Math.min(p0.x, p1.x), Math.min(p0.y, p1.y), Math.max(p0.x, p1.x), Math.max(p0.y, p1.y)]); const result = []; - let i, ii; - for (i = 0, ii = segmentsInExtent.length; i < ii; ++i) { + for (let i = 0, ii = segmentsInExtent.length; i < ii; ++i) { const currSeg = segmentsInExtent[i]; if (segment !== currSeg && (opt_touch || currSeg.p0 !== p1 || currSeg.p1 !== p0) && this.calculateIntersection_(p0, p1, currSeg.p0, currSeg.p1, opt_touch)) { @@ -713,8 +710,7 @@ WebGLPolygonReplay.prototype.getIntersections_ = function(segment, rtree, opt_to * @param {boolean=} opt_touch Touching segments should be considered an intersection. * @return {Array.|undefined} Intersection coordinates. */ -WebGLPolygonReplay.prototype.calculateIntersection_ = function(p0, - p1, p2, p3, opt_touch) { +WebGLPolygonReplay.prototype.calculateIntersection_ = function(p0, p1, p2, p3, opt_touch) { const denom = (p3.y - p2.y) * (p1.x - p0.x) - (p3.x - p2.x) * (p1.y - p0.y); if (denom !== 0) { const ua = ((p3.x - p2.x) * (p0.y - p2.y) - (p3.y - p2.y) * (p0.x - p2.x)) / denom; diff --git a/src/ol/render/webgl/TextReplay.js b/src/ol/render/webgl/TextReplay.js index 1634d12213..19025633dd 100644 --- a/src/ol/render/webgl/TextReplay.js +++ b/src/ol/render/webgl/TextReplay.js @@ -215,8 +215,7 @@ WebGLTextReplay.prototype.getTextSize_ = function(lines) { //Split every line to an array of chars, sum up their width, and select the longest. const textWidth = lines.map(function(str) { let sum = 0; - let i, ii; - for (i = 0, ii = str.length; i < ii; ++i) { + for (let i = 0, ii = str.length; i < ii; ++i) { const curr = str[i]; if (!glyphAtlas.width[curr]) { self.addCharToAtlas_(curr); @@ -239,10 +238,8 @@ WebGLTextReplay.prototype.getTextSize_ = function(lines) { * @param {number} end End. * @param {number} stride Stride. */ -WebGLTextReplay.prototype.drawText_ = function(flatCoordinates, offset, - end, stride) { - let i, ii; - for (i = offset, ii = end; i < ii; i += stride) { +WebGLTextReplay.prototype.drawText_ = function(flatCoordinates, offset, end, stride) { + for (let i = offset, ii = end; i < ii; i += stride) { this.drawCoordinates(flatCoordinates, offset, end, stride); } }; @@ -402,8 +399,7 @@ WebGLTextReplay.prototype.setTextStyle = function(textStyle) { */ WebGLTextReplay.prototype.getAtlas_ = function(state) { let params = []; - let i; - for (i in state) { + for (const i in state) { if (state[i] || state[i] === 0) { if (Array.isArray(state[i])) { params = params.concat(state[i]); @@ -438,9 +434,8 @@ WebGLTextReplay.prototype.getAtlas_ = function(state) { */ WebGLTextReplay.prototype.calculateHash_ = function(params) { //TODO: Create a more performant, reliable, general hash function. - let i, ii; let hash = ''; - for (i = 0, ii = params.length; i < ii; ++i) { + for (let i = 0, ii = params.length; i < ii; ++i) { hash += params[i]; } return hash; diff --git a/src/ol/renderer/Map.js b/src/ol/renderer/Map.js index 261dadcbaf..a8cfa9d836 100644 --- a/src/ol/renderer/Map.js +++ b/src/ol/renderer/Map.js @@ -301,8 +301,7 @@ MapRenderer.prototype.renderFrame = nullFunction; * @private */ MapRenderer.prototype.removeUnusedLayerRenderers_ = function(map, frameState) { - let layerKey; - for (layerKey in this.layerRenderers_) { + for (const layerKey in this.layerRenderers_) { if (!frameState || !(layerKey in frameState.layerStates)) { this.removeLayerRendererByKey_(layerKey).dispose(); } @@ -326,8 +325,7 @@ MapRenderer.prototype.scheduleExpireIconCache = function(frameState) { * @protected */ MapRenderer.prototype.scheduleRemoveUnusedLayerRenderers = function(frameState) { - let layerKey; - for (layerKey in this.layerRenderers_) { + for (const layerKey in this.layerRenderers_) { if (!(layerKey in frameState.layerStates)) { frameState.postRenderFunctions.push( /** @type {ol.PostRenderFunction} */ (this.removeUnusedLayerRenderers_.bind(this)) diff --git a/src/ol/renderer/webgl/TileLayer.js b/src/ol/renderer/webgl/TileLayer.js index 6444483e62..0020a3720d 100644 --- a/src/ol/renderer/webgl/TileLayer.js +++ b/src/ol/renderer/webgl/TileLayer.js @@ -299,10 +299,9 @@ WebGLTileLayerRenderer.prototype.prepareFrame = function(frameState, layerState, const zs = Object.keys(tilesToDrawByZ).map(Number); zs.sort(numberSafeCompareFunction); const u_tileOffset = new Float32Array(4); - let i, ii, tileKey, tilesToDraw; - for (i = 0, ii = zs.length; i < ii; ++i) { - tilesToDraw = tilesToDrawByZ[zs[i]]; - for (tileKey in tilesToDraw) { + for (let i = 0, ii = zs.length; i < ii; ++i) { + const tilesToDraw = tilesToDrawByZ[zs[i]]; + for (const tileKey in tilesToDraw) { tile = tilesToDraw[tileKey]; tileExtent = tileGrid.getTileCoordExtent(tile.tileCoord, tmpExtent); u_tileOffset[0] = 2 * (tileExtent[2] - tileExtent[0]) / diff --git a/src/ol/source/Vector.js b/src/ol/source/Vector.js index 4b8da23c6a..b51f98bd18 100644 --- a/src/ol/source/Vector.js +++ b/src/ol/source/Vector.js @@ -253,23 +253,21 @@ VectorSource.prototype.addFeatures = function(features) { * @protected */ VectorSource.prototype.addFeaturesInternal = function(features) { - let featureKey, i, length, feature; - const extents = []; const newFeatures = []; const geometryFeatures = []; - for (i = 0, length = features.length; i < length; i++) { - feature = features[i]; - featureKey = getUid(feature).toString(); + for (let i = 0, length = features.length; i < length; i++) { + const feature = features[i]; + const featureKey = getUid(feature).toString(); if (this.addToIndex_(featureKey, feature)) { newFeatures.push(feature); } } - for (i = 0, length = newFeatures.length; i < length; i++) { - feature = newFeatures[i]; - featureKey = getUid(feature).toString(); + for (let i = 0, length = newFeatures.length; i < length; i++) { + const feature = newFeatures[i]; + const featureKey = getUid(feature).toString(); this.setupChangeEvents_(featureKey, feature); const geometry = feature.getGeometry(); @@ -285,9 +283,8 @@ VectorSource.prototype.addFeaturesInternal = function(features) { this.featuresRtree_.load(extents, geometryFeatures); } - for (i = 0, length = newFeatures.length; i < length; i++) { - this.dispatchEvent(new VectorSource.Event( - VectorEventType.ADDFEATURE, newFeatures[i])); + for (let i = 0, length = newFeatures.length; i < length; i++) { + this.dispatchEvent(new VectorSource.Event(VectorEventType.ADDFEATURE, newFeatures[i])); } }; @@ -735,8 +732,7 @@ VectorSource.prototype.loadFeatures = function( extent, resolution, projection) { const loadedExtentsRtree = this.loadedExtentsRtree_; const extentsToLoad = this.strategy_(extent, resolution); - let i, ii; - for (i = 0, ii = extentsToLoad.length; i < ii; ++i) { + for (let i = 0, ii = extentsToLoad.length; i < ii; ++i) { const extentToLoad = extentsToLoad[i]; const alreadyLoaded = loadedExtentsRtree.forEachInExtent(extentToLoad, /** diff --git a/src/ol/source/Zoomify.js b/src/ol/source/Zoomify.js index ed37d45c2a..b4057e0a3a 100644 --- a/src/ol/source/Zoomify.js +++ b/src/ol/source/Zoomify.js @@ -71,8 +71,7 @@ const Zoomify = function(opt_options) { const resolutions = [1]; const tileCountUpToTier = [0]; - let i, ii; - for (i = 1, ii = tierSizeInTiles.length; i < ii; i++) { + for (let i = 1, ii = tierSizeInTiles.length; i < ii; i++) { resolutions.push(1 << i); tileCountUpToTier.push( tierSizeInTiles[i - 1][0] * tierSizeInTiles[i - 1][1] + diff --git a/src/ol/style/IconImageCache.js b/src/ol/style/IconImageCache.js index 74ce90f17f..5323fb21e0 100644 --- a/src/ol/style/IconImageCache.js +++ b/src/ol/style/IconImageCache.js @@ -56,9 +56,8 @@ IconImageCache.prototype.clear = function() { IconImageCache.prototype.expire = function() { if (this.cacheSize_ > this.maxCacheSize_) { let i = 0; - let key, iconImage; - for (key in this.cache_) { - iconImage = this.cache_[key]; + for (const key in this.cache_) { + const iconImage = this.cache_[key]; if ((i++ & 3) === 0 && !iconImage.hasListener()) { delete this.cache_[key]; --this.cacheSize_; diff --git a/src/ol/webgl/Context.js b/src/ol/webgl/Context.js index b4dbfe3a71..4d6ef13438 100644 --- a/src/ol/webgl/Context.js +++ b/src/ol/webgl/Context.js @@ -148,14 +148,13 @@ _ol_webgl_Context_.prototype.disposeInternal = function() { _ol_events_.unlistenAll(this.canvas_); const gl = this.getGL(); if (!gl.isContextLost()) { - let key; - for (key in this.bufferCache_) { + for (const key in this.bufferCache_) { gl.deleteBuffer(this.bufferCache_[key].buffer); } - for (key in this.programCache_) { + for (const key in this.programCache_) { gl.deleteProgram(this.programCache_[key]); } - for (key in this.shaderCache_) { + for (const key in this.shaderCache_) { gl.deleteShader(this.shaderCache_[key]); } // delete objects for hit-detection