Merge pull request #8291 from fredj/graticule_cleanup

Graticule code cleanup
This commit is contained in:
Frédéric Junod
2018-06-21 08:19:29 +02:00
committed by GitHub

View File

@@ -245,21 +245,20 @@ const Graticule = function(opt_options) {
this.parallelsLabels_ = null; this.parallelsLabels_ = null;
if (options.showLabels == true) { if (options.showLabels == true) {
const degreesToString = degreesToStringHDMS;
/** /**
* @type {null|function(number):string} * @type {null|function(number):string}
* @private * @private
*/ */
this.lonLabelFormatter_ = options.lonLabelFormatter == undefined ? this.lonLabelFormatter_ = options.lonLabelFormatter == undefined ?
degreesToString.bind(this, 'EW') : options.lonLabelFormatter; degreesToStringHDMS.bind(this, 'EW') : options.lonLabelFormatter;
/** /**
* @type {function(number):string} * @type {function(number):string}
* @private * @private
*/ */
this.latLabelFormatter_ = options.latLabelFormatter == undefined ? 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 * Longitude label position in fractions (0..1) of view extent. 0 means
@@ -520,21 +519,20 @@ Graticule.prototype.getInterval_ = function(resolution) {
const centerLon = this.projectionCenterLonLat_[0]; const centerLon = this.projectionCenterLonLat_[0];
const centerLat = this.projectionCenterLonLat_[1]; const centerLat = this.projectionCenterLonLat_[1];
let interval = -1; let interval = -1;
let i, ii, delta, dist;
const target = Math.pow(this.targetSize_ * resolution, 2); const target = Math.pow(this.targetSize_ * resolution, 2);
/** @type {Array.<number>} **/ /** @type {Array.<number>} **/
const p1 = []; const p1 = [];
/** @type {Array.<number>} **/ /** @type {Array.<number>} **/
const p2 = []; const p2 = [];
for (i = 0, ii = INTERVALS.length; i < ii; ++i) { for (let i = 0, ii = INTERVALS.length; i < ii; ++i) {
delta = INTERVALS[i] / 2; const delta = INTERVALS[i] / 2;
p1[0] = centerLon - delta; p1[0] = centerLon - delta;
p1[1] = centerLat - delta; p1[1] = centerLat - delta;
p2[0] = centerLon + delta; p2[0] = centerLon + delta;
p2[1] = centerLat + delta; p2[1] = centerLat + delta;
this.fromLonLatTransform_(p1, p1); this.fromLonLatTransform_(p1, p1);
this.fromLonLatTransform_(p2, p2); 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) { if (dist <= target) {
break; break;
} }
@@ -671,36 +669,24 @@ Graticule.prototype.handlePostCompose_ = function(e) {
Graticule.prototype.updateProjectionInfo_ = function(projection) { Graticule.prototype.updateProjectionInfo_ = function(projection) {
const epsg4326Projection = getProjection('EPSG:4326'); const epsg4326Projection = getProjection('EPSG:4326');
const extent = projection.getExtent();
const worldExtent = projection.getWorldExtent(); const worldExtent = projection.getWorldExtent();
const worldExtentP = transformExtent(worldExtent, epsg4326Projection, projection); const worldExtentP = transformExtent(worldExtent, epsg4326Projection, projection);
const maxLat = worldExtent[3]; this.maxLat_ = worldExtent[3];
const maxLon = worldExtent[2]; this.maxLon_ = worldExtent[2];
const minLat = worldExtent[1]; this.minLat_ = worldExtent[1];
const minLon = worldExtent[0]; this.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.maxLatP_ = worldExtentP[3];
this.maxLonP_ = worldExtentP[2];
this.minLatP_ = worldExtentP[1];
this.minLonP_ = worldExtentP[0];
this.fromLonLatTransform_ = getTransform(epsg4326Projection, projection); this.fromLonLatTransform_ = getTransform(epsg4326Projection, projection);
this.toLonLatTransform_ = getTransform(projection, epsg4326Projection); this.toLonLatTransform_ = getTransform(projection, epsg4326Projection);
this.projectionCenterLonLat_ = this.toLonLatTransform_(getCenter(extent)); this.projectionCenterLonLat_ = this.toLonLatTransform_(getCenter(projection.getExtent()));
this.projection_ = projection; this.projection_ = projection;
}; };