64 |
} |
} |
65 |
} |
} |
66 |
|
|
67 |
|
#define log2(x) (log(x) / log(2)) |
68 |
|
|
69 |
|
void get_zoom(context_t *context) { |
70 |
|
pos_float_t center_lat = (context->max.lat + context->min.lat)/2; |
71 |
|
|
72 |
|
/* we know pixel size, we know the real size, we want the zoom! */ |
73 |
|
|
74 |
|
printf("map_update: %d x %d\n", |
75 |
|
context->map.widget->allocation.width, |
76 |
|
context->map.widget->allocation.height); |
77 |
|
|
78 |
|
double vscale = DEG2RAD(POS_EQ_RADIUS); |
79 |
|
double hscale = DEG2RAD(cos(DEG2RAD(center_lat)) * POS_EQ_RADIUS); |
80 |
|
|
81 |
|
printf("scale: %f m/pix %f m/pix\n", hscale*256, vscale*256); |
82 |
|
|
83 |
|
// double height = 8 * (1<<zoom) / vscale; // 2^zoom ln2(zoom) |
84 |
|
// double hzoom = log2(context->map.widget->allocation.height * vscale / 8); |
85 |
|
// double width = 16 * (1<<zoom) / hscale; |
86 |
|
// double vzoom = log2(context->map.widget->allocation.width * hscale / 8); |
87 |
|
|
88 |
|
// printf("zoom: %f %f\n", hzoom, vzoom); |
89 |
|
} |
90 |
|
|
91 |
|
/* the contents of the map tab have been changed */ |
92 |
|
static void map_update(context_t *context) { |
93 |
|
pos_float_t center_lat = (context->max.lat + context->min.lat)/2; |
94 |
|
pos_float_t center_lon = (context->max.lon + context->min.lon)/2; |
95 |
|
|
96 |
|
get_zoom(context); |
97 |
|
|
98 |
|
osm_gps_map_set_center(OSM_GPS_MAP(context->map.widget), |
99 |
|
center_lat, center_lon); |
100 |
|
|
101 |
|
osm_gps_map_set_zoom(OSM_GPS_MAP(context->map.widget), 14); |
102 |
|
} |
103 |
|
|
104 |
|
static gboolean on_map_configure(GtkWidget *widget, |
105 |
|
GdkEventConfigure *event, |
106 |
|
context_t *context) { |
107 |
|
|
108 |
|
map_update(context); |
109 |
|
return FALSE; |
110 |
|
} |
111 |
|
|
112 |
/* the contents of the direct tab have been changed */ |
/* the contents of the direct tab have been changed */ |
113 |
static void direct_update(context_t *context) { |
static void direct_update(context_t *context) { |
114 |
pos_lat_entry_set(context->direct.minlat, context->min.lat); |
pos_lat_entry_set(context->direct.minlat, context->min.lat); |
185 |
|
|
186 |
/* also update other tabs */ |
/* also update other tabs */ |
187 |
direct_update(context); |
direct_update(context); |
188 |
|
map_update(context); |
189 |
} |
} |
190 |
|
|
191 |
static void callback_modified_unit(GtkWidget *widget, gpointer data) { |
static void callback_modified_unit(GtkWidget *widget, gpointer data) { |
256 |
/* also update other tabs */ |
/* also update other tabs */ |
257 |
direct_update(context); |
direct_update(context); |
258 |
extent_update(context); |
extent_update(context); |
259 |
|
map_update(context); |
260 |
} |
} |
261 |
#endif |
#endif |
262 |
|
|
266 |
g_object_get(map, "zoom", &zoom, NULL); |
g_object_get(map, "zoom", &zoom, NULL); |
267 |
zoom = osm_gps_map_set_zoom(map, zoom+step); |
zoom = osm_gps_map_set_zoom(map, zoom+step); |
268 |
|
|
269 |
|
get_zoom(context); |
270 |
|
|
271 |
/* enable/disable zoom buttons as required */ |
/* enable/disable zoom buttons as required */ |
272 |
gtk_widget_set_sensitive(context->map.zoomin, zoom<17); |
gtk_widget_set_sensitive(context->map.zoomin, zoom<17); |
273 |
gtk_widget_set_sensitive(context->map.zoomout, zoom>1); |
gtk_widget_set_sensitive(context->map.zoomout, zoom>1); |
303 |
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, |
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, |
304 |
NULL); |
NULL); |
305 |
|
|
306 |
GtkWidget *table = gtk_table_new(3, 3, FALSE); // x, y |
GtkWidget *table = gtk_table_new(4, 2, FALSE); // x, y |
307 |
|
|
308 |
GtkWidget *label = gtk_label_new(_("Latitude")); |
GtkWidget *label = gtk_label_new(_("Latitude:")); |
309 |
gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 2, 0, 1); |
misc_table_attach(table, label, 0, 0); |
|
label = gtk_label_new(_("Longitude")); |
|
|
gtk_table_attach_defaults(GTK_TABLE(table), label, 2, 3, 0, 1); |
|
|
|
|
|
label = gtk_label_new(_("Min:")); |
|
|
gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); |
|
|
gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2); |
|
310 |
context.minlat = pos_lat_label_new(area->min->lat); |
context.minlat = pos_lat_label_new(area->min->lat); |
311 |
gtk_table_attach_defaults(GTK_TABLE(table), context.minlat, 1, 2, 1, 2); |
misc_table_attach(table, context.minlat, 1, 0); |
312 |
context.minlon = pos_lon_label_new(area->min->lon); |
label = gtk_label_new(_("to")); |
313 |
gtk_table_attach_defaults(GTK_TABLE(table), context.minlon, 2, 3, 1, 2); |
misc_table_attach(table, label, 2, 0); |
|
|
|
|
label = gtk_label_new(_("Max:")); |
|
|
gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); |
|
|
gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 2, 3); |
|
314 |
context.maxlat = pos_lat_label_new(area->max->lat); |
context.maxlat = pos_lat_label_new(area->max->lat); |
315 |
gtk_table_attach_defaults(GTK_TABLE(table), context.maxlat, 1, 2, 2, 3); |
misc_table_attach(table, context.maxlat, 3, 0); |
316 |
|
|
317 |
|
label = gtk_label_new(_("Longitude:")); |
318 |
|
misc_table_attach(table, label, 0, 1); |
319 |
|
context.minlon = pos_lon_label_new(area->min->lon); |
320 |
|
misc_table_attach(table, context.minlon, 1, 1); |
321 |
|
label = gtk_label_new(_("to")); |
322 |
|
misc_table_attach(table, label, 2, 1); |
323 |
context.maxlon = pos_lon_label_new(area->max->lon); |
context.maxlon = pos_lon_label_new(area->max->lon); |
324 |
gtk_table_attach_defaults(GTK_TABLE(table), context.maxlon, 2, 3, 2, 3); |
misc_table_attach(table, context.maxlon, 3, 1); |
325 |
|
|
326 |
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(context.dialog)->vbox), |
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(context.dialog)->vbox), |
327 |
table, FALSE, FALSE, 0); |
table, FALSE, FALSE, 0); |
328 |
|
|
329 |
context.notebook = gtk_notebook_new(); |
context.notebook = gtk_notebook_new(); |
330 |
|
|
331 |
|
/* ------------- fetch from map ------------------------ */ |
332 |
|
|
333 |
|
GtkWidget *hbox = gtk_hbox_new(FALSE, 0); |
334 |
|
|
335 |
|
context.map.widget = g_object_new(OSM_TYPE_GPS_MAP, |
336 |
|
"repo-uri", MAP_SOURCE_OPENSTREETMAP, |
337 |
|
"proxy-uri", misc_get_proxy_uri(area->settings), |
338 |
|
NULL); |
339 |
|
|
340 |
|
g_signal_connect(G_OBJECT(context.map.widget), "configure-event", |
341 |
|
G_CALLBACK(on_map_configure), &context); |
342 |
|
|
343 |
|
gtk_box_pack_start_defaults(GTK_BOX(hbox), context.map.widget); |
344 |
|
|
345 |
|
/* zoom button box */ |
346 |
|
GtkWidget *vbox = gtk_vbox_new(FALSE,0); |
347 |
|
|
348 |
|
context.map.zoomin = gtk_button_new(); |
349 |
|
gtk_button_set_image(GTK_BUTTON(context.map.zoomin), |
350 |
|
gtk_image_new_from_stock(GTK_STOCK_ZOOM_IN, GTK_ICON_SIZE_MENU)); |
351 |
|
g_signal_connect(context.map.zoomin, "clicked", |
352 |
|
G_CALLBACK(cb_map_zoomin), &context); |
353 |
|
gtk_box_pack_start(GTK_BOX(vbox), context.map.zoomin, FALSE, FALSE, 0); |
354 |
|
|
355 |
|
context.map.zoomout = gtk_button_new(); |
356 |
|
gtk_button_set_image(GTK_BUTTON(context.map.zoomout), |
357 |
|
gtk_image_new_from_stock(GTK_STOCK_ZOOM_OUT, GTK_ICON_SIZE_MENU)); |
358 |
|
g_signal_connect(context.map.zoomout, "clicked", |
359 |
|
G_CALLBACK(cb_map_zoomout), &context); |
360 |
|
gtk_box_pack_start(GTK_BOX(vbox), context.map.zoomout, FALSE, FALSE, 0); |
361 |
|
|
362 |
|
gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); |
363 |
|
|
364 |
|
gtk_notebook_append_page(GTK_NOTEBOOK(context.notebook), |
365 |
|
hbox, gtk_label_new(_("Map"))); |
366 |
|
|
367 |
/* ------------ direct min/max edit --------------- */ |
/* ------------ direct min/max edit --------------- */ |
368 |
|
|
369 |
GtkWidget *vbox = gtk_vbox_new(FALSE, 10); |
vbox = gtk_vbox_new(FALSE, 10); |
370 |
table = gtk_table_new(3, 3, FALSE); // x, y |
table = gtk_table_new(3, 3, FALSE); // x, y |
371 |
|
|
372 |
label = gtk_label_new(_("Min:")); |
context.direct.minlat = pos_lat_entry_new(0.0); |
373 |
gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); |
misc_table_attach(table, context.direct.minlat, 0, 0); |
374 |
gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1); |
label = gtk_label_new(_("to")); |
375 |
context.direct.minlat = pos_lat_entry_new(0.); |
misc_table_attach(table, label, 1, 0); |
|
gtk_table_attach_defaults(GTK_TABLE(table), context.direct.minlat, 1, 2, 0, 1); |
|
|
context.direct.minlon = pos_lon_entry_new(area->min->lon); |
|
|
gtk_table_attach_defaults(GTK_TABLE(table), context.direct.minlon, 2, 3, 0, 1); |
|
|
|
|
|
label = gtk_label_new(_("Max:")); |
|
|
gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); |
|
|
gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2); |
|
376 |
context.direct.maxlat = pos_lat_entry_new(0.0); |
context.direct.maxlat = pos_lat_entry_new(0.0); |
377 |
gtk_table_attach_defaults(GTK_TABLE(table), context.direct.maxlat, 1, 2, 1, 2); |
misc_table_attach(table, context.direct.maxlat, 2, 0); |
378 |
|
|
379 |
|
context.direct.minlon = pos_lon_entry_new(area->min->lon); |
380 |
|
misc_table_attach(table, context.direct.minlon, 0, 1); |
381 |
|
label = gtk_label_new(_("to")); |
382 |
|
misc_table_attach(table, label, 1, 1); |
383 |
context.direct.maxlon = pos_lon_entry_new(0.0); |
context.direct.maxlon = pos_lon_entry_new(0.0); |
384 |
gtk_table_attach_defaults(GTK_TABLE(table), context.direct.maxlon, 2, 3, 1, 2); |
misc_table_attach(table, context.direct.maxlon, 2, 1); |
385 |
|
|
386 |
/* setup this page */ |
/* setup this page */ |
387 |
direct_update(&context); |
direct_update(&context); |
482 |
vbox, gtk_label_new(_("Maemo Mapper"))); |
vbox, gtk_label_new(_("Maemo Mapper"))); |
483 |
#endif |
#endif |
484 |
|
|
|
/* ------------- fetch from map ------------------------ */ |
|
|
|
|
|
GtkWidget *hbox = gtk_hbox_new(FALSE, 0); |
|
|
|
|
|
context.map.widget = g_object_new(OSM_TYPE_GPS_MAP, |
|
|
"repo-uri", MAP_SOURCE_OPENSTREETMAP, |
|
|
"proxy-uri", misc_get_proxy_uri(area->settings), |
|
|
NULL); |
|
|
|
|
|
gtk_box_pack_start_defaults(GTK_BOX(hbox), context.map.widget); |
|
|
|
|
|
/* zoom button box */ |
|
|
vbox = gtk_vbox_new(FALSE,0); |
|
|
|
|
|
context.map.zoomin = gtk_button_new(); |
|
|
gtk_button_set_image(GTK_BUTTON(context.map.zoomin), |
|
|
gtk_image_new_from_stock(GTK_STOCK_ZOOM_IN, GTK_ICON_SIZE_MENU)); |
|
|
g_signal_connect(context.map.zoomin, "clicked", |
|
|
G_CALLBACK(cb_map_zoomin), &context); |
|
|
gtk_box_pack_start(GTK_BOX(vbox), context.map.zoomin, FALSE, FALSE, 0); |
|
|
|
|
|
context.map.zoomout = gtk_button_new(); |
|
|
gtk_button_set_image(GTK_BUTTON(context.map.zoomout), |
|
|
gtk_image_new_from_stock(GTK_STOCK_ZOOM_OUT, GTK_ICON_SIZE_MENU)); |
|
|
g_signal_connect(context.map.zoomout, "clicked", |
|
|
G_CALLBACK(cb_map_zoomout), &context); |
|
|
gtk_box_pack_start(GTK_BOX(vbox), context.map.zoomout, FALSE, FALSE, 0); |
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); |
|
|
|
|
|
gtk_notebook_append_page(GTK_NOTEBOOK(context.notebook), |
|
|
hbox, gtk_label_new(_("Map"))); |
|
|
|
|
485 |
/* ------------------------------------------------------ */ |
/* ------------------------------------------------------ */ |
486 |
|
|
487 |
gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(context.dialog)->vbox), |
gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(context.dialog)->vbox), |