comparison src/djol/format/coords.js @ 34:27e8e9e38e07 default tip

Слияние
author nickolay
date Wed, 05 Jun 2019 20:44:15 +0300
parents 8af8e840dd49 1dc2fd263b90
children
comparison
equal deleted inserted replaced
33:8af8e840dd49 34:27e8e9e38e07
1 define(
2 [ "dojo/i18n!./nls/coords", "implab/text/format", "implab/safe" ],
3
4 function(nls, format, safe) {
5
6 var formatDMS = function(coord) {
7 return formatSD(coord, nls.dmsPattern);
8 };
9
10 var formatDM = function(coord) {
11 return formatSD(coord, nls.dmPattern);
12 };
13
14 var formatD = function(coord) {
15 return formatSD(coord, nls.dPattern);
16 };
17
18 /**
19 * pattern:
20 *
21 * {0} - signed floating point number - latitude
22 *
23 * {1} - positive floating point number - minutes part of latitude
24 *
25 * {2} - positive floating point number - seconds part of latitude
26 *
27 * {3} - localized hemisphere sign: north or south
28 *
29 * {4} - signed floating point number - longitude
30 *
31 * {5} - positive floating point number - minutes part of longitude
32 *
33 * {6} - positive floating point number - seconds part of longitude
34 *
35 * {7} - localized hemisphere sign: east or west
36 */
37 var formatSD = function(coord, pattern) {
38 safe.argumentNotNull(coord, "coord");
39 if (!pattern)
40 pattern = nls.sdPattern;
41 var x = (coord[0] % 360 + 540) % 360 - 180, y = (coord[1] % 180 + 270) % 180 - 90;
42
43 return format(pattern, y, Math.abs((y * 60) % 60), Math
44 .abs((y * 3600) % 60), y >= 0 ? nls.north : nls.south, x, Math
45 .abs((x * 60) % 60), Math.abs((x * 3600) % 60), x >= 0
46 ? nls.east
47 : nls.west);
48 };
49
50 var cls = function(fmt) {
51 switch (fmt) {
52 case "DMS":
53 return formatDMS;
54 case "DM":
55 return formatDM;
56 case "D":
57 return formatD;
58 case "SD":
59 return formatSD;
60 default:
61 if (!fmt)
62 return formatSD;
63 else
64 return function(coord) {
65 return formatSD(coord, fmt);
66 }
67 }
68 };
69
70 return cls;
71 });