]> git.street.me.uk Git - andy/viking.git/commitdiff
SF Features#120: Add Nautical Miles preference for distance units.
authorRob Norris <rw_norris@hotmail.com>
Mon, 9 Jun 2014 20:39:02 +0000 (21:39 +0100)
committerRob Norris <rw_norris@hotmail.com>
Mon, 9 Jun 2014 20:40:38 +0000 (21:40 +0100)
src/globals.c
src/globals.h
src/viktrwlayer.c
src/viktrwlayer_propwin.c
src/viktrwlayer_tpwin.c
src/vikutils.c
src/vikviewport.c
src/vikwindow.c

index b4f2ab27ac07d5e3e086438fc82a7508aef894eb..b4f2b5f90721f49f932a3914a64f67eab2df233f 100644 (file)
@@ -65,7 +65,7 @@ gint viking_version_to_number ( gchar *version )
 }
 
 static gchar * params_degree_formats[] = {"DDD", "DMM", "DMS", N_("Raw"), NULL};
-static gchar * params_units_distance[] = {"Kilometres", "Miles", NULL};
+static gchar * params_units_distance[] = {N_("Kilometres"), N_("Miles"), N_("Nautical Miles"), NULL};
 static gchar * params_units_speed[] = {"km/h", "mph", "m/s", "knots", NULL};
 static gchar * params_units_height[] = {"Metres", "Feet", NULL};
 static VikLayerParamScale params_scales_lat[] = { {-90.0, 90.0, 0.05, 2} };
index 29a5b49e6abc675e15bced8c583bd41e4ccc3ffd..28646523f7d45a8ffe3030419b83bcb5b063d606 100644 (file)
@@ -43,6 +43,10 @@ G_BEGIN_DECLS
 #define VIK_METERS_TO_MILES(X) ((X)*VIK_MILES_IN_METER)
 #define VIK_MILES_TO_METERS(X) ((X)/VIK_MILES_IN_METER)
 
+#define VIK_NAUTICAL_MILES_IN_METER 0.000539957
+#define VIK_METERS_TO_NAUTICAL_MILES(X) ((X)*VIK_NAUTICAL_MILES_IN_METER)
+#define VIK_NAUTICAL_MILES_TO_METERS(X) ((X)/VIK_NAUTICAL_MILES_IN_METER)
+
 /* MPS - Metres Per Second */
 /* MPH - Metres Per Hour */
 #define VIK_MPH_IN_MPS 2.23693629
@@ -99,6 +103,7 @@ vik_degree_format_t a_vik_get_degree_format ( );
 typedef enum {
   VIK_UNITS_DISTANCE_KILOMETRES,
   VIK_UNITS_DISTANCE_MILES,
+  VIK_UNITS_DISTANCE_NAUTICAL_MILES,
 } vik_units_distance_t;
 
 vik_units_distance_t a_vik_get_units_distance ( );
index 8bd6cb29c3c0300cc6f2f2eab31fc976df03e1ab..9aa427dfa50c64d97f78334eae107fea417ace41 100644 (file)
@@ -1740,6 +1740,9 @@ static gdouble distance_in_preferred_units ( gdouble dist )
   case VIK_UNITS_DISTANCE_MILES:
     mydist = VIK_METERS_TO_MILES(dist);
     break;
+  case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+    mydist = VIK_METERS_TO_NAUTICAL_MILES(dist);
+    break;
   // VIK_UNITS_DISTANCE_KILOMETRES:
   default:
     mydist = dist/1000.0;
