Beispiel #1
0
/* the contents of the map tab have been changed */
static void map_update(area_context_t *context, bool forced) {

  /* map is first tab (page 0) */
  if(!forced && !current_tab_is(context, TAB_LABEL_MAP)) {
    g_debug("schedule map redraw");
    context->map.needs_redraw = true;
    return;
  }

  g_debug("do map redraw");

  /* check if the position is invalid */
  if(!context->bounds.valid()) {
    /* no coordinates given: display around the current GPS position if available */
    pos_t pos = context->area.gps_state->get_pos();
    int zoom = 12;
    if(!pos.valid()) {
      /* no GPS position available: display the entire world */
      pos.lat = 0.0;
      pos.lon = 0.0;
      zoom = 1;
    }

    osm_gps_map_set_center_and_zoom(context->map.widget, pos.lat, pos.lon, zoom);
    osm_gps_map_track_remove_all(context->map.widget);
  } else {

    osm_gps_map_set_center(context->map.widget, context->bounds.centerLat(),
                           context->bounds.centerLon());

    /* we know the widgets pixel size, we know the required real size, */
    /* we want the zoom! */
    GtkWidget *wd = GTK_WIDGET(context->map.widget);
    double vzoom = wd->allocation.height / context->bounds.latDist();
    double hzoom = wd->allocation.width  / context->bounds.lonDist();

    /* use smallest zoom, so everything fits on screen */
    osm_gps_map_set_zoom(context->map.widget,
                         log2((45.0 / 32.0) * std::min(vzoom, hzoom)) - 1);

    /* ---------- draw border (as a gps track) -------------- */
    osm_gps_map_track_remove_all(context->map.widget);

    if(context->bounds.normalized()) {
      GSList *box = pos_append(nullptr, context->bounds.min.lat, context->bounds.min.lon);
      box = pos_append(box, context->bounds.max.lat, context->bounds.min.lon);
      box = pos_append(box, context->bounds.max.lat, context->bounds.max.lon);
      box = pos_append(box, context->bounds.min.lat, context->bounds.max.lon);
      box = pos_append(box, context->bounds.min.lat, context->bounds.min.lon);

      osm_gps_map_add_track(context->map.widget, box);
    }
  }

  // show all other bounds
  std::for_each(context->area.other_bounds.begin(), context->area.other_bounds.end(),
                add_bounds(context->map.widget));

  context->map.needs_redraw = false;
}
Beispiel #2
0
static gboolean
on_map_motion_notify_event(GtkWidget *widget,
			   GdkEventMotion  *event, area_context_t *context) {
  OsmGpsMap *map = OSM_GPS_MAP(widget);

  if(!std::isnan(context->map.start.rlon) &&
     !std::isnan(context->map.start.rlat)) {

    /* remove existing marker */
    osm_gps_map_track_remove_all(map);

    OsmGpsMapPoint start = context->map.start;
    OsmGpsMapPoint end = osm_gps_map_convert_screen_to_geographic(map, event->x, event->y);

    GSList *box = pos_append_rad(nullptr, start.rlat, start.rlon);
    box = pos_append_rad(box, end.rlat,   start.rlon);
    box = pos_append_rad(box, end.rlat,   end.rlon);
    box = pos_append_rad(box, start.rlat, end.rlon);
    box = pos_append_rad(box, start.rlat, start.rlon);

    osm_gps_map_add_track(map, box);
  }

  /* returning true here disables dragging in osm-gps-map */
  return osm_gps_map_osd_get_state(map) == TRUE ? FALSE : TRUE;
}
Beispiel #3
0
static gboolean
on_map_button_press_event(GtkWidget *widget,
			  GdkEventButton *event, area_context_t *context) {
  OsmGpsMap *map = OSM_GPS_MAP(widget);
  osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);

  /* osm-gps-map needs this event to handle the OSD */
  if(osd->check(osd, TRUE, event->x, event->y) != OSD_NONE)
    return FALSE;

  if(osm_gps_map_osd_get_state(map) == TRUE)
    return FALSE;

  /* remove existing marker */
  osm_gps_map_track_remove_all(map);

  /* and remember this location as the start */
  context->map.start = osm_gps_map_convert_screen_to_geographic(map, event->x, event->y);

  return TRUE;
}
Beispiel #4
0
/**
 * osm_gps_map_clear_tracks:
 *
 * Deprecated: 0.7.0: Use osm_gps_map_track_remove_all() instead.
 **/
void
osm_gps_map_clear_tracks (OsmGpsMap *map)
{
    g_warning("%s is deprecated", G_STRFUNC);
    osm_gps_map_track_remove_all (map);
}