+ struct UTM u;
+ gint tx, ty;
+
+ vik_viewport_screen_to_coord ( vvp, x1, y1, &test );
+ vik_coord_to_latlon ( &test, &ll );
+ ll.lat += vik_viewport_get_ympp ( vvp ) * vik_viewport_get_height ( vvp ) / 11000.0; // about 11km per degree latitude
+ a_coords_latlon_to_utm ( &ll, &u );
+ vik_coord_load_from_utm ( &test, VIK_VIEWPORT_DRAWMODE_UTM, &u );
+ vik_viewport_coord_to_screen ( vvp, &test, &tx, &ty );
+
+ baseangle = M_PI - atan2(tx-x1, ty-y1);
+ angle -= baseangle;
+ }
+
+ if (angle<0)
+ angle+=2*M_PI;
+ if (angle>2*M_PI)
+ angle-=2*M_PI;
+
+ {
+ GdkColor color;
+ gdk_gc_copy(thickgc, gc);
+ gdk_gc_set_line_attributes(thickgc, CW, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
+ gdk_color_parse("#2255cc", &color);
+ gdk_gc_set_rgb_fg_color(thickgc, &color);
+ }
+ gdk_draw_arc (d, thickgc, FALSE, x1-CR+CW/2, y1-CR+CW/2, 2*CR-CW, 2*CR-CW, (90 - baseangle*180/M_PI)*64, -angle*180/M_PI*64);
+
+
+ gdk_gc_copy(thickgc, gc);
+ gdk_gc_set_line_attributes(thickgc, 2, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
+ for (i=0; i<180; i++) {
+ c = cos(i*M_PI/90.0 + baseangle);
+ s = sin(i*M_PI/90.0 + baseangle);
+
+ if (i%5) {
+ gdk_draw_line (d, gc, x1 + CR*c, y1 + CR*s, x1 + (CR+CW)*c, y1 + (CR+CW)*s);
+ } else {
+ gdouble ticksize = 2*CW;
+ gdk_draw_line (d, thickgc, x1 + (CR-CW)*c, y1 + (CR-CW)*s, x1 + (CR+ticksize)*c, y1 + (CR+ticksize)*s);
+ }
+ }
+
+ gdk_draw_arc (d, gc, FALSE, x1-CR, y1-CR, 2*CR, 2*CR, 0, 64*360);
+ gdk_draw_arc (d, gc, FALSE, x1-CR-CW, y1-CR-CW, 2*(CR+CW), 2*(CR+CW), 0, 64*360);
+ gdk_draw_arc (d, gc, FALSE, x1-CR+CW, y1-CR+CW, 2*(CR-CW), 2*(CR-CW), 0, 64*360);
+ c = (CR+CW*2)*cos(baseangle);
+ s = (CR+CW*2)*sin(baseangle);
+ gdk_draw_line (d, gc, x1-c, y1-s, x1+c, y1+s);
+ gdk_draw_line (d, gc, x1+s, y1-c, x1-s, y1+c);
+
+ /* draw labels */
+#define LABEL(x, y, w, h) { \
+ gdk_draw_rectangle(d, labgc, TRUE, (x)-2, (y)-1, (w)+4, (h)+1); \
+ gdk_draw_rectangle(d, gc, FALSE, (x)-2, (y)-1, (w)+4, (h)+1); \
+ gdk_draw_layout(d, gc, (x), (y), pl); }
+ {
+ gint wd, hd, xd, yd;
+ gint wb, hb, xb, yb;
+
+ pl = gtk_widget_create_pango_layout (GTK_WIDGET(vvp), NULL);
+
+ pfd = pango_font_description_from_string ("Sans 8"); // FIXME: settable option? global variable?
+ pango_layout_set_font_description (pl, pfd);
+ pango_font_description_free (pfd);
+
+ pango_layout_set_text(pl, "N", -1);
+ gdk_draw_layout(d, gc, x1-5, y1-CR-3*CW-8, pl);
+
+ /* draw label with distance */
+ if (distance >= 1000 && distance < 100000) {
+ g_sprintf(str, "%3.2f km", distance/1000.0);
+ } else if (distance < 1000) {
+ g_sprintf(str, "%d m", (int)distance);
+ } else {
+ g_sprintf(str, "%d km", (int)distance/1000);
+ }
+ pango_layout_set_text(pl, str, -1);
+
+ pango_layout_get_pixel_size ( pl, &wd, &hd );
+ if (dy>0) {
+ xd = (x1+x2)/2 + dy;
+ yd = (y1+y2)/2 - hd/2 - dx;
+ } else {
+ xd = (x1+x2)/2 - dy;
+ yd = (y1+y2)/2 - hd/2 + dx;
+ }
+
+ if ( xd < -5 || yd < -5 || xd > vik_viewport_get_width(vvp)+5 || yd > vik_viewport_get_height(vvp)+5 ) {
+ xd = x2 + 10;
+ yd = y2 - 5;
+ }
+
+ LABEL(xd, yd, wd, hd);
+
+ /* draw label with bearing */
+ g_sprintf(str, "%3.1f°", angle*180.0/M_PI);
+ pango_layout_set_text(pl, str, -1);
+ pango_layout_get_pixel_size ( pl, &wb, &hb );
+ xb = x1 + CR*cos(angle-M_PI_2);
+ yb = y1 + CR*sin(angle-M_PI_2);
+
+ if ( xb < -5 || yb < -5 || xb > vik_viewport_get_width(vvp)+5 || yb > vik_viewport_get_height(vvp)+5 ) {
+ xb = x2 + 10;
+ yb = y2 + 10;
+ }
+