@@ -1785,6 +1788,9 @@ static void trw_layer_draw_dist_labels ( struct DrawingParams *dp, VikTrack *trk
     case VIK_UNITS_DISTANCE_MILES:
       dist_i = VIK_MILES_TO_METERS(dist_i);
       break;
+    case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+      dist_i = VIK_NAUTICAL_MILES_TO_METERS(dist_i);
+      break;
       // VIK_UNITS_DISTANCE_KILOMETRES:
     default:
       dist_i = dist_i*1000.0;
@@ -2843,13 +2849,19 @@ static const gchar* trw_layer_layer_tooltip ( VikTrwLayer *vtl )
       gdouble len_in_units;
 
       // Setup info dependent on distance units
-      if ( a_vik_get_units_distance() == VIK_UNITS_DISTANCE_MILES ) {
-       g_snprintf (tbuf4, sizeof(tbuf4), "miles");
-       len_in_units = VIK_METERS_TO_MILES(tt.length);
-      }
-      else {
-       g_snprintf (tbuf4, sizeof(tbuf4), "kms");
-       len_in_units = tt.length/1000.0;
+      switch ( a_vik_get_units_distance() ) {
+      case VIK_UNITS_DISTANCE_MILES:
+        g_snprintf (tbuf4, sizeof(tbuf4), "miles");
+        len_in_units = VIK_METERS_TO_MILES(tt.length);
+        break;
+      case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+        g_snprintf (tbuf4, sizeof(tbuf4), "NM");
+        len_in_units = VIK_METERS_TO_NAUTICAL_MILES(tt.length);
+        break;
+      default:
+        g_snprintf (tbuf4, sizeof(tbuf4), "kms");
+        len_in_units = tt.length/1000.0;
+        break;
       }
 
       // Timing information if available
@@ -2938,6 +2950,9 @@ static const gchar* trw_layer_sublayer_tooltip ( VikTrwLayer *l, gint subtype, g
        case VIK_UNITS_DISTANCE_MILES:
          g_snprintf (tmp_buf, sizeof(tmp_buf), _("%s%.1f miles %s"), time_buf1, VIK_METERS_TO_MILES(tr_len), time_buf2);
          break;
+       case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+         g_snprintf (tmp_buf, sizeof(tmp_buf), _("%s%.1f NM %s"), time_buf1, VIK_METERS_TO_NAUTICAL_MILES(tr_len), time_buf2);
+         break;
        default:
          break;
        }
@@ -9421,6 +9436,15 @@ static gchar* distance_string (gdouble distance)
       g_sprintf(str, "%d miles", (int)VIK_METERS_TO_MILES(distance));
     }
     break;
+  case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+    if (distance >= VIK_NAUTICAL_MILES_TO_METERS(1) && distance < VIK_NAUTICAL_MILES_TO_METERS(100)) {
+      g_sprintf(str, "%3.2f NM", VIK_METERS_TO_NAUTICAL_MILES(distance));
+    } else if (distance < VIK_NAUTICAL_MILES_TO_METERS(1)) {
+      g_sprintf(str, "%d yards", (int)(distance*1.0936133));
+    } else {
+      g_sprintf(str, "%d NM", (int)VIK_METERS_TO_NAUTICAL_MILES(distance));
+    }
+    break;
   default:
     // VIK_UNITS_DISTANCE_KILOMETRES
     if (distance >= 1000 && distance < 100000) {
index f8cbf9cca1e8716142bd92b574b667e6a1699435..7e8071e243c4507fab04cb742e79b637e970e4af 100644 (file)
@@ -748,6 +748,9 @@ void track_profile_move( GtkWidget *event_box, GdkEventMotion *event, PropWidget
     case VIK_UNITS_DISTANCE_MILES:
       g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(meters_from_start) );
       break;
+    case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+      g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f NM", VIK_METERS_TO_NAUTICAL_MILES(meters_from_start) );
+      break;
     default:
       g_critical("Houston, we've had a problem. distance=%d", dist_units);
     }
@@ -828,6 +831,9 @@ void track_gradient_move( GtkWidget *event_box, GdkEventMotion *event, PropWidge
     case VIK_UNITS_DISTANCE_MILES:
       g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(meters_from_start) );
       break;
+    case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+      g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f NM", VIK_METERS_TO_NAUTICAL_MILES(meters_from_start) );
+      break;
     default:
       g_critical("Houston, we've had a problem. distance=%d", dist_units);
     }
@@ -1031,10 +1037,17 @@ void track_dt_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *wi
 
   if (trackpoint && widgets->w_cur_dist_dist) {
     static gchar tmp_buf[20];
-    if ( a_vik_get_units_distance () == VIK_UNITS_DISTANCE_MILES )
+    switch ( a_vik_get_units_distance () ) {
+    case VIK_UNITS_DISTANCE_MILES:
       g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", widgets->distances[ix]);
-    else
+      break;
+    case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+      g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f NM", widgets->distances[ix]);
+      break;
+    default:
       g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km", widgets->distances[ix]);
+      break;
+    }
     gtk_label_set_text(GTK_LABEL(widgets->w_cur_dist_dist), tmp_buf);
   }
 
