Remove Goog.string

This commit is contained in:
nicholas
2016-03-26 16:34:36 +13:00
parent cd6494149b
commit c92223d792
6 changed files with 122 additions and 13 deletions

View File

@@ -2,8 +2,8 @@ goog.provide('ol.Coordinate');
goog.provide('ol.CoordinateFormatType');
goog.provide('ol.coordinate');
goog.require('goog.string');
goog.require('ol.math');
goog.require('ol.string');
/**
@@ -133,8 +133,8 @@ ol.coordinate.degreesToStringHDMS_ = function(degrees, hemispheres, opt_fraction
var x = Math.abs(3600 * normalizedDegrees);
var dflPrecision = opt_fractionDigits || 0;
return Math.floor(x / 3600) + '\u00b0 ' +
goog.string.padNumber(Math.floor((x / 60) % 60), 2) + '\u2032 ' +
goog.string.padNumber((x % 60), 2, dflPrecision) + '\u2033 ' +
ol.string.padNumber(Math.floor((x / 60) % 60), 2) + '\u2032 ' +
ol.string.padNumber((x % 60), 2, dflPrecision) + '\u2033 ' +
hemispheres.charAt(normalizedDegrees < 0 ? 1 : 0);
};

View File

@@ -1,9 +1,9 @@
goog.provide('ol.format.XSD');
goog.require('goog.asserts');
goog.require('goog.string');
goog.require('ol');
goog.require('ol.xml');
goog.require('ol.string');
/**
@@ -142,11 +142,11 @@ ol.format.XSD.writeBooleanTextNode = function(node, bool) {
ol.format.XSD.writeDateTimeTextNode = function(node, dateTime) {
var date = new Date(dateTime * 1000);
var string = date.getUTCFullYear() + '-' +
goog.string.padNumber(date.getUTCMonth() + 1, 2) + '-' +
goog.string.padNumber(date.getUTCDate(), 2) + 'T' +
goog.string.padNumber(date.getUTCHours(), 2) + ':' +
goog.string.padNumber(date.getUTCMinutes(), 2) + ':' +
goog.string.padNumber(date.getUTCSeconds(), 2) + 'Z';
ol.string.padNumber(date.getUTCMonth() + 1, 2) + '-' +
ol.string.padNumber(date.getUTCDate(), 2) + 'T' +
ol.string.padNumber(date.getUTCHours(), 2) + ':' +
ol.string.padNumber(date.getUTCMinutes(), 2) + ':' +
ol.string.padNumber(date.getUTCSeconds(), 2) + 'Z';
node.appendChild(ol.xml.DOCUMENT.createTextNode(string));
};

View File

@@ -3,7 +3,6 @@
goog.provide('ol.source.ImageWMS');
goog.require('goog.asserts');
goog.require('goog.string');
goog.require('goog.uri.utils');
goog.require('ol');
goog.require('ol.Image');
@@ -16,6 +15,7 @@ goog.require('ol.proj');
goog.require('ol.source.Image');
goog.require('ol.source.wms');
goog.require('ol.source.wms.ServerType');
goog.require('ol.string');
/**
@@ -372,5 +372,5 @@ ol.source.ImageWMS.prototype.updateParams = function(params) {
*/
ol.source.ImageWMS.prototype.updateV13_ = function() {
var version = this.params_['VERSION'] || ol.DEFAULT_WMS_VERSION;
this.v13_ = goog.string.compareVersions(version, '1.3') >= 0;
this.v13_ = ol.string.compareVersions(version, '1.3') >= 0;
};

View File

@@ -5,7 +5,6 @@
goog.provide('ol.source.TileWMS');
goog.require('goog.asserts');
goog.require('goog.string');
goog.require('goog.uri.utils');
goog.require('ol');
goog.require('ol.TileCoord');
@@ -18,6 +17,7 @@ goog.require('ol.source.TileImage');
goog.require('ol.source.wms');
goog.require('ol.source.wms.ServerType');
goog.require('ol.tilecoord');
goog.require('ol.string');
/**
@@ -390,5 +390,5 @@ ol.source.TileWMS.prototype.updateParams = function(params) {
*/
ol.source.TileWMS.prototype.updateV13_ = function() {
var version = this.params_['VERSION'] || ol.DEFAULT_WMS_VERSION;
this.v13_ = goog.string.compareVersions(version, '1.3') >= 0;
this.v13_ = ol.string.compareVersions(version, '1.3') >= 0;
};

35
src/ol/string.js Normal file
View File

@@ -0,0 +1,35 @@
goog.provide('ol.string');
/**
* @param {number} number Number to be formatted
* @param {number} width The desired width
* @param {number=} opt_precision Precision of the output string (i.e. number of decimal places)
* @returns {string} Formatted string
*/
ol.string.padNumber = function(number, width, opt_precision) {
var numberString = opt_precision !== undefined ? number.toFixed(opt_precision) : '' + number;
var decimal = numberString.indexOf('.');
decimal = decimal === -1 ? numberString.length : decimal;
return decimal > width ? numberString : new Array(1 + width - decimal).join('0') + numberString;
};
/**
* Adapted from https://github.com/omichelsen/compare-versions/blob/master/index.js
* @param {string|number} v1 First version
* @param {string|number} v2 Second version
* @returns {number} Value
*/
ol.string.compareVersions = function(v1, v2) {
var s1 = ('' + v1).split('.');
var s2 = ('' + v2).split('.');
for (var i = 0; i < Math.max(s1.length, s2.length); i++) {
var n1 = parseInt(s1[i] || '0', 10);
var n2 = parseInt(s2[i] || '0', 10);
if (n1 > n2) return 1;
if (n2 > n1) return -1;
}
return 0;
};