Dedicated module for scale line units enum
This commit is contained in:
+2
-2
@@ -1391,7 +1391,7 @@ olx.control.OverviewMapOptions.prototype.view;
|
|||||||
* minWidth: (number|undefined),
|
* minWidth: (number|undefined),
|
||||||
* render: (function(ol.MapEvent)|undefined),
|
* render: (function(ol.MapEvent)|undefined),
|
||||||
* target: (Element|undefined),
|
* target: (Element|undefined),
|
||||||
* units: (ol.control.ScaleLine.Units|string|undefined)}}
|
* units: (ol.control.ScaleLineUnits|string|undefined)}}
|
||||||
*/
|
*/
|
||||||
olx.control.ScaleLineOptions;
|
olx.control.ScaleLineOptions;
|
||||||
|
|
||||||
@@ -1431,7 +1431,7 @@ olx.control.ScaleLineOptions.prototype.target;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Units. Default is `metric`.
|
* Units. Default is `metric`.
|
||||||
* @type {ol.control.ScaleLine.Units|string|undefined}
|
* @type {ol.control.ScaleLineUnits|string|undefined}
|
||||||
* @api stable
|
* @api stable
|
||||||
*/
|
*/
|
||||||
olx.control.ScaleLineOptions.prototype.units;
|
olx.control.ScaleLineOptions.prototype.units;
|
||||||
|
|||||||
+11
-24
@@ -4,6 +4,7 @@ goog.require('ol');
|
|||||||
goog.require('ol.Object');
|
goog.require('ol.Object');
|
||||||
goog.require('ol.asserts');
|
goog.require('ol.asserts');
|
||||||
goog.require('ol.control.Control');
|
goog.require('ol.control.Control');
|
||||||
|
goog.require('ol.control.ScaleLineUnits');
|
||||||
goog.require('ol.css');
|
goog.require('ol.css');
|
||||||
goog.require('ol.events');
|
goog.require('ol.events');
|
||||||
goog.require('ol.proj');
|
goog.require('ol.proj');
|
||||||
@@ -88,8 +89,8 @@ ol.control.ScaleLine = function(opt_options) {
|
|||||||
this, ol.Object.getChangeEventType(ol.control.ScaleLine.Property_.UNITS),
|
this, ol.Object.getChangeEventType(ol.control.ScaleLine.Property_.UNITS),
|
||||||
this.handleUnitsChanged_, this);
|
this.handleUnitsChanged_, this);
|
||||||
|
|
||||||
this.setUnits(/** @type {ol.control.ScaleLine.Units} */ (options.units) ||
|
this.setUnits(/** @type {ol.control.ScaleLineUnits} */ (options.units) ||
|
||||||
ol.control.ScaleLine.Units.METRIC);
|
ol.control.ScaleLineUnits.METRIC);
|
||||||
|
|
||||||
};
|
};
|
||||||
ol.inherits(ol.control.ScaleLine, ol.control.Control);
|
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 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.
|
* line.
|
||||||
* @observable
|
* @observable
|
||||||
* @api stable
|
* @api stable
|
||||||
*/
|
*/
|
||||||
ol.control.ScaleLine.prototype.getUnits = function() {
|
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));
|
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.
|
* 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
|
* @observable
|
||||||
* @api stable
|
* @api stable
|
||||||
*/
|
*/
|
||||||
@@ -175,7 +176,7 @@ ol.control.ScaleLine.prototype.updateElement_ = function() {
|
|||||||
var nominalCount = this.minWidth_ * pointResolution;
|
var nominalCount = this.minWidth_ * pointResolution;
|
||||||
var suffix = '';
|
var suffix = '';
|
||||||
var units = this.getUnits();
|
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];
|
var metersPerDegree = ol.proj.METERS_PER_UNIT[ol.proj.Units.DEGREES];
|
||||||
pointResolution /= metersPerDegree;
|
pointResolution /= metersPerDegree;
|
||||||
if (nominalCount < metersPerDegree / 60) {
|
if (nominalCount < metersPerDegree / 60) {
|
||||||
@@ -187,7 +188,7 @@ ol.control.ScaleLine.prototype.updateElement_ = function() {
|
|||||||
} else {
|
} else {
|
||||||
suffix = '\u00b0'; // degrees
|
suffix = '\u00b0'; // degrees
|
||||||
}
|
}
|
||||||
} else if (units == ol.control.ScaleLine.Units.IMPERIAL) {
|
} else if (units == ol.control.ScaleLineUnits.IMPERIAL) {
|
||||||
if (nominalCount < 0.9144) {
|
if (nominalCount < 0.9144) {
|
||||||
suffix = 'in';
|
suffix = 'in';
|
||||||
pointResolution /= 0.0254;
|
pointResolution /= 0.0254;
|
||||||
@@ -198,10 +199,10 @@ ol.control.ScaleLine.prototype.updateElement_ = function() {
|
|||||||
suffix = 'mi';
|
suffix = 'mi';
|
||||||
pointResolution /= 1609.344;
|
pointResolution /= 1609.344;
|
||||||
}
|
}
|
||||||
} else if (units == ol.control.ScaleLine.Units.NAUTICAL) {
|
} else if (units == ol.control.ScaleLineUnits.NAUTICAL) {
|
||||||
pointResolution /= 1852;
|
pointResolution /= 1852;
|
||||||
suffix = 'nm';
|
suffix = 'nm';
|
||||||
} else if (units == ol.control.ScaleLine.Units.METRIC) {
|
} else if (units == ol.control.ScaleLineUnits.METRIC) {
|
||||||
if (nominalCount < 1) {
|
if (nominalCount < 1) {
|
||||||
suffix = 'mm';
|
suffix = 'mm';
|
||||||
pointResolution *= 1000;
|
pointResolution *= 1000;
|
||||||
@@ -211,7 +212,7 @@ ol.control.ScaleLine.prototype.updateElement_ = function() {
|
|||||||
suffix = 'km';
|
suffix = 'km';
|
||||||
pointResolution /= 1000;
|
pointResolution /= 1000;
|
||||||
}
|
}
|
||||||
} else if (units == ol.control.ScaleLine.Units.US) {
|
} else if (units == ol.control.ScaleLineUnits.US) {
|
||||||
if (nominalCount < 0.9144) {
|
if (nominalCount < 0.9144) {
|
||||||
suffix = 'in';
|
suffix = 'in';
|
||||||
pointResolution *= 39.37;
|
pointResolution *= 39.37;
|
||||||
@@ -269,17 +270,3 @@ ol.control.ScaleLine.prototype.updateElement_ = function() {
|
|||||||
ol.control.ScaleLine.Property_ = {
|
ol.control.ScaleLine.Property_ = {
|
||||||
UNITS: 'units'
|
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'
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
goog.provide('ol.control.ScaleLineUnits');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Units for the scale line. Supported values are `'degrees'`, `'imperial'`,
|
||||||
|
* `'nautical'`, `'metric'`, `'us'`.
|
||||||
|
* @enum {string}
|
||||||
|
*/
|
||||||
|
ol.control.ScaleLineUnits = {
|
||||||
|
DEGREES: 'degrees',
|
||||||
|
IMPERIAL: 'imperial',
|
||||||
|
NAUTICAL: 'nautical',
|
||||||
|
METRIC: 'metric',
|
||||||
|
US: 'us'
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user