@@ -1181,6 +1194,9 @@ void track_sd_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *wi
     case VIK_UNITS_DISTANCE_MILES:
       g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(meters_from_start) );
       break;
+    case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+      g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f NM", VIK_METERS_TO_NAUTICAL_MILES(meters_from_start) );
+      break;
     default:
       g_critical("Houston, we've had a problem. distance=%d", dist_units);
     }
@@ -1409,16 +1425,27 @@ static void draw_grid_x_time ( GtkWidget *window, GtkWidget *image, PropWidgets
 static void draw_grid_x_distance ( GtkWidget *window, GtkWidget *image, PropWidgets *widgets, GdkPixmap *pix, guint ii, gdouble dd, guint xx, vik_units_distance_t dist_units )
 {
   gchar *label_markup = NULL;
-  if ( dist_units == VIK_UNITS_DISTANCE_MILES )
+  switch ( dist_units ) {
+  case VIK_UNITS_DISTANCE_MILES:
     if ( ii > 4 )
       label_markup = g_strdup_printf ( "<span size=\"small\">%d %s</span>", (guint)dd, _("miles") );
     else
       label_markup = g_strdup_printf ( "<span size=\"small\">%.1f %s</span>", dd, _("miles") );
-  else
+    break;
+  case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+    if ( ii > 4 )
+      label_markup = g_strdup_printf ( "<span size=\"small\">%d %s</span>", (guint)dd, _("NM") );
+    else
+      label_markup = g_strdup_printf ( "<span size=\"small\">%.1f %s</span>", dd, _("NM") );
+    break;
+  default:
+    // VIK_UNITS_DISTANCE_KILOMETRES:
     if ( ii > 4 )
       label_markup = g_strdup_printf ( "<span size=\"small\">%d %s</span>", (guint)dd, _("km") );
     else
       label_markup = g_strdup_printf ( "<span size=\"small\">%.1f %s</span>", dd, _("km") );
+    break;
+  }
 
   if ( label_markup ) {
     PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
@@ -1456,12 +1483,18 @@ static void draw_distance_divisions ( GtkWidget *window, GtkWidget *image, GdkPi
 {
   // Set to display units from length in metres.
   gdouble length = widgets->track_length_inc_gaps;
-  if ( dist_units == VIK_UNITS_DISTANCE_MILES )
-    length = VIK_METERS_TO_MILES(length);
-  else
-    // KM
-    length = length/1000.0;
-
+  switch (dist_units) {
+    case VIK_UNITS_DISTANCE_MILES:
+      length = VIK_METERS_TO_MILES(length);
+      break;
+    case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+      length = VIK_METERS_TO_NAUTICAL_MILES(length);
+      break;
+    default:
+      // KM
+      length = length/1000.0;
+      break;
+  }
   guint index = get_distance_chunk_index ( length );
   gdouble dist_per_pixel = length/widgets->profile_width;
 
@@ -1875,16 +1908,23 @@ static void draw_dt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
 
   // Convert into appropriate units
   vik_units_distance_t dist_units = a_vik_get_units_distance ();
-  if ( dist_units == VIK_UNITS_DISTANCE_MILES ) {
-    for ( i = 0; i < widgets->profile_width; i++ ) {
-      widgets->distances[i] = VIK_METERS_TO_MILES(widgets->distances[i]);
-    }
-  }
-  else {
-    // Metres - but want in kms
-    for ( i = 0; i < widgets->profile_width; i++ ) {
-      widgets->distances[i] = widgets->distances[i]/1000.0;
-    }
+  switch ( dist_units ) {
+    case VIK_UNITS_DISTANCE_MILES:
+      for ( i = 0; i < widgets->profile_width; i++ ) {
+        widgets->distances[i] = VIK_METERS_TO_MILES(widgets->distances[i]);
+      }
+      break;
+    case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+      for ( i = 0; i < widgets->profile_width; i++ ) {
+        widgets->distances[i] = VIK_METERS_TO_NAUTICAL_MILES(widgets->distances[i]);
+      }
+      break;
+    default:
+      // Metres - but want in kms
+      for ( i = 0; i < widgets->profile_width; i++ ) {
+        widgets->distances[i] = widgets->distances[i]/1000.0;
+      }
+      break;
   }
 
   widgets->duration = vik_track_get_duration ( widgets->tr );
@@ -1901,10 +1941,17 @@ static void draw_dt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
   // Assign locally
   // mind = 0.0; - Thus not used
   gdouble maxd;
-  if ( dist_units == VIK_UNITS_DISTANCE_MILES )
+  switch ( dist_units ) {
+  case VIK_UNITS_DISTANCE_MILES:
     maxd = VIK_METERS_TO_MILES(vik_track_get_length_including_gaps (tr));
-  else
+    break;
+  case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+    maxd = VIK_METERS_TO_NAUTICAL_MILES(vik_track_get_length_including_gaps (tr));
+    break;
+  default:
     maxd = vik_track_get_length_including_gaps (tr) / 1000.0;
+    break;
+  }
 
   /* Find suitable chunk index */
   gdouble dummy = 0.0; // expect this to remain the same! (not that it's used)
@@ -1917,10 +1964,17 @@ static void draw_dt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
   for (i=0; i<=LINES; i++) {
     gchar s[32];
 
-    if ( dist_units == VIK_UNITS_DISTANCE_MILES )
+    switch ( dist_units ) {
+    case VIK_UNITS_DISTANCE_MILES:
       sprintf(s, _("%.1f miles"), ((LINES-i)*chunksd[widgets->cid]));
-    else
+      break;
+    case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+      sprintf(s, _("%.1f NM"), ((LINES-i)*chunksd[widgets->cid]));
+      break;
+    default:
       sprintf(s, _("%.1f km"), ((LINES-i)*chunksd[widgets->cid]));
+      break;
+    }
 
     draw_grid_y ( window, image, widgets, pix, s, i );
   }
@@ -3142,6 +3196,9 @@ void vik_trw_layer_propwin_run ( GtkWindow *parent,
   case VIK_UNITS_DISTANCE_MILES:
     g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(tr_len) );
     break;
+  case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+    g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f NM", VIK_METERS_TO_NAUTICAL_MILES(tr_len) );
+    break;
   default:
     g_critical("Houston, we've had a problem. distance=%d", dist_units);
   }
@@ -3243,6 +3300,9 @@ void vik_trw_layer_propwin_run ( GtkWindow *parent,
   case VIK_UNITS_DISTANCE_MILES:
     g_snprintf(tmp_buf, sizeof(tmp_buf), "%.3f miles", (tp_count - seg_count) == 0 ? 0 : VIK_METERS_TO_MILES(tr_len / ( tp_count - seg_count )) );
     break;
+  case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+    g_snprintf(tmp_buf, sizeof(tmp_buf), "%.3f NM", (tp_count - seg_count) == 0 ? 0 : VIK_METERS_TO_NAUTICAL_MILES(tr_len / ( tp_count - seg_count )) );
+    break;
   default:
     g_critical("Houston, we've had a problem. distance=%d", dist_units);
   }
index 84f9107194a52c0e0a2da19a2c1e8d8c9b270efd..22c849032faa2de063c6ae3cfc1fdc781a9352d9 100644 (file)
@@ -430,6 +430,7 @@ void vik_trw_layer_tpwin_set_tp ( VikTrwLayerTpwin *tpwin, GList *tpl, const gch
       g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f m", vik_coord_diff(&(tp->coord), &(tpwin->cur_tp->coord)));
       break;
     case VIK_UNITS_DISTANCE_MILES:
+    case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
       g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f yards", vik_coord_diff(&(tp->coord), &(tpwin->cur_tp->coord))*1.0936133);
       break;
     default:
index 30f5b243a14c121ea354f50ad34f51640c0e0d09..bbe365831531a2c781433d2a58321f62a5a8be2c 100644 (file)
@@ -166,6 +166,7 @@ gchar* vu_trackpoint_formatted_message ( gchar *format_code, VikTrackpoint *trkp
                                // expect the difference between track points to be small hence use metres or yards
                                switch (dist_units) {
                                case VIK_UNITS_DISTANCE_MILES:
+                               case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
                                        dist_units_str = g_strdup ( _("yards") );
                                        break;
                                default:
@@ -212,12 +213,15 @@ gchar* vu_trackpoint_formatted_message ( gchar *format_code, VikTrackpoint *trkp
                                gdouble distd = vik_track_get_length_to_trackpoint (trk, trkpt);
                                gchar *dist_units_str = NULL;
                                vik_units_distance_t dist_units = a_vik_get_units_distance ();
-                               // expect the difference between track points to be small hence use metres or yards
                                switch (dist_units) {
                                case VIK_UNITS_DISTANCE_MILES:
                                        dist_units_str = g_strdup ( _("miles") );
                                        distd = VIK_METERS_TO_MILES(distd);
                                        break;
+                               case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+                                       dist_units_str = g_strdup ( _("NM") );
+                                       distd = VIK_METERS_TO_NAUTICAL_MILES(distd);
+                                       break;
                                default:
                                        // VIK_UNITS_DISTANCE_KILOMETRES:
                                        dist_units_str = g_strdup ( _("km") );
index 44ef982e0621b339c4d1f512d3f768139e851612..b15e9acfe8084bd9afeea5224959256a11ced388 100644 (file)
@@ -503,6 +503,10 @@ void vik_viewport_draw_scale ( VikViewport *vvp )
       // in 0.1 miles (copes better when zoomed in as 1 mile can be too big)
       base = VIK_METERS_TO_MILES(vik_coord_diff ( &left, &right )) * 10.0;
       break;
+    case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+      // in 0.1 NM (copes better when zoomed in as 1 NM can be too big)
+      base = VIK_METERS_TO_NAUTICAL_MILES(vik_coord_diff ( &left, &right )) * 10.0;
+      break;
     default:
       base = 1; // Keep the compiler happy
       g_critical("Houston, we've had a problem. distance=%d", dist_units);
@@ -561,21 +565,33 @@ void vik_viewport_draw_scale ( VikViewport *vvp )
     switch (dist_units) {
     case VIK_UNITS_DISTANCE_KILOMETRES:
       if (unit >= 1000) {
-       sprintf(s, "%d km", (int)unit/1000);
+        sprintf(s, "%d km", (int)unit/1000);
       } else {
-       sprintf(s, "%d m", (int)unit);
+        sprintf(s, "%d m", (int)unit);
       }
       break;
     case VIK_UNITS_DISTANCE_MILES:
       // Handle units in 0.1 miles
       if (unit < 10.0) {
-       sprintf(s, "%0.1f miles", unit/10.0);
+        sprintf(s, "%0.1f miles", unit/10.0);
+      }
+      else if ((int)unit == 10.0) {
+        sprintf(s, "1 mile");
+      }
+      else {
+        sprintf(s, "%d miles", (int)(unit/10.0));
+      }
+      break;
+    case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+      // Handle units in 0.1 NM
+      if (unit < 10.0) {
+        sprintf(s, "%0.1f NM", unit/10.0);
       }
       else if ((int)unit == 10.0) {
-       sprintf(s, "1 mile");
+        sprintf(s, "1 NM");
       }
       else {
-       sprintf(s, "%d miles", (int)(unit/10.0));
+        sprintf(s, "%d NMs", (int)(unit/10.0));
       }
       break;
     default:
index 20d65aae0b97ecf3cf7169410c7f56f89441a595..e783e9a64f1d7570df3db4bda857d1891c5547d1 100644 (file)
@@ -1447,20 +1447,29 @@ static void draw_ruler(VikViewport *vvp, GdkDrawable *d, GdkGC *gc, gint x1, gin
     switch (dist_units) {
     case VIK_UNITS_DISTANCE_KILOMETRES:
       if (distance >= 1000 && distance < 100000) {
-       g_sprintf(str, "%3.2f km", distance/1000.0);
+        g_sprintf(str, "%3.2f km", distance/1000.0);
       } else if (distance < 1000) {
-       g_sprintf(str, "%d m", (int)distance);
+        g_sprintf(str, "%d m", (int)distance);
       } else {
-       g_sprintf(str, "%d km", (int)distance/1000);
+        g_sprintf(str, "%d km", (int)distance/1000);
       }
       break;
     case VIK_UNITS_DISTANCE_MILES:
       if (distance >= VIK_MILES_TO_METERS(1) && distance < VIK_MILES_TO_METERS(100)) {
-       g_sprintf(str, "%3.2f miles", VIK_METERS_TO_MILES(distance));
+        g_sprintf(str, "%3.2f miles", VIK_METERS_TO_MILES(distance));
       } else if (distance < VIK_MILES_TO_METERS(1)) {
-       g_sprintf(str, "%d yards", (int)(distance*1.0936133));
+        g_sprintf(str, "%d yards", (int)(distance*1.0936133));
       } else {
-       g_sprintf(str, "%d miles", (int)VIK_METERS_TO_MILES(distance));
+        g_sprintf(str, "%d miles", (int)VIK_METERS_TO_MILES(distance));
+      }
+      break;
+    case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+      if (distance >= VIK_NAUTICAL_MILES_TO_METERS(1) && distance < VIK_NAUTICAL_MILES_TO_METERS(100)) {
+        g_sprintf(str, "%3.2f NM", VIK_METERS_TO_NAUTICAL_MILES(distance));
+      } else if (distance < VIK_NAUTICAL_MILES_TO_METERS(1)) {
+        g_sprintf(str, "%d yards", (int)(distance*1.0936133));
+      } else {
+        g_sprintf(str, "%d NM", (int)VIK_METERS_TO_NAUTICAL_MILES(distance));
       }
       break;
     default:
@@ -1547,14 +1556,17 @@ static VikLayerToolFuncStatus ruler_click (VikLayer *vl, GdkEventButton *event,
       vik_units_distance_t dist_units = a_vik_get_units_distance ();
       switch (dist_units) {
       case VIK_UNITS_DISTANCE_KILOMETRES:
-       temp = g_strdup_printf ( "%s %s DIFF %f meters", lat, lon, vik_coord_diff( &coord, &(s->oldcoord) ) );
-       break;
+        temp = g_strdup_printf ( "%s %s DIFF %f meters", lat, lon, vik_coord_diff( &coord, &(s->oldcoord) ) );
+        break;
       case VIK_UNITS_DISTANCE_MILES:
-       temp = g_strdup_printf ( "%s %s DIFF %f miles", lat, lon, VIK_METERS_TO_MILES(vik_coord_diff( &coord, &(s->oldcoord) )) );
-       break;
+        temp = g_strdup_printf ( "%s %s DIFF %f miles", lat, lon, VIK_METERS_TO_MILES(vik_coord_diff( &coord, &(s->oldcoord) )) );
+        break;
+      case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+        temp = g_strdup_printf ( "%s %s DIFF %f NM", lat, lon, VIK_METERS_TO_NAUTICAL_MILES(vik_coord_diff( &coord, &(s->oldcoord) )) );
+        break;
       default:
-       temp = g_strdup_printf ("Just to keep the compiler happy");
-       g_critical("Houston, we've had a problem. distance=%d", dist_units);
+        temp = g_strdup_printf ("Just to keep the compiler happy");
+        g_critical("Houston, we've had a problem. distance=%d", dist_units);
       }
 
       s->has_oldcoord = FALSE;
@@ -1624,6 +1636,9 @@ static VikLayerToolFuncStatus ruler_move (VikLayer *vl, GdkEventMotion *event, r
     case VIK_UNITS_DISTANCE_MILES:
       temp = g_strdup_printf ( "%s %s DIFF %f miles", lat, lon, VIK_METERS_TO_MILES (vik_coord_diff( &coord, &(s->oldcoord) )) );
       break;
+    case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+      temp = g_strdup_printf ( "%s %s DIFF %f NM", lat, lon, VIK_METERS_TO_NAUTICAL_MILES (vik_coord_diff( &coord, &(s->oldcoord) )) );
+      break;
     default:
       temp = g_strdup_printf ("Just to keep the compiler happy");
       g_critical("Houston, we've had a problem. distance=%d", dist_units);
@@ -3609,6 +3624,9 @@ static void draw_to_image_file_total_area_cb (GtkSpinButton *spinbutton, gpointe
   case VIK_UNITS_DISTANCE_MILES:
     label_text = g_strdup_printf ( _("Total area: %ldm x %ldm (%.3f sq. miles)"), (glong)w, (glong)h, (w*h/2589988.11));
     break;
+  case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+    label_text = g_strdup_printf ( _("Total area: %ldm x %ldm (%.3f sq. NM)"), (glong)w, (glong)h, (w*h/(1852.0*1852.0)));
+    break;
   default:
     label_text = g_strdup_printf ("Just to keep the compiler happy");
     g_critical("Houston, we've had a problem. distance=%d", dist_units);