Add ol.coordinate.format function
Return a formatted coordinate. Example usage:
> ol.coordinate.format([0.01 ,12.14], "{x}, {y}", 2)
"0.01, 12.14"
> ol.coordinate.format([0.01 ,12.14], "lat: {y} / lon: {x}", 1)
"lat: 12.1 / lon: 0.0"
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
@exportSymbol ol.coordinate.createStringXY
|
||||
@exportSymbol ol.coordinate.format
|
||||
@exportSymbol ol.coordinate.toStringHDMS
|
||||
@exportSymbol ol.coordinate.toStringXY
|
||||
@exportSymbol ol.coordinate.fromProjectedArray
|
||||
|
||||
@@ -75,6 +75,25 @@ ol.coordinate.degreesToStringHDMS_ = function(degrees, hemispheres) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Coordinate|undefined} coordinate Coordinate.
|
||||
* @param {string} template Template.
|
||||
* @param {number=} opt_precision Precision.
|
||||
* @return {string} Formated coordinate.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.coordinate.format = function(coordinate, template, opt_precision) {
|
||||
if (goog.isDef(coordinate)) {
|
||||
var precision = opt_precision || 0;
|
||||
return template
|
||||
.replace('{x}', coordinate[0].toFixed(precision))
|
||||
.replace('{y}', coordinate[1].toFixed(precision));
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Coordinate} coordinate Coordinate.
|
||||
* @param {number} angle Angle.
|
||||
@@ -137,13 +156,7 @@ ol.coordinate.toStringHDMS = function(coordinate) {
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.coordinate.toStringXY = function(coordinate, opt_precision) {
|
||||
if (goog.isDef(coordinate)) {
|
||||
var precision = opt_precision || 0;
|
||||
return coordinate[0].toFixed(precision) + ', ' +
|
||||
coordinate[1].toFixed(precision);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
return ol.coordinate.format(coordinate, '{x}, {y}', opt_precision);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user