diff --git a/examples/overlay-and-popup.js b/examples/overlay-and-popup.js index 660ab2f38f..4b9b9f7222 100644 --- a/examples/overlay-and-popup.js +++ b/examples/overlay-and-popup.js @@ -3,7 +3,6 @@ goog.require('goog.debug.Logger'); goog.require('goog.debug.Logger.Level'); goog.require('ol.Collection'); goog.require('ol.Coordinate'); -goog.require('ol.CoordinateFormat'); goog.require('ol.Map'); goog.require('ol.overlay.Overlay'); goog.require('ol.source.MapQuestOpenAerial'); @@ -42,7 +41,7 @@ map.addEventListener('click', function(evt) { var coordinate = evt.getCoordinate(); popup.getElement().innerHTML = 'Welcome to ol3. The location you clicked was
' + - ol.CoordinateFormat.hdms(ol.Projection.transformWithCodes( + ol.Coordinate.toStringHDMS(ol.Projection.transformWithCodes( coordinate, 'EPSG:3857', 'EPSG:4326')); popup.setCoordinate(coordinate); }); diff --git a/examples/side-by-side.js b/examples/side-by-side.js index 61e9fdb3a5..5d7f531d31 100644 --- a/examples/side-by-side.js +++ b/examples/side-by-side.js @@ -1,7 +1,7 @@ goog.require('goog.debug.Console'); goog.require('goog.debug.Logger'); goog.require('goog.debug.Logger.Level'); -goog.require('ol.CoordinateFormat'); +goog.require('ol.Coordinate'); goog.require('ol.Map'); goog.require('ol.RendererHint'); goog.require('ol.control.MousePosition'); @@ -29,7 +29,7 @@ var domMap = new ol.Map({ }); domMap.getControls().push(new ol.control.MousePosition({ - coordinateFormat: ol.CoordinateFormat.hdms, + coordinateFormat: ol.Coordinate.toStringHDMS, projection: ol.Projection.getFromCode('EPSG:4326'), target: document.getElementById('domMousePosition'), undefinedHtml: ' ' @@ -47,7 +47,7 @@ if (webglMap !== null) { } webglMap.getControls().push(new ol.control.MousePosition({ - coordinateFormat: ol.CoordinateFormat.hdms, + coordinateFormat: ol.Coordinate.toStringHDMS, projection: ol.Projection.getFromCode('EPSG:4326'), target: document.getElementById('webglMousePosition'), undefinedHtml: ' ' diff --git a/src/ol/coordinate.js b/src/ol/coordinate.js index 38aa293044..255ea2bbf8 100644 --- a/src/ol/coordinate.js +++ b/src/ol/coordinate.js @@ -1,8 +1,16 @@ goog.provide('ol.Coordinate'); +goog.provide('ol.CoordinateFormatType'); +goog.require('goog.math'); goog.require('goog.math.Vec2'); +/** + * @typedef {function((ol.Coordinate|undefined)): string} + */ +ol.CoordinateFormatType; + + /** * @constructor @@ -21,3 +29,60 @@ goog.inherits(ol.Coordinate, goog.math.Vec2); * @type {ol.Coordinate} */ ol.Coordinate.ZERO = new ol.Coordinate(0, 0); + + +/** + * @param {number=} opt_precision Precision. + * @return {ol.CoordinateFormatType} Coordinate format. + */ +ol.Coordinate.createStringXY = function(opt_precision) { + return function(coordinate) { + return ol.Coordinate.toStringXY(coordinate, opt_precision); + }; +}; + + +/** + * @private + * @param {number} degrees Degrees. + * @param {string} hemispheres Hemispheres. + * @return {string} String. + */ +ol.Coordinate.degreesToStringHDMS_ = function(degrees, hemispheres) { + var normalizedDegrees = goog.math.modulo(degrees + 180, 360) - 180; + var x = Math.abs(Math.round(3600 * normalizedDegrees)); + return Math.floor(x / 3600) + '\u00b0 ' + + Math.floor((x / 60) % 60) + '\u2032 ' + + Math.floor(x % 60) + '\u2033 ' + + hemispheres.charAt(normalizedDegrees < 0 ? 1 : 0); +}; + + +/** + * @param {ol.Coordinate|undefined} coordinate Coordinate. + * @return {string} Hemisphere, degrees, minutes and seconds. + */ +ol.Coordinate.toStringHDMS = function(coordinate) { + if (goog.isDef(coordinate)) { + return ol.Coordinate.degreesToStringHDMS_(coordinate.y, 'NS') + ' ' + + ol.Coordinate.degreesToStringHDMS_(coordinate.x, 'EW'); + } else { + return ''; + } +}; + + +/** + * @param {ol.Coordinate|undefined} coordinate Coordinate. + * @param {number=} opt_precision Precision. + * @return {string} XY. + */ +ol.Coordinate.toStringXY = function(coordinate, opt_precision) { + if (goog.isDef(coordinate)) { + var precision = opt_precision || 0; + return coordinate.x.toFixed(precision) + ', ' + + coordinate.y.toFixed(precision); + } else { + return ''; + } +}; diff --git a/src/ol/coordinateformat.js b/src/ol/coordinateformat.js deleted file mode 100644 index a654b757a8..0000000000 --- a/src/ol/coordinateformat.js +++ /dev/null @@ -1,57 +0,0 @@ -goog.provide('ol.CoordinateFormat'); -goog.provide('ol.CoordinateFormatType'); - -goog.require('goog.math'); -goog.require('ol.Coordinate'); - - -/** - * @typedef {function((ol.Coordinate|undefined)): string} - */ -ol.CoordinateFormatType; - - -/** - * @param {number} precision Precision. - * @return {ol.CoordinateFormatType} Coordinate format. - */ -ol.CoordinateFormat.createXY = function(precision) { - return function(coordinate) { - if (goog.isDef(coordinate)) { - return coordinate.x.toFixed(precision) + ', ' + - coordinate.y.toFixed(precision); - } else { - return ''; - } - }; -}; - - -/** - * @private - * @param {number} degrees Degrees. - * @param {string} hemispheres Hemispheres. - * @return {string} String. - */ -ol.CoordinateFormat.degreesToHDMS_ = function(degrees, hemispheres) { - var normalizedDegrees = goog.math.modulo(degrees + 180, 360) - 180; - var x = Math.abs(Math.round(3600 * normalizedDegrees)); - return Math.floor(x / 3600) + '\u00b0 ' + - Math.floor((x / 60) % 60) + '\u2032 ' + - Math.floor(x % 60) + '\u2033 ' + - hemispheres.charAt(normalizedDegrees < 0 ? 1 : 0); -}; - - -/** - * @param {ol.Coordinate|undefined} coordinate Coordinate. - * @return {string} Coordinate format. - */ -ol.CoordinateFormat.hdms = function(coordinate) { - if (goog.isDef(coordinate)) { - return ol.CoordinateFormat.degreesToHDMS_(coordinate.y, 'NS') + ' ' + - ol.CoordinateFormat.degreesToHDMS_(coordinate.x, 'EW'); - } else { - return ''; - } -}; diff --git a/src/ol/exports.txt b/src/ol/exports.txt index f59f548c69..ecb405fba8 100644 --- a/src/ol/exports.txt +++ b/src/ol/exports.txt @@ -15,9 +15,7 @@ @exportProperty ol.Collection.prototype.setAt @exportSymbol ol.Coordinate - -@exportSymbol ol.CoordinateFormat -@exportProperty ol.CoordinateFormat.hdms +@exportProperty ol.Coordinate.toStringHDMS @exportSymbol ol.Extent