Merge pull request #66 from twpayne/coordinate-format-cleanup
Coordinate format cleanup
This commit is contained in:
@@ -3,7 +3,6 @@ goog.require('goog.debug.Logger');
|
|||||||
goog.require('goog.debug.Logger.Level');
|
goog.require('goog.debug.Logger.Level');
|
||||||
goog.require('ol.Collection');
|
goog.require('ol.Collection');
|
||||||
goog.require('ol.Coordinate');
|
goog.require('ol.Coordinate');
|
||||||
goog.require('ol.CoordinateFormat');
|
|
||||||
goog.require('ol.Map');
|
goog.require('ol.Map');
|
||||||
goog.require('ol.overlay.Overlay');
|
goog.require('ol.overlay.Overlay');
|
||||||
goog.require('ol.source.MapQuestOpenAerial');
|
goog.require('ol.source.MapQuestOpenAerial');
|
||||||
@@ -42,7 +41,7 @@ map.addEventListener('click', function(evt) {
|
|||||||
var coordinate = evt.getCoordinate();
|
var coordinate = evt.getCoordinate();
|
||||||
popup.getElement().innerHTML =
|
popup.getElement().innerHTML =
|
||||||
'Welcome to ol3. The location you clicked was<br>' +
|
'Welcome to ol3. The location you clicked was<br>' +
|
||||||
ol.CoordinateFormat.hdms(ol.Projection.transformWithCodes(
|
ol.Coordinate.toStringHDMS(ol.Projection.transformWithCodes(
|
||||||
coordinate, 'EPSG:3857', 'EPSG:4326'));
|
coordinate, 'EPSG:3857', 'EPSG:4326'));
|
||||||
popup.setCoordinate(coordinate);
|
popup.setCoordinate(coordinate);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
goog.require('goog.debug.Console');
|
goog.require('goog.debug.Console');
|
||||||
goog.require('goog.debug.Logger');
|
goog.require('goog.debug.Logger');
|
||||||
goog.require('goog.debug.Logger.Level');
|
goog.require('goog.debug.Logger.Level');
|
||||||
goog.require('ol.CoordinateFormat');
|
goog.require('ol.Coordinate');
|
||||||
goog.require('ol.Map');
|
goog.require('ol.Map');
|
||||||
goog.require('ol.RendererHint');
|
goog.require('ol.RendererHint');
|
||||||
goog.require('ol.control.MousePosition');
|
goog.require('ol.control.MousePosition');
|
||||||
@@ -29,7 +29,7 @@ var domMap = new ol.Map({
|
|||||||
});
|
});
|
||||||
|
|
||||||
domMap.getControls().push(new ol.control.MousePosition({
|
domMap.getControls().push(new ol.control.MousePosition({
|
||||||
coordinateFormat: ol.CoordinateFormat.hdms,
|
coordinateFormat: ol.Coordinate.toStringHDMS,
|
||||||
projection: ol.Projection.getFromCode('EPSG:4326'),
|
projection: ol.Projection.getFromCode('EPSG:4326'),
|
||||||
target: document.getElementById('domMousePosition'),
|
target: document.getElementById('domMousePosition'),
|
||||||
undefinedHtml: ' '
|
undefinedHtml: ' '
|
||||||
@@ -47,7 +47,7 @@ if (webglMap !== null) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
webglMap.getControls().push(new ol.control.MousePosition({
|
webglMap.getControls().push(new ol.control.MousePosition({
|
||||||
coordinateFormat: ol.CoordinateFormat.hdms,
|
coordinateFormat: ol.Coordinate.toStringHDMS,
|
||||||
projection: ol.Projection.getFromCode('EPSG:4326'),
|
projection: ol.Projection.getFromCode('EPSG:4326'),
|
||||||
target: document.getElementById('webglMousePosition'),
|
target: document.getElementById('webglMousePosition'),
|
||||||
undefinedHtml: ' '
|
undefinedHtml: ' '
|
||||||
|
|||||||
@@ -1,8 +1,16 @@
|
|||||||
goog.provide('ol.Coordinate');
|
goog.provide('ol.Coordinate');
|
||||||
|
goog.provide('ol.CoordinateFormatType');
|
||||||
|
|
||||||
|
goog.require('goog.math');
|
||||||
goog.require('goog.math.Vec2');
|
goog.require('goog.math.Vec2');
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {function((ol.Coordinate|undefined)): string}
|
||||||
|
*/
|
||||||
|
ol.CoordinateFormatType;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
@@ -21,3 +29,60 @@ goog.inherits(ol.Coordinate, goog.math.Vec2);
|
|||||||
* @type {ol.Coordinate}
|
* @type {ol.Coordinate}
|
||||||
*/
|
*/
|
||||||
ol.Coordinate.ZERO = new ol.Coordinate(0, 0);
|
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 '';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -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 '';
|
|
||||||
}
|
|
||||||
};
|
|
||||||
+1
-3
@@ -15,9 +15,7 @@
|
|||||||
@exportProperty ol.Collection.prototype.setAt
|
@exportProperty ol.Collection.prototype.setAt
|
||||||
|
|
||||||
@exportSymbol ol.Coordinate
|
@exportSymbol ol.Coordinate
|
||||||
|
@exportProperty ol.Coordinate.toStringHDMS
|
||||||
@exportSymbol ol.CoordinateFormat
|
|
||||||
@exportProperty ol.CoordinateFormat.hdms
|
|
||||||
|
|
||||||
@exportSymbol ol.Extent
|
@exportSymbol ol.Extent
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user