Showing 1 changed files with 13 additions and 12 deletions
+13 -12
Nasal/buttons.nas
... ...
@@ -93,9 +93,13 @@ var buttonsClass = {
93 93
         if (!contains(me.device.windows.window, menu_label ~ '-bg')) {
94 94
             var level_min = 13;
95 95
             var level_max = 7;
96
-            var levels = [ sprintf('  % 2u >', level_max) ];
96
+            var range_from_level = func (l) {
97
+                var r = (me.device.display.display.get('view[1]') / 2 * 84.53 * math.cos(data.lat) / math.pow(2, l)) * units.distance.from_nm;
98
+                return sprintf('% 3u%s', math.round(r, r > 10 ? 5 : 1), units.distance.from_nm == 1 ? 'NM' : 'km');
99
+            }
100
+            var ranges = [ sprintf('  %s >', range_from_level(level_max)) ];
97 101
             for (var i = level_max + 1; i <= level_min; i += 1)
98
-                append(levels, sprintf(i < level_min ? '< % 2u >' : '< % 2u  ', i));
102
+                append(ranges, sprintf(i < level_min ? '< %s >' : '< %s  ', range_from_level(i)));
99 103
             var orientation = [ '  NORTH UP >', '<  TRK UP  >' ];
100 104
             if (getprop('/instrumentation/gps/route-distance-nm') != nil)
101 105
                 append(orientation, '<  DTK UP  >');
... ...
@@ -106,18 +110,15 @@ var buttonsClass = {
106 110
                     [
107 111
                         {text: menu_label, type: 'title'},
108 112
                         {type: 'separator'},
109
-                        {text: 'ZOOM LEVEL', type: 'normal'},
110
-                        {text: sprintf('%s % 2u %s',
111
-                                me.device.data.zoom > level_max ? '<' : ' ',
112
-                                me.device.data.zoom,
113
-                                me.device.data.zoom < level_min ? '>' : ' '),
113
+                        {text: 'RANGE: ', type: 'normal'},
114
+                        {text: ranges[me.device.data.zoom - level_max],
114 115
                          type: 'selected|end-of-line',
115
-                         choices: levels,
116
+                         choices: ranges,
117
+                         level_max: level_max,
116 118
                          callback: func (id, selected) {
117
-                             var z = me.device.windows.state[id].objects[selected].text;
118
-                             foreach (var c; [' ', '<', '>'])
119
-                                 z = string.replace(z, c, '');
120
-                             me.device.data.zoom = z;
119
+                             me.device.data.zoom = vecindex(me.device.windows.state[id].objects[selected].choices,
120
+                                                            me.device.windows.state[id].objects[selected].text)
121
+                                                   + me.device.windows.state[id].objects[selected].level_max;
121 122
                              me.device.map.changeZoom();
122 123
                              me.device.map.update();
123 124
                          }