Better variables scoping

This commit is contained in:
Frederic Junod
2018-01-17 09:05:39 +01:00
parent ee348c50e9
commit 4c5ca75ca6
21 changed files with 93 additions and 147 deletions

View File

@@ -169,8 +169,7 @@ BaseObject.prototype.set = function(key, value, opt_silent) {
* @api * @api
*/ */
BaseObject.prototype.setProperties = function(values, opt_silent) { BaseObject.prototype.setProperties = function(values, opt_silent) {
let key; for (const key in values) {
for (key in values) {
this.set(key, values[key], opt_silent); this.set(key, values[key], opt_silent);
} }
}; };

View File

@@ -916,9 +916,8 @@ PluggableMap.prototype.handleMapBrowserEvent = function(mapBrowserEvent) {
this.focus_ = mapBrowserEvent.coordinate; this.focus_ = mapBrowserEvent.coordinate;
mapBrowserEvent.frameState = this.frameState_; mapBrowserEvent.frameState = this.frameState_;
const interactionsArray = this.getInteractions().getArray(); const interactionsArray = this.getInteractions().getArray();
let i;
if (this.dispatchEvent(mapBrowserEvent) !== false) { 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]; const interaction = interactionsArray[i];
if (!interaction.getActive()) { if (!interaction.getActive()) {
continue; continue;
@@ -970,8 +969,7 @@ PluggableMap.prototype.handlePostRender = function() {
} }
const postRenderFunctions = this.postRenderFunctions_; const postRenderFunctions = this.postRenderFunctions_;
let i, ii; for (let i = 0, ii = postRenderFunctions.length; i < ii; ++i) {
for (i = 0, ii = postRenderFunctions.length; i < ii; ++i) {
postRenderFunctions[i](this, frameState); postRenderFunctions[i](this, frameState);
} }
postRenderFunctions.length = 0; postRenderFunctions.length = 0;
@@ -1191,7 +1189,7 @@ PluggableMap.prototype.removeOverlay = function(overlay) {
* @private * @private
*/ */
PluggableMap.prototype.renderFrame_ = function(time) { PluggableMap.prototype.renderFrame_ = function(time) {
let i, ii, viewState; let viewState;
const size = this.getSize(); const size = this.getSize();
const view = this.getView(); const view = this.getView();
@@ -1203,7 +1201,7 @@ PluggableMap.prototype.renderFrame_ = function(time) {
const viewHints = view.getHints(this.frameState_ ? this.frameState_.viewHints : undefined); const viewHints = view.getHints(this.frameState_ ? this.frameState_.viewHints : undefined);
const layerStatesArray = this.getLayerGroup().getLayerStatesArray(); const layerStatesArray = this.getLayerGroup().getLayerStatesArray();
const layerStates = {}; 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]; layerStates[getUid(layerStatesArray[i].layer)] = layerStatesArray[i];
} }
viewState = view.getState(); viewState = view.getState();

View File

@@ -91,8 +91,7 @@ export const fromString = (
} else { } else {
if (cacheSize >= MAX_CACHE_SIZE) { if (cacheSize >= MAX_CACHE_SIZE) {
let i = 0; let i = 0;
let key; for (const key in cache) {
for (key in cache) {
if ((i++ & 3) === 0) { if ((i++ & 3) === 0) {
delete cache[key]; delete cache[key];
--cacheSize; --cacheSize;

View File

@@ -312,8 +312,8 @@ TopoJSON.prototype.readFeaturesFromObject = function(
const features = []; const features = [];
const topoJSONFeatures = topoJSONTopology.objects; const topoJSONFeatures = topoJSONTopology.objects;
const property = this.layerName_; const property = this.layerName_;
let objectName, feature; let feature;
for (objectName in topoJSONFeatures) { for (const objectName in topoJSONFeatures) {
if (this.layers_ && this.layers_.indexOf(objectName) == -1) { if (this.layers_ && this.layers_.indexOf(objectName) == -1) {
continue; continue;
} }
@@ -343,8 +343,7 @@ TopoJSON.prototype.readFeaturesFromObject = function(
* @param {Array.<number>} translate Translation for each dimension. * @param {Array.<number>} translate Translation for each dimension.
*/ */
function transformArcs(arcs, scale, translate) { function transformArcs(arcs, scale, translate) {
let i, ii; for (let i = 0, ii = arcs.length; i < ii; ++i) {
for (i = 0, ii = arcs.length; i < ii; ++i) {
transformArc(arcs[i], scale, translate); transformArc(arcs[i], scale, translate);
} }
} }
@@ -360,10 +359,8 @@ function transformArcs(arcs, scale, translate) {
function transformArc(arc, scale, translate) { function transformArc(arc, scale, translate) {
let x = 0; let x = 0;
let y = 0; let y = 0;
let vertex; for (let i = 0, ii = arc.length; i < ii; ++i) {
let i, ii; const vertex = arc[i];
for (i = 0, ii = arc.length; i < ii; ++i) {
vertex = arc[i];
x += vertex[0]; x += vertex[0];
y += vertex[1]; y += vertex[1];
vertex[0] = x; vertex[0] = x;

View File

@@ -50,16 +50,15 @@ Circle.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistanc
const dy = y - flatCoordinates[1]; const dy = y - flatCoordinates[1];
const squaredDistance = dx * dx + dy * dy; const squaredDistance = dx * dx + dy * dy;
if (squaredDistance < minSquaredDistance) { if (squaredDistance < minSquaredDistance) {
let i;
if (squaredDistance === 0) { if (squaredDistance === 0) {
for (i = 0; i < this.stride; ++i) { for (let i = 0; i < this.stride; ++i) {
closestPoint[i] = flatCoordinates[i]; closestPoint[i] = flatCoordinates[i];
} }
} else { } else {
const delta = this.getRadius() / Math.sqrt(squaredDistance); const delta = this.getRadius() / Math.sqrt(squaredDistance);
closestPoint[0] = flatCoordinates[0] + delta * dx; closestPoint[0] = flatCoordinates[0] + delta * dx;
closestPoint[1] = flatCoordinates[1] + delta * dy; 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]; closestPoint[i] = flatCoordinates[i];
} }
} }
@@ -168,8 +167,7 @@ Circle.prototype.setCenter = function(center) {
const radius = this.flatCoordinates[stride] - this.flatCoordinates[0]; const radius = this.flatCoordinates[stride] - this.flatCoordinates[0];
const flatCoordinates = center.slice(); const flatCoordinates = center.slice();
flatCoordinates[stride] = flatCoordinates[0] + radius; flatCoordinates[stride] = flatCoordinates[0] + radius;
let i; for (let i = 1; i < stride; ++i) {
for (i = 1; i < stride; ++i) {
flatCoordinates[stride + i] = center[i]; flatCoordinates[stride + i] = center[i];
} }
this.setFlatCoordinates(this.layout, flatCoordinates); this.setFlatCoordinates(this.layout, flatCoordinates);
@@ -197,8 +195,7 @@ Circle.prototype.setCenterAndRadius = function(center, radius, opt_layout) {
let offset = _ol_geom_flat_deflate_.coordinate( let offset = _ol_geom_flat_deflate_.coordinate(
flatCoordinates, 0, center, this.stride); flatCoordinates, 0, center, this.stride);
flatCoordinates[offset++] = flatCoordinates[0] + radius; flatCoordinates[offset++] = flatCoordinates[0] + radius;
let i, ii; for (let i = 1, ii = this.stride; i < ii; ++i) {
for (i = 1, ii = this.stride; i < ii; ++i) {
flatCoordinates[offset++] = flatCoordinates[i]; flatCoordinates[offset++] = flatCoordinates[i];
} }
flatCoordinates.length = offset; flatCoordinates.length = offset;

View File

@@ -45,12 +45,10 @@ Point.prototype.clone = function() {
*/ */
Point.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistance) { Point.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistance) {
const flatCoordinates = this.flatCoordinates; const flatCoordinates = this.flatCoordinates;
const squaredDistance = squaredDx( const squaredDistance = squaredDx(x, y, flatCoordinates[0], flatCoordinates[1]);
x, y, flatCoordinates[0], flatCoordinates[1]);
if (squaredDistance < minSquaredDistance) { if (squaredDistance < minSquaredDistance) {
const stride = this.stride; const stride = this.stride;
let i; for (let i = 0; i < stride; ++i) {
for (i = 0; i < stride; ++i) {
closestPoint[i] = flatCoordinates[i]; closestPoint[i] = flatCoordinates[i];
} }
closestPoint.length = stride; closestPoint.length = stride;

View File

@@ -264,8 +264,7 @@ Polygon.prototype.getLinearRings = function() {
const ends = this.ends_; const ends = this.ends_;
const linearRings = []; const linearRings = [];
let offset = 0; let offset = 0;
let i, ii; for (let i = 0, ii = ends.length; i < ii; ++i) {
for (i = 0, ii = ends.length; i < ii; ++i) {
const end = ends[i]; const end = ends[i];
const linearRing = new LinearRing(null); const linearRing = new LinearRing(null);
linearRing.setFlatCoordinates(layout, flatCoordinates.slice(offset, end)); 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; const n = opt_n ? opt_n : 32;
/** @type {Array.<number>} */ /** @type {Array.<number>} */
const flatCoordinates = []; const flatCoordinates = [];
let i; for (let i = 0; i < n; ++i) {
for (i = 0; i < n; ++i) {
extend(flatCoordinates, sphereOffset(center, radius, 2 * Math.PI * i / n, opt_sphereRadius)); extend(flatCoordinates, sphereOffset(center, radius, 2 * Math.PI * i / n, opt_sphereRadius));
} }
flatCoordinates.push(flatCoordinates[0], flatCoordinates[1]); flatCoordinates.push(flatCoordinates[0], flatCoordinates[1]);
const polygon = new Polygon(null); const polygon = new Polygon(null);
polygon.setFlatCoordinates( polygon.setFlatCoordinates(GeometryLayout.XY, flatCoordinates, [flatCoordinates.length]);
GeometryLayout.XY, flatCoordinates, [flatCoordinates.length]);
return polygon; return polygon;
} }
@@ -459,10 +456,9 @@ export function makeRegular(polygon, center, radius, opt_angle) {
const ends = polygon.getEnds(); const ends = polygon.getEnds();
const sides = flatCoordinates.length / stride - 1; const sides = flatCoordinates.length / stride - 1;
const startAngle = opt_angle ? opt_angle : 0; const startAngle = opt_angle ? opt_angle : 0;
let angle, offset;
for (let i = 0; i <= sides; ++i) { for (let i = 0; i <= sides; ++i) {
offset = i * stride; const offset = i * stride;
angle = startAngle + (modulo(i, sides) * 2 * Math.PI / sides); const angle = startAngle + (modulo(i, sides) * 2 * Math.PI / sides);
flatCoordinates[offset] = center[0] + (radius * Math.cos(angle)); flatCoordinates[offset] = center[0] + (radius * Math.cos(angle));
flatCoordinates[offset + 1] = center[1] + (radius * Math.sin(angle)); flatCoordinates[offset + 1] = center[1] + (radius * Math.sin(angle));
} }

View File

@@ -35,8 +35,7 @@ _ol_geom_flat_area_.linearRing = function(flatCoordinates, offset, end, stride)
*/ */
_ol_geom_flat_area_.linearRings = function(flatCoordinates, offset, ends, stride) { _ol_geom_flat_area_.linearRings = function(flatCoordinates, offset, ends, stride) {
let area = 0; let area = 0;
let i, ii; for (let i = 0, ii = ends.length; i < ii; ++i) {
for (i = 0, ii = ends.length; i < ii; ++i) {
const end = ends[i]; const end = ends[i];
area += _ol_geom_flat_area_.linearRing(flatCoordinates, offset, end, stride); area += _ol_geom_flat_area_.linearRing(flatCoordinates, offset, end, stride);
offset = end; 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) { _ol_geom_flat_area_.linearRingss = function(flatCoordinates, offset, endss, stride) {
let area = 0; let area = 0;
let i, ii; for (let i = 0, ii = endss.length; i < ii; ++i) {
for (i = 0, ii = endss.length; i < ii; ++i) {
const ends = endss[i]; const ends = endss[i];
area += area += _ol_geom_flat_area_.linearRings(flatCoordinates, offset, ends, stride);
_ol_geom_flat_area_.linearRings(flatCoordinates, offset, ends, stride);
offset = ends[ends.length - 1]; offset = ends[ends.length - 1];
} }
return area; return area;

View File

@@ -32,8 +32,7 @@ _ol_geom_flat_interpolate_.lineString = function(flatCoordinates, offset, end, s
let y1 = flatCoordinates[offset + 1]; let y1 = flatCoordinates[offset + 1];
let length = 0; let length = 0;
const cumulativeLengths = [0]; const cumulativeLengths = [0];
let i; for (let i = offset + stride; i < end; i += stride) {
for (i = offset + stride; i < end; i += stride) {
const x2 = flatCoordinates[i]; const x2 = flatCoordinates[i];
const y2 = flatCoordinates[i + 1]; const y2 = flatCoordinates[i + 1];
length += Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); 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 m1 = flatCoordinates[(lo + 1) * stride - 1];
const t = (m - m0) / (m1 - m0); const t = (m - m0) / (m1 - m0);
coordinate = []; coordinate = [];
let i; for (let i = 0; i < stride - 1; ++i) {
for (i = 0; i < stride - 1; ++i) {
coordinate.push(lerp(flatCoordinates[(lo - 1) * stride + i], coordinate.push(lerp(flatCoordinates[(lo - 1) * stride + i],
flatCoordinates[lo * stride + i], t)); flatCoordinates[lo * stride + i], t));
} }
@@ -163,8 +161,7 @@ _ol_geom_flat_interpolate_.lineStringsCoordinateAtM = function(
return null; return null;
} }
} }
let i, ii; for (let i = 0, ii = ends.length; i < ii; ++i) {
for (i = 0, ii = ends.length; i < ii; ++i) {
const end = ends[i]; const end = ends[i];
if (offset == end) { if (offset == end) {
continue; continue;

View File

@@ -44,8 +44,7 @@ _ol_geom_flat_orient_.linearRingIsClockwise = function(flatCoordinates, offset,
*/ */
_ol_geom_flat_orient_.linearRingsAreOriented = function(flatCoordinates, offset, ends, stride, opt_right) { _ol_geom_flat_orient_.linearRingsAreOriented = function(flatCoordinates, offset, ends, stride, opt_right) {
const right = opt_right !== undefined ? opt_right : false; const right = opt_right !== undefined ? opt_right : false;
let i, ii; for (let i = 0, ii = ends.length; i < ii; ++i) {
for (i = 0, ii = ends.length; i < ii; ++i) {
const end = ends[i]; const end = ends[i];
const isClockwise = _ol_geom_flat_orient_.linearRingIsClockwise( const isClockwise = _ol_geom_flat_orient_.linearRingIsClockwise(
flatCoordinates, offset, end, stride); flatCoordinates, offset, end, stride);
@@ -78,8 +77,7 @@ _ol_geom_flat_orient_.linearRingsAreOriented = function(flatCoordinates, offset,
* @return {boolean} Rings are correctly oriented. * @return {boolean} Rings are correctly oriented.
*/ */
_ol_geom_flat_orient_.linearRingssAreOriented = function(flatCoordinates, offset, endss, stride, opt_right) { _ol_geom_flat_orient_.linearRingssAreOriented = function(flatCoordinates, offset, endss, stride, opt_right) {
let i, ii; for (let i = 0, ii = endss.length; i < ii; ++i) {
for (i = 0, ii = endss.length; i < ii; ++i) {
if (!_ol_geom_flat_orient_.linearRingsAreOriented( if (!_ol_geom_flat_orient_.linearRingsAreOriented(
flatCoordinates, offset, endss[i], stride, opt_right)) { flatCoordinates, offset, endss[i], stride, opt_right)) {
return false; 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) { _ol_geom_flat_orient_.orientLinearRings = function(flatCoordinates, offset, ends, stride, opt_right) {
const right = opt_right !== undefined ? opt_right : false; const right = opt_right !== undefined ? opt_right : false;
let i, ii; for (let i = 0, ii = ends.length; i < ii; ++i) {
for (i = 0, ii = ends.length; i < ii; ++i) {
const end = ends[i]; const end = ends[i];
const isClockwise = _ol_geom_flat_orient_.linearRingIsClockwise( const isClockwise = _ol_geom_flat_orient_.linearRingIsClockwise(
flatCoordinates, offset, end, stride); flatCoordinates, offset, end, stride);
@@ -135,8 +132,7 @@ _ol_geom_flat_orient_.orientLinearRings = function(flatCoordinates, offset, ends
* @return {number} End. * @return {number} End.
*/ */
_ol_geom_flat_orient_.orientLinearRingss = function(flatCoordinates, offset, endss, stride, opt_right) { _ol_geom_flat_orient_.orientLinearRingss = function(flatCoordinates, offset, endss, stride, opt_right) {
let i, ii; for (let i = 0, ii = endss.length; i < ii; ++i) {
for (i = 0, ii = endss.length; i < ii; ++i) {
offset = _ol_geom_flat_orient_.orientLinearRings( offset = _ol_geom_flat_orient_.orientLinearRings(
flatCoordinates, offset, endss[i], stride, opt_right); flatCoordinates, offset, endss[i], stride, opt_right);
} }

View File

@@ -16,8 +16,7 @@ const _ol_geom_flat_transform_ = {};
_ol_geom_flat_transform_.transform2D = function(flatCoordinates, offset, end, stride, transform, opt_dest) { _ol_geom_flat_transform_.transform2D = function(flatCoordinates, offset, end, stride, transform, opt_dest) {
const dest = opt_dest ? opt_dest : []; const dest = opt_dest ? opt_dest : [];
let i = 0; let i = 0;
let j; for (let j = offset; j < end; j += stride) {
for (j = offset; j < end; j += stride) {
const x = flatCoordinates[j]; const x = flatCoordinates[j];
const y = flatCoordinates[j + 1]; const y = flatCoordinates[j + 1];
dest[i++] = transform[0] * x + transform[2] * y + transform[4]; 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) { _ol_geom_flat_transform_.translate = function(flatCoordinates, offset, end, stride, deltaX, deltaY, opt_dest) {
const dest = opt_dest ? opt_dest : []; const dest = opt_dest ? opt_dest : [];
let i = 0; let i = 0;
let j, k; for (let j = offset; j < end; j += stride) {
for (j = offset; j < end; j += stride) {
dest[i++] = flatCoordinates[j] + deltaX; dest[i++] = flatCoordinates[j] + deltaX;
dest[i++] = flatCoordinates[j + 1] + deltaY; 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]; dest[i++] = flatCoordinates[k];
} }
} }

View File

@@ -437,10 +437,9 @@ Snap.prototype.updateFeature_ = function(feature) {
Snap.prototype.writeCircleGeometry_ = function(feature, geometry) { Snap.prototype.writeCircleGeometry_ = function(feature, geometry) {
const polygon = fromCircle(geometry); const polygon = fromCircle(geometry);
const coordinates = polygon.getCoordinates()[0]; const coordinates = polygon.getCoordinates()[0];
let i, ii, segment, segmentData; for (let i = 0, ii = coordinates.length - 1; i < ii; ++i) {
for (i = 0, ii = coordinates.length - 1; i < ii; ++i) { const segment = coordinates.slice(i, i + 2);
segment = coordinates.slice(i, i + 2); const segmentData = /** @type {ol.SnapSegmentDataType} */ ({
segmentData = /** @type {ol.SnapSegmentDataType} */ ({
feature: feature, feature: feature,
segment: segment segment: segment
}); });
@@ -472,10 +471,9 @@ Snap.prototype.writeGeometryCollectionGeometry_ = function(feature, geometry) {
*/ */
Snap.prototype.writeLineStringGeometry_ = function(feature, geometry) { Snap.prototype.writeLineStringGeometry_ = function(feature, geometry) {
const coordinates = geometry.getCoordinates(); const coordinates = geometry.getCoordinates();
let i, ii, segment, segmentData; for (let i = 0, ii = coordinates.length - 1; i < ii; ++i) {
for (i = 0, ii = coordinates.length - 1; i < ii; ++i) { const segment = coordinates.slice(i, i + 2);
segment = coordinates.slice(i, i + 2); const segmentData = /** @type {ol.SnapSegmentDataType} */ ({
segmentData = /** @type {ol.SnapSegmentDataType} */ ({
feature: feature, feature: feature,
segment: segment segment: segment
}); });
@@ -491,12 +489,11 @@ Snap.prototype.writeLineStringGeometry_ = function(feature, geometry) {
*/ */
Snap.prototype.writeMultiLineStringGeometry_ = function(feature, geometry) { Snap.prototype.writeMultiLineStringGeometry_ = function(feature, geometry) {
const lines = geometry.getCoordinates(); const lines = geometry.getCoordinates();
let coordinates, i, ii, j, jj, segment, segmentData; for (let j = 0, jj = lines.length; j < jj; ++j) {
for (j = 0, jj = lines.length; j < jj; ++j) { const coordinates = lines[j];
coordinates = lines[j]; for (let i = 0, ii = coordinates.length - 1; i < ii; ++i) {
for (i = 0, ii = coordinates.length - 1; i < ii; ++i) { const segment = coordinates.slice(i, i + 2);
segment = coordinates.slice(i, i + 2); const segmentData = /** @type {ol.SnapSegmentDataType} */ ({
segmentData = /** @type {ol.SnapSegmentDataType} */ ({
feature: feature, feature: feature,
segment: segment segment: segment
}); });
@@ -513,10 +510,9 @@ Snap.prototype.writeMultiLineStringGeometry_ = function(feature, geometry) {
*/ */
Snap.prototype.writeMultiPointGeometry_ = function(feature, geometry) { Snap.prototype.writeMultiPointGeometry_ = function(feature, geometry) {
const points = geometry.getCoordinates(); const points = geometry.getCoordinates();
let coordinates, i, ii, segmentData; for (let i = 0, ii = points.length; i < ii; ++i) {
for (i = 0, ii = points.length; i < ii; ++i) { const coordinates = points[i];
coordinates = points[i]; const segmentData = /** @type {ol.SnapSegmentDataType} */ ({
segmentData = /** @type {ol.SnapSegmentDataType} */ ({
feature: feature, feature: feature,
segment: [coordinates, coordinates] segment: [coordinates, coordinates]
}); });
@@ -532,14 +528,13 @@ Snap.prototype.writeMultiPointGeometry_ = function(feature, geometry) {
*/ */
Snap.prototype.writeMultiPolygonGeometry_ = function(feature, geometry) { Snap.prototype.writeMultiPolygonGeometry_ = function(feature, geometry) {
const polygons = geometry.getCoordinates(); const polygons = geometry.getCoordinates();
let coordinates, i, ii, j, jj, k, kk, rings, segment, segmentData; for (let k = 0, kk = polygons.length; k < kk; ++k) {
for (k = 0, kk = polygons.length; k < kk; ++k) { const rings = polygons[k];
rings = polygons[k]; for (let j = 0, jj = rings.length; j < jj; ++j) {
for (j = 0, jj = rings.length; j < jj; ++j) { const coordinates = rings[j];
coordinates = rings[j]; for (let i = 0, ii = coordinates.length - 1; i < ii; ++i) {
for (i = 0, ii = coordinates.length - 1; i < ii; ++i) { const segment = coordinates.slice(i, i + 2);
segment = coordinates.slice(i, i + 2); const segmentData = /** @type {ol.SnapSegmentDataType} */ ({
segmentData = /** @type {ol.SnapSegmentDataType} */ ({
feature: feature, feature: feature,
segment: segment segment: segment
}); });
@@ -572,12 +567,11 @@ Snap.prototype.writePointGeometry_ = function(feature, geometry) {
*/ */
Snap.prototype.writePolygonGeometry_ = function(feature, geometry) { Snap.prototype.writePolygonGeometry_ = function(feature, geometry) {
const rings = geometry.getCoordinates(); const rings = geometry.getCoordinates();
let coordinates, i, ii, j, jj, segment, segmentData; for (let j = 0, jj = rings.length; j < jj; ++j) {
for (j = 0, jj = rings.length; j < jj; ++j) { const coordinates = rings[j];
coordinates = rings[j]; for (let i = 0, ii = coordinates.length - 1; i < ii; ++i) {
for (i = 0, ii = coordinates.length - 1; i < ii; ++i) { const segment = coordinates.slice(i, i + 2);
segment = coordinates.slice(i, i + 2); const segmentData = /** @type {ol.SnapSegmentDataType} */ ({
segmentData = /** @type {ol.SnapSegmentDataType} */ ({
feature: feature, feature: feature,
segment: segment segment: segment
}); });

View File

@@ -260,8 +260,7 @@ CanvasReplayGroup.prototype.hasReplays = function(replays) {
* FIXME empty description for jsdoc * FIXME empty description for jsdoc
*/ */
CanvasReplayGroup.prototype.finish = function() { CanvasReplayGroup.prototype.finish = function() {
let zKey; for (const zKey in this.replaysByZIndex_) {
for (zKey in this.replaysByZIndex_) {
const replays = this.replaysByZIndex_[zKey]; const replays = this.replaysByZIndex_[zKey];
for (const replayKey in replays) { for (const replayKey in replays) {
replays[replayKey].finish(); replays[replayKey].finish();

View File

@@ -652,16 +652,14 @@ WebGLPolygonReplay.prototype.removeItem_ = function(s0, s1, list, rtree) {
* @param {boolean=} opt_reflex Only include reflex points. * @param {boolean=} opt_reflex Only include reflex points.
* @return {Array.<ol.WebglPolygonVertex>} Points in the triangle. * @return {Array.<ol.WebglPolygonVertex>} Points in the triangle.
*/ */
WebGLPolygonReplay.prototype.getPointsInTriangle_ = function(p0, p1, WebGLPolygonReplay.prototype.getPointsInTriangle_ = function(p0, p1, p2, rtree, opt_reflex) {
p2, rtree, opt_reflex) {
let i, ii, j, p;
const result = []; const result = [];
const segmentsInExtent = rtree.getInExtent([Math.min(p0.x, p1.x, p2.x), 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, Math.min(p0.y, p1.y, p2.y), Math.max(p0.x, p1.x, p2.x), Math.max(p0.y,
p1.y, p2.y)]); p1.y, p2.y)]);
for (i = 0, ii = segmentsInExtent.length; i < ii; ++i) { for (let i = 0, ii = segmentsInExtent.length; i < ii; ++i) {
for (j in segmentsInExtent[i]) { for (const j in segmentsInExtent[i]) {
p = segmentsInExtent[i][j]; const p = segmentsInExtent[i][j];
if (typeof p === 'object' && (!opt_reflex || p.reflex)) { 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) && 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 && (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), 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)]); Math.min(p0.y, p1.y), Math.max(p0.x, p1.x), Math.max(p0.y, p1.y)]);
const result = []; const result = [];
let i, ii; for (let i = 0, ii = segmentsInExtent.length; i < ii; ++i) {
for (i = 0, ii = segmentsInExtent.length; i < ii; ++i) {
const currSeg = segmentsInExtent[i]; const currSeg = segmentsInExtent[i];
if (segment !== currSeg && (opt_touch || currSeg.p0 !== p1 || currSeg.p1 !== p0) && if (segment !== currSeg && (opt_touch || currSeg.p0 !== p1 || currSeg.p1 !== p0) &&
this.calculateIntersection_(p0, p1, currSeg.p0, currSeg.p1, opt_touch)) { 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. * @param {boolean=} opt_touch Touching segments should be considered an intersection.
* @return {Array.<number>|undefined} Intersection coordinates. * @return {Array.<number>|undefined} Intersection coordinates.
*/ */
WebGLPolygonReplay.prototype.calculateIntersection_ = function(p0, WebGLPolygonReplay.prototype.calculateIntersection_ = function(p0, p1, p2, p3, opt_touch) {
p1, p2, p3, opt_touch) {
const denom = (p3.y - p2.y) * (p1.x - p0.x) - (p3.x - p2.x) * (p1.y - p0.y); const denom = (p3.y - p2.y) * (p1.x - p0.x) - (p3.x - p2.x) * (p1.y - p0.y);
if (denom !== 0) { if (denom !== 0) {
const ua = ((p3.x - p2.x) * (p0.y - p2.y) - (p3.y - p2.y) * (p0.x - p2.x)) / denom; const ua = ((p3.x - p2.x) * (p0.y - p2.y) - (p3.y - p2.y) * (p0.x - p2.x)) / denom;

View File

@@ -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. //Split every line to an array of chars, sum up their width, and select the longest.
const textWidth = lines.map(function(str) { const textWidth = lines.map(function(str) {
let sum = 0; let sum = 0;
let i, ii; for (let i = 0, ii = str.length; i < ii; ++i) {
for (i = 0, ii = str.length; i < ii; ++i) {
const curr = str[i]; const curr = str[i];
if (!glyphAtlas.width[curr]) { if (!glyphAtlas.width[curr]) {
self.addCharToAtlas_(curr); self.addCharToAtlas_(curr);
@@ -239,10 +238,8 @@ WebGLTextReplay.prototype.getTextSize_ = function(lines) {
* @param {number} end End. * @param {number} end End.
* @param {number} stride Stride. * @param {number} stride Stride.
*/ */
WebGLTextReplay.prototype.drawText_ = function(flatCoordinates, offset, WebGLTextReplay.prototype.drawText_ = function(flatCoordinates, offset, end, stride) {
end, stride) { for (let i = offset, ii = end; i < ii; i += stride) {
let i, ii;
for (i = offset, ii = end; i < ii; i += stride) {
this.drawCoordinates(flatCoordinates, offset, end, stride); this.drawCoordinates(flatCoordinates, offset, end, stride);
} }
}; };
@@ -402,8 +399,7 @@ WebGLTextReplay.prototype.setTextStyle = function(textStyle) {
*/ */
WebGLTextReplay.prototype.getAtlas_ = function(state) { WebGLTextReplay.prototype.getAtlas_ = function(state) {
let params = []; let params = [];
let i; for (const i in state) {
for (i in state) {
if (state[i] || state[i] === 0) { if (state[i] || state[i] === 0) {
if (Array.isArray(state[i])) { if (Array.isArray(state[i])) {
params = params.concat(state[i]); params = params.concat(state[i]);
@@ -438,9 +434,8 @@ WebGLTextReplay.prototype.getAtlas_ = function(state) {
*/ */
WebGLTextReplay.prototype.calculateHash_ = function(params) { WebGLTextReplay.prototype.calculateHash_ = function(params) {
//TODO: Create a more performant, reliable, general hash function. //TODO: Create a more performant, reliable, general hash function.
let i, ii;
let hash = ''; let hash = '';
for (i = 0, ii = params.length; i < ii; ++i) { for (let i = 0, ii = params.length; i < ii; ++i) {
hash += params[i]; hash += params[i];
} }
return hash; return hash;

View File

@@ -301,8 +301,7 @@ MapRenderer.prototype.renderFrame = nullFunction;
* @private * @private
*/ */
MapRenderer.prototype.removeUnusedLayerRenderers_ = function(map, frameState) { MapRenderer.prototype.removeUnusedLayerRenderers_ = function(map, frameState) {
let layerKey; for (const layerKey in this.layerRenderers_) {
for (layerKey in this.layerRenderers_) {
if (!frameState || !(layerKey in frameState.layerStates)) { if (!frameState || !(layerKey in frameState.layerStates)) {
this.removeLayerRendererByKey_(layerKey).dispose(); this.removeLayerRendererByKey_(layerKey).dispose();
} }
@@ -326,8 +325,7 @@ MapRenderer.prototype.scheduleExpireIconCache = function(frameState) {
* @protected * @protected
*/ */
MapRenderer.prototype.scheduleRemoveUnusedLayerRenderers = function(frameState) { MapRenderer.prototype.scheduleRemoveUnusedLayerRenderers = function(frameState) {
let layerKey; for (const layerKey in this.layerRenderers_) {
for (layerKey in this.layerRenderers_) {
if (!(layerKey in frameState.layerStates)) { if (!(layerKey in frameState.layerStates)) {
frameState.postRenderFunctions.push( frameState.postRenderFunctions.push(
/** @type {ol.PostRenderFunction} */ (this.removeUnusedLayerRenderers_.bind(this)) /** @type {ol.PostRenderFunction} */ (this.removeUnusedLayerRenderers_.bind(this))

View File

@@ -299,10 +299,9 @@ WebGLTileLayerRenderer.prototype.prepareFrame = function(frameState, layerState,
const zs = Object.keys(tilesToDrawByZ).map(Number); const zs = Object.keys(tilesToDrawByZ).map(Number);
zs.sort(numberSafeCompareFunction); zs.sort(numberSafeCompareFunction);
const u_tileOffset = new Float32Array(4); const u_tileOffset = new Float32Array(4);
let i, ii, tileKey, tilesToDraw; for (let i = 0, ii = zs.length; i < ii; ++i) {
for (i = 0, ii = zs.length; i < ii; ++i) { const tilesToDraw = tilesToDrawByZ[zs[i]];
tilesToDraw = tilesToDrawByZ[zs[i]]; for (const tileKey in tilesToDraw) {
for (tileKey in tilesToDraw) {
tile = tilesToDraw[tileKey]; tile = tilesToDraw[tileKey];
tileExtent = tileGrid.getTileCoordExtent(tile.tileCoord, tmpExtent); tileExtent = tileGrid.getTileCoordExtent(tile.tileCoord, tmpExtent);
u_tileOffset[0] = 2 * (tileExtent[2] - tileExtent[0]) / u_tileOffset[0] = 2 * (tileExtent[2] - tileExtent[0]) /

View File

@@ -253,23 +253,21 @@ VectorSource.prototype.addFeatures = function(features) {
* @protected * @protected
*/ */
VectorSource.prototype.addFeaturesInternal = function(features) { VectorSource.prototype.addFeaturesInternal = function(features) {
let featureKey, i, length, feature;
const extents = []; const extents = [];
const newFeatures = []; const newFeatures = [];
const geometryFeatures = []; const geometryFeatures = [];
for (i = 0, length = features.length; i < length; i++) { for (let i = 0, length = features.length; i < length; i++) {
feature = features[i]; const feature = features[i];
featureKey = getUid(feature).toString(); const featureKey = getUid(feature).toString();
if (this.addToIndex_(featureKey, feature)) { if (this.addToIndex_(featureKey, feature)) {
newFeatures.push(feature); newFeatures.push(feature);
} }
} }
for (i = 0, length = newFeatures.length; i < length; i++) { for (let i = 0, length = newFeatures.length; i < length; i++) {
feature = newFeatures[i]; const feature = newFeatures[i];
featureKey = getUid(feature).toString(); const featureKey = getUid(feature).toString();
this.setupChangeEvents_(featureKey, feature); this.setupChangeEvents_(featureKey, feature);
const geometry = feature.getGeometry(); const geometry = feature.getGeometry();
@@ -285,9 +283,8 @@ VectorSource.prototype.addFeaturesInternal = function(features) {
this.featuresRtree_.load(extents, geometryFeatures); this.featuresRtree_.load(extents, geometryFeatures);
} }
for (i = 0, length = newFeatures.length; i < length; i++) { for (let i = 0, length = newFeatures.length; i < length; i++) {
this.dispatchEvent(new VectorSource.Event( this.dispatchEvent(new VectorSource.Event(VectorEventType.ADDFEATURE, newFeatures[i]));
VectorEventType.ADDFEATURE, newFeatures[i]));
} }
}; };
@@ -735,8 +732,7 @@ VectorSource.prototype.loadFeatures = function(
extent, resolution, projection) { extent, resolution, projection) {
const loadedExtentsRtree = this.loadedExtentsRtree_; const loadedExtentsRtree = this.loadedExtentsRtree_;
const extentsToLoad = this.strategy_(extent, resolution); const extentsToLoad = this.strategy_(extent, resolution);
let i, ii; for (let i = 0, ii = extentsToLoad.length; i < ii; ++i) {
for (i = 0, ii = extentsToLoad.length; i < ii; ++i) {
const extentToLoad = extentsToLoad[i]; const extentToLoad = extentsToLoad[i];
const alreadyLoaded = loadedExtentsRtree.forEachInExtent(extentToLoad, const alreadyLoaded = loadedExtentsRtree.forEachInExtent(extentToLoad,
/** /**

View File

@@ -71,8 +71,7 @@ const Zoomify = function(opt_options) {
const resolutions = [1]; const resolutions = [1];
const tileCountUpToTier = [0]; const tileCountUpToTier = [0];
let i, ii; for (let i = 1, ii = tierSizeInTiles.length; i < ii; i++) {
for (i = 1, ii = tierSizeInTiles.length; i < ii; i++) {
resolutions.push(1 << i); resolutions.push(1 << i);
tileCountUpToTier.push( tileCountUpToTier.push(
tierSizeInTiles[i - 1][0] * tierSizeInTiles[i - 1][1] + tierSizeInTiles[i - 1][0] * tierSizeInTiles[i - 1][1] +

View File

@@ -56,9 +56,8 @@ IconImageCache.prototype.clear = function() {
IconImageCache.prototype.expire = function() { IconImageCache.prototype.expire = function() {
if (this.cacheSize_ > this.maxCacheSize_) { if (this.cacheSize_ > this.maxCacheSize_) {
let i = 0; let i = 0;
let key, iconImage; for (const key in this.cache_) {
for (key in this.cache_) { const iconImage = this.cache_[key];
iconImage = this.cache_[key];
if ((i++ & 3) === 0 && !iconImage.hasListener()) { if ((i++ & 3) === 0 && !iconImage.hasListener()) {
delete this.cache_[key]; delete this.cache_[key];
--this.cacheSize_; --this.cacheSize_;

View File

@@ -148,14 +148,13 @@ _ol_webgl_Context_.prototype.disposeInternal = function() {
_ol_events_.unlistenAll(this.canvas_); _ol_events_.unlistenAll(this.canvas_);
const gl = this.getGL(); const gl = this.getGL();
if (!gl.isContextLost()) { if (!gl.isContextLost()) {
let key; for (const key in this.bufferCache_) {
for (key in this.bufferCache_) {
gl.deleteBuffer(this.bufferCache_[key].buffer); gl.deleteBuffer(this.bufferCache_[key].buffer);
} }
for (key in this.programCache_) { for (const key in this.programCache_) {
gl.deleteProgram(this.programCache_[key]); gl.deleteProgram(this.programCache_[key]);
} }
for (key in this.shaderCache_) { for (const key in this.shaderCache_) {
gl.deleteShader(this.shaderCache_[key]); gl.deleteShader(this.shaderCache_[key]);
} }
// delete objects for hit-detection // delete objects for hit-detection