added Graticule control and Util.getFormattedLonLat function. Thanks madair for this excellent patch. p=madair, r=me (closes #1083)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@9757 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2009-10-24 05:36:34 +00:00
parent a864838e96
commit 6d43a28da6
7 changed files with 528 additions and 0 deletions

View File

@@ -958,6 +958,8 @@ OpenLayers.Util.getParameters = function(url) {
var end = OpenLayers.String.contains(url, "#") ?
url.indexOf('#') : url.length;
paramsString = url.substring(start, end);
} else {
paramsString = url;
}
var parameters = {};
@@ -1642,3 +1644,61 @@ OpenLayers.Util.getScrollbarWidth = function() {
return scrollbarWidth;
};
/**
* APIFunction: getFormattedLonLat
* This function will return latitude or longitude value formatted as
*
* Parameters:
* coordinate - {Float} the coordinate value to be formatted
* axis - {String} value of either 'lat' or 'lon' to indicate which axis is to
* to be formatted (default = lat)
* dmsOption - {String} specify the precision of the output can be one of:
* 'dms' show degrees minutes and seconds
* 'dm' show only degrees and minutes
* 'd' show only degrees
*
* Returns:
* {String} the coordinate value formatted as a string
*/
OpenLayers.Util.getFormattedLonLat = function(coordinate, axis, dmsOption) {
if (!dmsOption) {
dmsOption = 'dms'; //default to show degree, minutes, seconds
}
var abscoordinate = Math.abs(coordinate)
var coordinatedegrees = Math.floor(abscoordinate);
var coordinateminutes = (abscoordinate - coordinatedegrees)/(1/60);
var tempcoordinateminutes = coordinateminutes;
coordinateminutes = Math.floor(coordinateminutes);
var coordinateseconds = (tempcoordinateminutes - coordinateminutes)/(1/60);
coordinateseconds = Math.round(coordinateseconds*10);
coordinateseconds /= 10;
if( coordinatedegrees < 10 ) {
coordinatedegrees = "0" + coordinatedegrees;
}
var str = coordinatedegrees + " "; //get degree symbol here somehow for SVG/VML labelling
if (dmsOption.indexOf('dm') >= 0) {
if( coordinateminutes < 10 ) {
coordinateminutes = "0" + coordinateminutes;
}
str += coordinateminutes + "'";
if (dmsOption.indexOf('dms') >= 0) {
if( coordinateseconds < 10 ) {
coordinateseconds = "0" + coordinateseconds;
}
str += coordinateseconds + '"';
}
}
if (axis == "lon") {
str += coordinate < 0 ? OpenLayers.i18n("W") : OpenLayers.i18n("E");
} else {
str += coordinate < 0 ? OpenLayers.i18n("S") : OpenLayers.i18n("N");
}
return str;
};