Index: branches/SemanticMaps0.8/includes/services/OpenLayers/jquery.openlayersinput.js |
— | — | @@ -164,7 +164,7 @@ |
165 | 165 | markerLayer, |
166 | 166 | { |
167 | 167 | lonlat: location, |
168 | | - text: '<b>' + address + '</b><hr />' + semanticMaps.dms( normalProjectionLocation.lat, normalProjectionLocation.lon ), |
| 168 | + text: '<b>' + address + '</b><hr />' + coord.dms( normalProjectionLocation.lat, normalProjectionLocation.lon ), |
169 | 169 | title: address, |
170 | 170 | icon: options.icon |
171 | 171 | } |
Index: branches/SemanticMaps0.8/includes/forminputs/ext.sm.forminputs.js |
— | — | @@ -9,22 +9,112 @@ |
10 | 10 | * @author Jeroen De Dauw <jeroendedauw at gmail dot com> |
11 | 11 | */ |
12 | 12 | |
| 13 | +window.coord = new ( function( $ ) { |
| 14 | + |
| 15 | + /** |
| 16 | + * The separator used between latitude and longitude in a coordinate set. |
| 17 | + * @const |
| 18 | + * @type {string} |
| 19 | + */ |
| 20 | + this.SEPARATOR = ','; |
| 21 | + |
| 22 | + /** |
| 23 | + * The delimiter used between coordinate sets. |
| 24 | + * @const |
| 25 | + * @type {string} |
| 26 | + */ |
| 27 | + this.DELIMITER = ';'; |
| 28 | + |
| 29 | + /** |
| 30 | + * Returns a list with coordinates obtained by splitting the provided string. |
| 31 | + * @param {string} coords The coordinates to split. |
| 32 | + * @return {Array} The split coordinates. |
| 33 | + */ |
| 34 | + this.split = function( coords ) { |
| 35 | + coords = coords.split( this.DELIMITER ); |
| 36 | + for ( i in coords ) coords[i] = coords[i].trim(); |
| 37 | + return coords; |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Returns the provided coordinates joined in a string. |
| 42 | + * @param {Array} coords The coordinates to join. |
| 43 | + * @return {string} The joined coordinates. |
| 44 | + */ |
| 45 | + this.join = function( coords ) { |
| 46 | + return coords.join( this.DELIMITER + ' ' ); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Returns a string with the directional DMS representatation of the provided latitude and longitude. |
| 51 | + * @param {float} lat The latitude. |
| 52 | + * @param {float} lon The longitude. |
| 53 | + * @return {string} The string with DMS coordinates. |
| 54 | + */ |
| 55 | + this.dms = function( lat, lon ) { // TODO: i18n |
| 56 | + return |
| 57 | + Math.abs( lat ).toString() + '° ' + ( lat < 0 ? 'S' : 'N' ) |
| 58 | + + this.SEPARATOR + ' ' |
| 59 | + + Math.abs( lon ).toString() + '° ' + ( lon < 0 ? 'W' : 'E' ); |
| 60 | + }; |
| 61 | + |
| 62 | + /** |
| 63 | + * Returns a string with the non-directional float representatation of the provided latitude and longitude. |
| 64 | + * @param {float} lat The latitude. |
| 65 | + * @param {float} lon The longitude. |
| 66 | + * @return {string} The string with float coordinates. |
| 67 | + */ |
| 68 | + this.float = function( lat, lon ) { |
| 69 | + return lat.toString() + this.SEPARATOR + ' ' + lon.toString(); |
| 70 | + } |
| 71 | + |
| 72 | + this.parse = function( coord ) { |
| 73 | + coord = coord.split( this.SEPARATOR ); |
| 74 | + if ( coord.length != 2 ) return false; |
| 75 | + |
| 76 | + var lat = coord[0].trim(); |
| 77 | + var lon = coord[1].trim(); |
| 78 | + var parsed; |
| 79 | + |
| 80 | + parsed = this.parseFloat( lat, lon ); |
| 81 | + if ( parsed !== false ) return parsed; |
| 82 | + |
| 83 | + parsed = this.parseDMS( lat, lon ); |
| 84 | + if ( parsed !== false ) return parsed; |
| 85 | + |
| 86 | + return false; |
| 87 | + } |
| 88 | + |
| 89 | + this.parseDMS = function( lat, lon ) { |
| 90 | + if ( true ) { |
| 91 | + // TODO |
| 92 | + } |
| 93 | + else { |
| 94 | + return false; |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + this.parseFloat = function( lat, lon ) { |
| 99 | + if ( true ) { |
| 100 | + // TODO |
| 101 | + } |
| 102 | + else { |
| 103 | + return false; |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | +} )( jQuery ); |
| 108 | + |
13 | 109 | window.semanticMaps = new ( function( $ ) { |
14 | 110 | |
15 | | - this.buildInputValue = function ( locations ) { |
16 | | - var dms = []; |
| 111 | + this.buildInputValue = function( locations ) { |
| 112 | + var floats = []; |
17 | 113 | |
18 | 114 | for ( i in locations ) { |
19 | | - dms.push( this.dms( locations[i].lat, locations[i].lon ) ); |
| 115 | + floats.push( coord.float( locations[i].lat, locations[i].lon ) ); |
20 | 116 | } |
21 | 117 | |
22 | | - return dms.join( '; ' ); |
| 118 | + return floats.join( '; ' ); |
23 | 119 | }; |
24 | 120 | |
25 | | - this.dms = function ( lat, lon ) { // TODO: i18n |
26 | | - return Math.abs( lat ) + '° ' + ( lat < 0 ? 'S' : 'N' ) + ', ' + Math.abs( lon ) + '° ' + ( lon < 0 ? 'W' : 'E' ); |
27 | | - }; |
28 | | - |
29 | | - this.locationToDMS = this.dms; |
30 | | - |
31 | 121 | } )( jQuery ); |
\ No newline at end of file |