diff --git a/src/ol/control/scalelinecontrol.js b/src/ol/control/scalelinecontrol.js index c5880528c3..f8a2db6cca 100644 --- a/src/ol/control/scalelinecontrol.js +++ b/src/ol/control/scalelinecontrol.js @@ -8,14 +8,10 @@ goog.require('goog.events'); goog.require('goog.style'); goog.require('ol'); goog.require('ol.Object'); -goog.require('ol.TransformFunction'); goog.require('ol.control.Control'); goog.require('ol.css'); -goog.require('ol.math'); -goog.require('ol.proj'); goog.require('ol.proj.METERS_PER_UNIT'); goog.require('ol.proj.Units'); -goog.require('ol.sphere.NORMAL'); /** @@ -106,12 +102,6 @@ ol.control.ScaleLine = function(opt_options) { */ this.renderedHTML_ = ''; - /** - * @private - * @type {?ol.TransformFunction} - */ - this.toEPSG4326_ = null; - var render = options.render ? options.render : ol.control.ScaleLine.render; goog.base(this, { @@ -203,61 +193,21 @@ ol.control.ScaleLine.prototype.updateElement_ = function() { var center = viewState.center; var projection = viewState.projection; + var metersPerUnit = projection.getMetersPerUnit(); var pointResolution = - projection.getPointResolution(viewState.resolution, center); - var projectionUnits = projection.getUnits(); - - var cosLatitude; - var units = this.getUnits(); - if (projectionUnits == ol.proj.Units.DEGREES && - (units == ol.control.ScaleLineUnits.METRIC || - units == ol.control.ScaleLineUnits.IMPERIAL || - units == ol.control.ScaleLineUnits.US || - units == ol.control.ScaleLineUnits.NAUTICAL)) { - - // Convert pointResolution from degrees to meters - this.toEPSG4326_ = null; - cosLatitude = Math.cos(ol.math.toRadians(center[1])); - pointResolution *= Math.PI * cosLatitude * ol.sphere.NORMAL.radius / 180; - projectionUnits = ol.proj.Units.METERS; - - } else if (projectionUnits != ol.proj.Units.DEGREES && - units == ol.control.ScaleLineUnits.DEGREES) { - - // Convert pointResolution from other units to degrees - if (!this.toEPSG4326_) { - this.toEPSG4326_ = ol.proj.getTransformFromProjections( - projection, ol.proj.get('EPSG:4326')); - } - cosLatitude = Math.cos(ol.math.toRadians(this.toEPSG4326_(center)[1])); - var radius = ol.sphere.NORMAL.radius; - goog.asserts.assert(ol.proj.METERS_PER_UNIT[projectionUnits], - 'Meters per unit should be defined for the projection unit'); - radius /= ol.proj.METERS_PER_UNIT[projectionUnits]; - pointResolution *= 180 / (Math.PI * cosLatitude * radius); - projectionUnits = ol.proj.Units.DEGREES; - - } else { - this.toEPSG4326_ = null; - } - - goog.asserts.assert( - ((units == ol.control.ScaleLineUnits.METRIC || - units == ol.control.ScaleLineUnits.IMPERIAL || - units == ol.control.ScaleLineUnits.US || - units == ol.control.ScaleLineUnits.NAUTICAL) && - projectionUnits == ol.proj.Units.METERS) || - (units == ol.control.ScaleLineUnits.DEGREES && - projectionUnits == ol.proj.Units.DEGREES), - 'Scale line units and projection units should match'); + projection.getPointResolution(viewState.resolution, center) * + metersPerUnit; var nominalCount = this.minWidth_ * pointResolution; var suffix = ''; + var units = this.getUnits(); if (units == ol.control.ScaleLineUnits.DEGREES) { - if (nominalCount < 1 / 60) { + var metersPerDegree = ol.proj.METERS_PER_UNIT[ol.proj.Units.DEGREES]; + pointResolution /= metersPerDegree; + if (nominalCount < metersPerDegree / 60) { suffix = '\u2033'; // seconds pointResolution *= 3600; - } else if (nominalCount < 1) { + } else if (nominalCount < metersPerDegree) { suffix = '\u2032'; // minutes pointResolution *= 60; } else {