| | 1647 | |
|---|
| | 1648 | /** |
|---|
| | 1649 | * APIFunction: getFormattedLonLat |
|---|
| | 1650 | * This function will return latitude or longitude value formatted as |
|---|
| | 1651 | * |
|---|
| | 1652 | * Parameters: |
|---|
| | 1653 | * coordinate - {Float} the coordinate value to be formatted |
|---|
| | 1654 | * axis - {String} value of either 'lat' or 'lon' to indicate which axis is to |
|---|
| | 1655 | * to be formatted (default = lat) |
|---|
| | 1656 | * dmsOption - {String} specify the precision of the output can be one of: |
|---|
| | 1657 | * 'dms' show degrees minutes and seconds |
|---|
| | 1658 | * 'dm' show only degrees and minutes |
|---|
| | 1659 | * 'd' show only degrees |
|---|
| | 1660 | * |
|---|
| | 1661 | * Returns: |
|---|
| | 1662 | * {String} the coordinate value formatted as a string |
|---|
| | 1663 | */ |
|---|
| | 1664 | OpenLayers.Util.getFormattedLonLat = function(coordinate, axis, dmsOption) { |
|---|
| | 1665 | if (!dmsOption) { |
|---|
| | 1666 | dmsOption = 'dms'; //default to show degree, minutes, seconds |
|---|
| | 1667 | } |
|---|
| | 1668 | var abscoordinate = Math.abs(coordinate) |
|---|
| | 1669 | var coordinatedegrees = Math.floor(abscoordinate); |
|---|
| | 1670 | |
|---|
| | 1671 | var coordinateminutes = (abscoordinate - coordinatedegrees)/(1/60); |
|---|
| | 1672 | var tempcoordinateminutes = coordinateminutes; |
|---|
| | 1673 | coordinateminutes = Math.floor(coordinateminutes); |
|---|
| | 1674 | var coordinateseconds = (tempcoordinateminutes - coordinateminutes)/(1/60); |
|---|
| | 1675 | coordinateseconds = Math.round(coordinateseconds*10); |
|---|
| | 1676 | coordinateseconds /= 10; |
|---|
| | 1677 | |
|---|
| | 1678 | if( coordinatedegrees < 10 ) { |
|---|
| | 1679 | coordinatedegrees = "0" + coordinatedegrees; |
|---|
| | 1680 | } |
|---|
| | 1681 | var str = coordinatedegrees + " "; //get degree symbol here somehow for SVG/VML labelling |
|---|
| | 1682 | |
|---|
| | 1683 | if (dmsOption.indexOf('dm') >= 0) { |
|---|
| | 1684 | if( coordinateminutes < 10 ) { |
|---|
| | 1685 | coordinateminutes = "0" + coordinateminutes; |
|---|
| | 1686 | } |
|---|
| | 1687 | str += coordinateminutes + "'"; |
|---|
| | 1688 | |
|---|
| | 1689 | if (dmsOption.indexOf('dms') >= 0) { |
|---|
| | 1690 | if( coordinateseconds < 10 ) { |
|---|
| | 1691 | coordinateseconds = "0" + coordinateseconds; |
|---|
| | 1692 | } |
|---|
| | 1693 | str += coordinateseconds + '"'; |
|---|
| | 1694 | } |
|---|
| | 1695 | } |
|---|
| | 1696 | |
|---|
| | 1697 | if (axis == "lon") { |
|---|
| | 1698 | str += coordinate < 0 ? OpenLayers.i18n("W") : OpenLayers.i18n("E"); |
|---|
| | 1699 | } else { |
|---|
| | 1700 | str += coordinate < 0 ? OpenLayers.i18n("S") : OpenLayers.i18n("N"); |
|---|
| | 1701 | } |
|---|
| | 1702 | return str; |
|---|
| | 1703 | }; |
|---|
| | 1704 | |
|---|