One provide from scaleline.js
This commit is contained in:
+2
-2
@@ -1260,7 +1260,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.ScaleLineUnits|string|undefined)}}
|
* units: (ol.control.ScaleLine.Units|string|undefined)}}
|
||||||
*/
|
*/
|
||||||
olx.control.ScaleLineOptions;
|
olx.control.ScaleLineOptions;
|
||||||
|
|
||||||
@@ -1300,7 +1300,7 @@ olx.control.ScaleLineOptions.prototype.target;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Units. Default is `metric`.
|
* Units. Default is `metric`.
|
||||||
* @type {ol.control.ScaleLineUnits|string|undefined}
|
* @type {ol.control.ScaleLine.Units|string|undefined}
|
||||||
* @api stable
|
* @api stable
|
||||||
*/
|
*/
|
||||||
olx.control.ScaleLineOptions.prototype.units;
|
olx.control.ScaleLineOptions.prototype.units;
|
||||||
|
|||||||
+38
-37
@@ -1,37 +1,15 @@
|
|||||||
goog.provide('ol.control.ScaleLine');
|
goog.provide('ol.control.ScaleLine');
|
||||||
goog.provide('ol.control.ScaleLineUnits');
|
|
||||||
|
|
||||||
goog.require('ol.events');
|
|
||||||
goog.require('ol');
|
goog.require('ol');
|
||||||
goog.require('ol.Object');
|
goog.require('ol.Object');
|
||||||
|
goog.require('ol.asserts');
|
||||||
goog.require('ol.control.Control');
|
goog.require('ol.control.Control');
|
||||||
goog.require('ol.css');
|
goog.require('ol.css');
|
||||||
|
goog.require('ol.events');
|
||||||
goog.require('ol.proj.METERS_PER_UNIT');
|
goog.require('ol.proj.METERS_PER_UNIT');
|
||||||
goog.require('ol.proj.Units');
|
goog.require('ol.proj.Units');
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @enum {string}
|
|
||||||
*/
|
|
||||||
ol.control.ScaleLineProperty = {
|
|
||||||
UNITS: 'units'
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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'
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @classdesc
|
* @classdesc
|
||||||
* A control displaying rough y-axis distances, calculated for the center of the
|
* A control displaying rough y-axis distances, calculated for the center of the
|
||||||
@@ -107,11 +85,11 @@ ol.control.ScaleLine = function(opt_options) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
ol.events.listen(
|
ol.events.listen(
|
||||||
this, ol.Object.getChangeEventType(ol.control.ScaleLineProperty.UNITS),
|
this, ol.Object.getChangeEventType(ol.control.ScaleLine.Property.UNITS),
|
||||||
this.handleUnitsChanged_, this);
|
this.handleUnitsChanged_, this);
|
||||||
|
|
||||||
this.setUnits(/** @type {ol.control.ScaleLineUnits} */ (options.units) ||
|
this.setUnits(/** @type {ol.control.ScaleLine.Units} */ (options.units) ||
|
||||||
ol.control.ScaleLineUnits.METRIC);
|
ol.control.ScaleLine.Units.METRIC);
|
||||||
|
|
||||||
};
|
};
|
||||||
ol.inherits(ol.control.ScaleLine, ol.control.Control);
|
ol.inherits(ol.control.ScaleLine, ol.control.Control);
|
||||||
@@ -126,14 +104,14 @@ 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.ScaleLineUnits|undefined} The units to use in the scale
|
* @return {ol.control.ScaleLine.Units|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.ScaleLineUnits|undefined} */ (
|
return /** @type {ol.control.ScaleLine.Units|undefined} */ (
|
||||||
this.get(ol.control.ScaleLineProperty.UNITS));
|
this.get(ol.control.ScaleLine.Property.UNITS));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -164,12 +142,12 @@ 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.ScaleLineUnits} units The units to use in the scale line.
|
* @param {ol.control.ScaleLine.Units} units The units to use in the scale line.
|
||||||
* @observable
|
* @observable
|
||||||
* @api stable
|
* @api stable
|
||||||
*/
|
*/
|
||||||
ol.control.ScaleLine.prototype.setUnits = function(units) {
|
ol.control.ScaleLine.prototype.setUnits = function(units) {
|
||||||
this.set(ol.control.ScaleLineProperty.UNITS, units);
|
this.set(ol.control.ScaleLine.Property.UNITS, units);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -197,7 +175,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.ScaleLineUnits.DEGREES) {
|
if (units == ol.control.ScaleLine.Units.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) {
|
||||||
@@ -209,7 +187,7 @@ ol.control.ScaleLine.prototype.updateElement_ = function() {
|
|||||||
} else {
|
} else {
|
||||||
suffix = '\u00b0'; // degrees
|
suffix = '\u00b0'; // degrees
|
||||||
}
|
}
|
||||||
} else if (units == ol.control.ScaleLineUnits.IMPERIAL) {
|
} else if (units == ol.control.ScaleLine.Units.IMPERIAL) {
|
||||||
if (nominalCount < 0.9144) {
|
if (nominalCount < 0.9144) {
|
||||||
suffix = 'in';
|
suffix = 'in';
|
||||||
pointResolution /= 0.0254;
|
pointResolution /= 0.0254;
|
||||||
@@ -220,10 +198,10 @@ ol.control.ScaleLine.prototype.updateElement_ = function() {
|
|||||||
suffix = 'mi';
|
suffix = 'mi';
|
||||||
pointResolution /= 1609.344;
|
pointResolution /= 1609.344;
|
||||||
}
|
}
|
||||||
} else if (units == ol.control.ScaleLineUnits.NAUTICAL) {
|
} else if (units == ol.control.ScaleLine.Units.NAUTICAL) {
|
||||||
pointResolution /= 1852;
|
pointResolution /= 1852;
|
||||||
suffix = 'nm';
|
suffix = 'nm';
|
||||||
} else if (units == ol.control.ScaleLineUnits.METRIC) {
|
} else if (units == ol.control.ScaleLine.Units.METRIC) {
|
||||||
if (nominalCount < 1) {
|
if (nominalCount < 1) {
|
||||||
suffix = 'mm';
|
suffix = 'mm';
|
||||||
pointResolution *= 1000;
|
pointResolution *= 1000;
|
||||||
@@ -233,7 +211,7 @@ ol.control.ScaleLine.prototype.updateElement_ = function() {
|
|||||||
suffix = 'km';
|
suffix = 'km';
|
||||||
pointResolution /= 1000;
|
pointResolution /= 1000;
|
||||||
}
|
}
|
||||||
} else if (units == ol.control.ScaleLineUnits.US) {
|
} else if (units == ol.control.ScaleLine.Units.US) {
|
||||||
if (nominalCount < 0.9144) {
|
if (nominalCount < 0.9144) {
|
||||||
suffix = 'in';
|
suffix = 'in';
|
||||||
pointResolution *= 39.37;
|
pointResolution *= 39.37;
|
||||||
@@ -282,3 +260,26 @@ ol.control.ScaleLine.prototype.updateElement_ = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @enum {string}
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
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'
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user