Dedicated module for scale line units enum

This commit is contained in:
Tim Schaub
2016-12-27 13:15:35 -07:00
parent c4b75f79c1
commit 511e21ce5f
3 changed files with 27 additions and 26 deletions

View File

@@ -4,6 +4,7 @@ goog.require('ol');
goog.require('ol.Object');
goog.require('ol.asserts');
goog.require('ol.control.Control');
goog.require('ol.control.ScaleLineUnits');
goog.require('ol.css');
goog.require('ol.events');
goog.require('ol.proj');
@@ -88,8 +89,8 @@ ol.control.ScaleLine = function(opt_options) {
this, ol.Object.getChangeEventType(ol.control.ScaleLine.Property_.UNITS),
this.handleUnitsChanged_, this);
this.setUnits(/** @type {ol.control.ScaleLine.Units} */ (options.units) ||
ol.control.ScaleLine.Units.METRIC);
this.setUnits(/** @type {ol.control.ScaleLineUnits} */ (options.units) ||
ol.control.ScaleLineUnits.METRIC);
};
ol.inherits(ol.control.ScaleLine, ol.control.Control);
@@ -104,13 +105,13 @@ ol.control.ScaleLine.LEADING_DIGITS = [1, 2, 5];
/**
* Return the units to use in the scale line.
* @return {ol.control.ScaleLine.Units|undefined} The units to use in the scale
* @return {ol.control.ScaleLineUnits|undefined} The units to use in the scale
* line.
* @observable
* @api stable
*/
ol.control.ScaleLine.prototype.getUnits = function() {
return /** @type {ol.control.ScaleLine.Units|undefined} */ (
return /** @type {ol.control.ScaleLineUnits|undefined} */ (
this.get(ol.control.ScaleLine.Property_.UNITS));
};
@@ -142,7 +143,7 @@ ol.control.ScaleLine.prototype.handleUnitsChanged_ = function() {
/**
* Set the units to use in the scale line.
* @param {ol.control.ScaleLine.Units} units The units to use in the scale line.
* @param {ol.control.ScaleLineUnits} units The units to use in the scale line.
* @observable
* @api stable
*/
@@ -175,7 +176,7 @@ ol.control.ScaleLine.prototype.updateElement_ = function() {
var nominalCount = this.minWidth_ * pointResolution;
var suffix = '';
var units = this.getUnits();
if (units == ol.control.ScaleLine.Units.DEGREES) {
if (units == ol.control.ScaleLineUnits.DEGREES) {
var metersPerDegree = ol.proj.METERS_PER_UNIT[ol.proj.Units.DEGREES];
pointResolution /= metersPerDegree;
if (nominalCount < metersPerDegree / 60) {
@@ -187,7 +188,7 @@ ol.control.ScaleLine.prototype.updateElement_ = function() {
} else {
suffix = '\u00b0'; // degrees
}
} else if (units == ol.control.ScaleLine.Units.IMPERIAL) {
} else if (units == ol.control.ScaleLineUnits.IMPERIAL) {
if (nominalCount < 0.9144) {
suffix = 'in';
pointResolution /= 0.0254;
@@ -198,10 +199,10 @@ ol.control.ScaleLine.prototype.updateElement_ = function() {
suffix = 'mi';
pointResolution /= 1609.344;
}
} else if (units == ol.control.ScaleLine.Units.NAUTICAL) {
} else if (units == ol.control.ScaleLineUnits.NAUTICAL) {
pointResolution /= 1852;
suffix = 'nm';
} else if (units == ol.control.ScaleLine.Units.METRIC) {
} else if (units == ol.control.ScaleLineUnits.METRIC) {
if (nominalCount < 1) {
suffix = 'mm';
pointResolution *= 1000;
@@ -211,7 +212,7 @@ ol.control.ScaleLine.prototype.updateElement_ = function() {
suffix = 'km';
pointResolution /= 1000;
}
} else if (units == ol.control.ScaleLine.Units.US) {
} else if (units == ol.control.ScaleLineUnits.US) {
if (nominalCount < 0.9144) {
suffix = 'in';
pointResolution *= 39.37;
@@ -269,17 +270,3 @@ ol.control.ScaleLine.prototype.updateElement_ = function() {
ol.control.ScaleLine.Property_ = {
UNITS: 'units'
};
/**
* Units for the scale line. Supported values are `'degrees'`, `'imperial'`,
* `'nautical'`, `'metric'`, `'us'`.
* @enum {string}
*/
ol.control.ScaleLine.Units = {
DEGREES: 'degrees',
IMPERIAL: 'imperial',
NAUTICAL: 'nautical',
METRIC: 'metric',
US: 'us'
};