From 40236fbd8b4f287c8e6293bbda2b677bc48de863 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Tue, 19 Jun 2018 16:17:05 +0200 Subject: [PATCH 1/2] Remove local variables in ol/Graticule --- src/ol/Graticule.js | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/src/ol/Graticule.js b/src/ol/Graticule.js index af0e44f3eb..50450bdbb0 100644 --- a/src/ol/Graticule.js +++ b/src/ol/Graticule.js @@ -245,21 +245,20 @@ const Graticule = function(opt_options) { this.parallelsLabels_ = null; if (options.showLabels == true) { - const degreesToString = degreesToStringHDMS; /** * @type {null|function(number):string} * @private */ this.lonLabelFormatter_ = options.lonLabelFormatter == undefined ? - degreesToString.bind(this, 'EW') : options.lonLabelFormatter; + degreesToStringHDMS.bind(this, 'EW') : options.lonLabelFormatter; /** * @type {function(number):string} * @private */ this.latLabelFormatter_ = options.latLabelFormatter == undefined ? - degreesToString.bind(this, 'NS') : options.latLabelFormatter; + degreesToStringHDMS.bind(this, 'NS') : options.latLabelFormatter; /** * Longitude label position in fractions (0..1) of view extent. 0 means @@ -671,36 +670,24 @@ Graticule.prototype.handlePostCompose_ = function(e) { Graticule.prototype.updateProjectionInfo_ = function(projection) { const epsg4326Projection = getProjection('EPSG:4326'); - const extent = projection.getExtent(); const worldExtent = projection.getWorldExtent(); const worldExtentP = transformExtent(worldExtent, epsg4326Projection, projection); - const maxLat = worldExtent[3]; - const maxLon = worldExtent[2]; - const minLat = worldExtent[1]; - const minLon = worldExtent[0]; - - const maxLatP = worldExtentP[3]; - const maxLonP = worldExtentP[2]; - const minLatP = worldExtentP[1]; - const minLonP = worldExtentP[0]; - - this.maxLat_ = maxLat; - this.maxLon_ = maxLon; - this.minLat_ = minLat; - this.minLon_ = minLon; - - this.maxLatP_ = maxLatP; - this.maxLonP_ = maxLonP; - this.minLatP_ = minLatP; - this.minLonP_ = minLonP; + this.maxLat_ = worldExtent[3]; + this.maxLon_ = worldExtent[2]; + this.minLat_ = worldExtent[1]; + this.minLon_ = worldExtent[0]; + this.maxLatP_ = worldExtentP[3]; + this.maxLonP_ = worldExtentP[2]; + this.minLatP_ = worldExtentP[1]; + this.minLonP_ = worldExtentP[0]; this.fromLonLatTransform_ = getTransform(epsg4326Projection, projection); this.toLonLatTransform_ = getTransform(projection, epsg4326Projection); - this.projectionCenterLonLat_ = this.toLonLatTransform_(getCenter(extent)); + this.projectionCenterLonLat_ = this.toLonLatTransform_(getCenter(projection.getExtent())); this.projection_ = projection; }; From e91fde00c945305bda03ed1f74d14634243532a4 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Tue, 19 Jun 2018 16:19:06 +0200 Subject: [PATCH 2/2] Better variables scoping --- src/ol/Graticule.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/ol/Graticule.js b/src/ol/Graticule.js index 50450bdbb0..431e9c12df 100644 --- a/src/ol/Graticule.js +++ b/src/ol/Graticule.js @@ -519,21 +519,20 @@ Graticule.prototype.getInterval_ = function(resolution) { const centerLon = this.projectionCenterLonLat_[0]; const centerLat = this.projectionCenterLonLat_[1]; let interval = -1; - let i, ii, delta, dist; const target = Math.pow(this.targetSize_ * resolution, 2); /** @type {Array.} **/ const p1 = []; /** @type {Array.} **/ const p2 = []; - for (i = 0, ii = INTERVALS.length; i < ii; ++i) { - delta = INTERVALS[i] / 2; + for (let i = 0, ii = INTERVALS.length; i < ii; ++i) { + const delta = INTERVALS[i] / 2; p1[0] = centerLon - delta; p1[1] = centerLat - delta; p2[0] = centerLon + delta; p2[1] = centerLat + delta; this.fromLonLatTransform_(p1, p1); this.fromLonLatTransform_(p2, p2); - dist = Math.pow(p2[0] - p1[0], 2) + Math.pow(p2[1] - p1[1], 2); + const dist = Math.pow(p2[0] - p1[0], 2) + Math.pow(p2[1] - p1[1], 2); if (dist <= target) { break; }