From: Bluezery <ohpowel@gmail.com>
[framework/uifw/elementary.git] / src / bin / test_map.c
1 #include <Elementary.h>
2 #ifdef HAVE_CONFIG_H
3 # include "elementary_config.h"
4 #endif
5 #ifndef ELM_LIB_QUICKLAUNCH
6
7 #define SOURCE_MAX 10
8 #define MARKER_MAX 1000
9 #define NAME_ENTRY_TEXT "Enter freeform address"
10
11 typedef struct Overlay_Data
12 {
13    const char *file;
14 } Overlay_Data;
15
16 typedef struct Map_Source
17 {
18    Evas_Object *map;
19    char *source_name;
20 } Map_Source;
21
22 Overlay_Data data1 = {PACKAGE_DATA_DIR"/images/logo.png"};
23 Overlay_Data data2 = {PACKAGE_DATA_DIR"/images/logo_small.png"};
24 Overlay_Data data3 = {PACKAGE_DATA_DIR"/images/panel_01.jpg"};
25 Overlay_Data data4 = {PACKAGE_DATA_DIR"/images/plant_01.jpg"};
26 Overlay_Data data5 = {PACKAGE_DATA_DIR"/images/rock_01.jpg"};
27 Overlay_Data data6 = {PACKAGE_DATA_DIR"/images/rock_02.jpg"};
28 Overlay_Data data7 = {PACKAGE_DATA_DIR"/images/sky_01.jpg"};
29 Overlay_Data data8 = {PACKAGE_DATA_DIR"/images/sky_02.jpg"};
30 Overlay_Data data9 = {PACKAGE_DATA_DIR"/images/sky_03.jpg"};
31 Overlay_Data data10 = {PACKAGE_DATA_DIR"/images/sky_03.jpg"};
32 Overlay_Data data11= {PACKAGE_DATA_DIR"/images/wood_01.jpg"};
33 Overlay_Data parking= {PACKAGE_DATA_DIR"/images/parking.png"};
34 Overlay_Data icon_data = {PACKAGE_DATA_DIR"/images/icon_14.png"};
35
36 static Elm_Map_Overlay *route_start, *route_end, *route_clas;
37 static Elm_Map_Overlay *bubble_img;
38 static Elm_Map_Overlay *bubble_parking;
39 static Elm_Map_Overlay *route_ovl;
40
41 static Evas_Object *menu, *fs_win;
42 static Elm_Map_Route *route;
43 static Elm_Map_Name *name;
44 static Evas_Object *track;
45 static const char **source_names = NULL;
46 static Evas_Coord old_x, old_y;
47 static Evas_Coord old_d;
48 static Map_Source ms[SOURCE_MAX];
49
50 static void
51 #ifdef ELM_EMAP
52 my_map_gpx_fileselector_done(void *data, Evas_Object *obj __UNUSED__, void *event_info)
53 #else
54 my_map_gpx_fileselector_done(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
55 #endif
56 {
57    const char *selected = event_info;
58
59    if (selected)
60      {
61         printf("Selected file: %s\n", selected);
62 #ifdef ELM_EMAP
63         EMap_Route *emap = emap_route_gpx_new(selected);
64         track = elm_map_track_add(data, emap);
65 #else
66         printf("libEMap is required !\n");
67 #endif
68      }
69    evas_object_del(fs_win);
70 }
71
72 static Evas_Object *
73 _route_icon_get(Evas_Object *obj)
74 {
75    Evas_Object *icon = elm_icon_add(obj);
76    elm_icon_file_set(icon, PACKAGE_DATA_DIR"/images/bubble.png", NULL);
77    evas_object_show(icon);
78
79    return icon;
80 }
81
82 static void
83 _map_clicked(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
84 {
85    printf("clicked\n");
86 }
87
88 static void
89 _map_clicked_double(void *data __UNUSED__, Evas_Object *obj, void *event_info)
90 {
91    printf("clicked,double\n");
92    double lon, lat;
93    Evas_Event_Mouse_Down *down = (Evas_Event_Mouse_Down *)event_info;
94    if (!down) return;
95    if (elm_map_zoom_get(obj) < 5) return;
96
97    elm_map_canvas_to_region_convert(obj, down->canvas.x, down->canvas.y, &lon, &lat);
98    printf("x:%d, y:%d, lon:%lf, lat:%lf\n", down->canvas.x, down->canvas.y, lon, lat);
99
100    if (!route_clas)
101      {
102         route_clas = elm_map_overlay_class_add(obj);
103         elm_map_overlay_icon_set(route_clas, _route_icon_get(obj));
104         elm_map_overlay_displayed_zoom_min_set(route_clas, 5);
105      }
106
107    if (route_start && route_end)
108      {
109         elm_map_overlay_del(route_start);
110         elm_map_overlay_del(route_end);
111 // FIXME: deprecated        
112 //        elm_map_route_remove(route);
113         route_start = NULL;
114         route_end = NULL;
115         route = NULL;
116      }
117
118    if (!route_start) route_start = elm_map_overlay_add(obj, lon, lat);
119    else route_end = elm_map_overlay_add(obj, lon, lat);
120
121    if (route_start && route_end)
122      {
123         double start_lon, start_lat, end_lon, end_lat;
124         elm_map_overlay_class_append(route_clas, route_start);
125         elm_map_overlay_class_append(route_clas, route_end);
126         elm_map_overlay_region_get(route_start, &start_lon, &start_lat);
127         elm_map_overlay_region_get(route_end, &end_lon, &end_lat);
128         route = elm_map_route_add(obj, ELM_MAP_ROUTE_TYPE_MOTOCAR,
129                                      ELM_MAP_ROUTE_METHOD_FASTEST,
130                                      start_lon, start_lat, end_lon, end_lat,
131                                      NULL, NULL);
132      }
133 }
134
135 static void
136 _map_press(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
137 {
138    printf("press\n");
139 }
140
141 static void
142 _map_longpressed(void *data __UNUSED__, Evas_Object *obj, void *event_info)
143 {
144    if (!event_info) return;
145    double lon, lat;
146    Evas_Event_Mouse_Down *down = (Evas_Event_Mouse_Down *)event_info;
147    elm_map_canvas_to_region_convert(obj, down->canvas.x, down->canvas.y, &lon, &lat);
148    printf("longpressed, x:%d, y:%d, lon:%lf, lat:%lf\n", down->canvas.x, down->canvas.y, lon, lat);
149
150    if (elm_map_zoom_get(obj) < 8) return;
151 // FIXME: deprecated        
152 //   if (name) elm_map_name_remove(name);
153    name = elm_map_name_add(obj, NULL, lon, lat, NULL, NULL);
154 }
155
156 static void
157 _map_scroll(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
158 {
159    double lon, lat;
160    elm_map_region_get(obj, &lon, &lat);
161    printf("scroll, longitude: %f latitude: %f\n", lon, lat);
162 }
163
164 static void
165 _map_drag_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
166 {
167    printf("scroll,drag,start\n");
168    evas_object_smart_callback_del(data, "longpressed", _map_longpressed);
169 }
170
171 static void
172 _map_drag_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
173 {
174    printf("scroll,drag,stop\n");
175    evas_object_smart_callback_add(data, "longpressed", _map_longpressed, data);
176 }
177
178 static void
179 _map_anim_start(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
180 {
181    printf("scroll,anim,start\n");
182 }
183
184 static void
185 _map_anim_stop(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
186 {
187    printf("scroll,anim,stop\n");
188 }
189
190 static void
191 _map_zoom_start(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
192 {
193    printf("zoom,start\n");
194 }
195
196 static void
197 _map_zoom_stop(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
198 {
199    printf("zoom,stop\n");
200 }
201
202 static void
203 _map_zoom_change(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
204 {
205    printf("zoom,change\n");
206 }
207
208 static void
209 _map_tile_load(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
210 {
211    printf("tile,load\n");
212 }
213
214 static void
215 _map_tile_loaded(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
216 {
217    int try_num, finish_num;
218    elm_map_tile_load_status_get(data, &try_num, &finish_num);
219    printf("tile,loaded: %d / %d\n", finish_num, try_num);
220 }
221
222 static void
223 _map_tile_loaded_fail(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
224 {
225    int try_num, finish_num;
226    elm_map_tile_load_status_get(data, &try_num, &finish_num);
227    printf("tile,loaded,fail: %d / %d\n", finish_num, try_num);
228 }
229
230 static void
231 _map_route_load(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
232 {
233    printf("route,load\n");
234 }
235
236 static void
237 _map_route_loaded(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
238 {
239    printf("route,loaded\n");
240    double d;
241    const char *w, *n;
242
243    d = elm_map_route_distance_get(route);
244    printf("route distance = %lf km\n", d);
245
246    w = elm_map_route_waypoint_get(route);
247    if (w) printf("[waypoints]\n%s\n", w);
248
249    n = elm_map_route_node_get(route);
250    if (n) printf("[nodes]\n%s\n", n);
251
252    if (route_ovl) elm_map_overlay_del(route_ovl);
253    route_ovl = elm_map_overlay_route_add(obj, route);
254    elm_map_overlay_color_set(route_ovl, 255, 0, 0, 255);
255 }
256
257 static void
258 _map_route_loaded_fail(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
259 {
260    printf("route,loaded,fail\n");
261 }
262
263 static void
264 _map_name_load(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
265 {
266    printf("name,load\n");
267 }
268
269 static void
270 _map_name_loaded(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
271 {
272    printf("name,loaded\n");
273    if (!name) return;
274    double lon, lat;
275    const char *addr = elm_map_name_address_get(name);
276    elm_map_name_region_get(name, &lon, &lat);
277    if (addr)
278      {
279         printf("name of [lon = %lf, lat = %lf] is %s\n", lon, lat, addr);
280         if ((lon != 0.0) && (lat !=0.0))
281           {
282              Eina_Bool b = elm_map_paused_get(data);
283              elm_map_paused_set(data, EINA_TRUE);
284              elm_map_zoom_mode_set(data, ELM_MAP_ZOOM_MODE_MANUAL);
285              elm_map_region_show(data, lon, lat);
286              elm_map_zoom_set(data, elm_map_zoom_max_get(data));
287              elm_map_paused_set(data, b);
288           }
289      }
290 // FIXME: deprecated        
291 //   elm_map_name_remove(name);
292    name = NULL;
293 }
294
295 static void
296 _map_name_loaded_fail(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
297 {
298    printf("name,loaded,fail\n");
299 }
300
301 static void
302 map_show_urmatt(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
303 {
304    Eina_Bool b = elm_map_paused_get(data);
305    elm_map_paused_set(data, EINA_TRUE);
306    elm_map_zoom_mode_set(data, ELM_MAP_ZOOM_MODE_MANUAL);
307    elm_map_region_show(data,7.325201, 48.526813);
308    elm_map_zoom_set(data, 12);
309    elm_map_paused_set(data, b);
310 }
311
312 static void
313 map_bring_seoul(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
314 {
315    elm_map_region_bring_in(data, 126.977969, 37.566535);
316 }
317
318 static void
319 map_paused_set(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
320 {
321    elm_map_paused_set(data, EINA_TRUE);
322 }
323
324 static void
325 map_paused_unset(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
326 {
327    elm_map_paused_set(data, EINA_FALSE);
328 }
329
330 static void
331 map_zoom_in(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
332 {
333    int zoom;
334
335    zoom = elm_map_zoom_get(data) + 1;
336    elm_map_zoom_mode_set(data, ELM_MAP_ZOOM_MODE_MANUAL);
337    elm_map_zoom_set(data, zoom);
338 }
339
340 static void
341 map_zoom_out(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
342 {
343    int zoom;
344
345    zoom = elm_map_zoom_get(data) - 1;
346    elm_map_zoom_mode_set(data, ELM_MAP_ZOOM_MODE_MANUAL);
347    elm_map_zoom_set(data, zoom);
348 }
349
350 static void
351 map_zoom_fit(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
352 {
353    elm_map_zoom_mode_set(data, ELM_MAP_ZOOM_MODE_AUTO_FIT);
354 }
355
356 static void
357 map_zoom_fill(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
358 {
359    elm_map_zoom_mode_set(data, ELM_MAP_ZOOM_MODE_AUTO_FILL);
360 }
361
362 static void
363 map_track_add(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
364 {
365    Evas_Object *fs, *bg, *vbox, *hbox, *sep;
366    char *path = NULL;
367
368    fs_win = elm_win_add(NULL, "fileselector", ELM_WIN_BASIC);
369    elm_win_title_set(fs_win, "File Selector");
370    elm_win_autodel_set(fs_win, 1);
371
372    bg = elm_bg_add(fs_win);
373    elm_win_resize_object_add(fs_win, bg);
374    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
375    evas_object_show(bg);
376
377    vbox = elm_box_add(fs_win);
378    elm_win_resize_object_add(fs_win, vbox);
379    evas_object_size_hint_weight_set(vbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
380    evas_object_show(vbox);
381
382    fs = elm_fileselector_add(fs_win);
383    elm_fileselector_is_save_set(fs, EINA_TRUE);
384    elm_fileselector_expandable_set(fs, EINA_FALSE);
385    path = getenv("HOME");
386    //if "HOME" is not available, set current dir. path
387    if (!path)
388      path = ".";
389    elm_fileselector_path_set(fs, path);
390    evas_object_size_hint_weight_set(fs, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
391    evas_object_size_hint_align_set(fs, EVAS_HINT_FILL, EVAS_HINT_FILL);
392    elm_box_pack_end(vbox, fs);
393    evas_object_show(fs);
394
395    evas_object_smart_callback_add(fs, "done", my_map_gpx_fileselector_done, data);
396
397    sep = elm_separator_add(fs_win);
398    elm_separator_horizontal_set(sep, EINA_TRUE);
399    elm_box_pack_end(vbox, sep);
400    evas_object_show(sep);
401
402    hbox = elm_box_add(fs_win);
403    elm_box_horizontal_set(hbox, EINA_TRUE);
404    elm_box_pack_end(vbox, hbox);
405    evas_object_show(hbox);
406
407    evas_object_resize(fs_win, 240, 350);
408    evas_object_show(fs_win);
409 }
410
411
412 static void
413 map_track_remove(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
414 {
415    elm_map_track_remove(data, track);
416 }
417
418 static void
419 map_rotate_cw(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
420 {
421    double d;
422    Evas_Coord x, y, w, h;
423    float half_w, half_h;
424    evas_object_geometry_get(data, &x, &y, &w, &h);
425    half_w = (float)w * 0.5;
426    half_h = (float)h * 0.5;
427
428    elm_map_rotate_get(data, &d, NULL, NULL);
429    d += 15.0;
430    elm_map_rotate_set(data, d, x + half_w, y + half_h);
431 }
432
433 static void
434 map_rotate_ccw(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
435 {
436    double d;
437    Evas_Coord x, y, w, h;
438    float half_w, half_h;
439    evas_object_geometry_get(data, &x, &y, &w, &h);
440    half_w = (float)w * 0.5;
441    half_h = (float)h * 0.5;
442
443    elm_map_rotate_get(data, &d, NULL, NULL);
444    d -= 15.0;
445    elm_map_rotate_set(data, d, x + half_w, y + half_h);
446 }
447
448 static void
449 map_rotate_reset(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
450 {
451    Evas_Coord x, y, w, h;
452    float half_w, half_h;
453    evas_object_geometry_get(data, &x, &y, &w, &h);
454    half_w = (float)w * 0.5;
455    half_h = (float)h * 0.5;
456
457    elm_map_rotate_set(data, 0.0, x + half_w, y + half_h);
458 }
459
460 static void
461 map_zoom_min_set(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
462 {
463    elm_map_zoom_min_set(data, 1);
464 }
465
466 static void
467 map_zoom_max_set(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
468 {
469    elm_map_zoom_max_set(data, 10);
470 }
471
472 static void
473 map_source(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
474 {
475    Map_Source *s = data;
476
477    if (!s) return;
478    elm_map_source_set(s->map, ELM_MAP_SOURCE_TYPE_TILE, s->source_name);
479 }
480
481 /*
482 static void
483 map_marker_add(void *data)
484 {
485    int i;
486    Elm_Map_Group_Class *g_clas;
487    Elm_Map_Marker_Class *m_clas;
488    Overlay_Data *d = &data7;
489
490    if (*markers) return;
491    for (i =0; i<MARKER_MAX; i++)
492      {
493         d = &data7;
494
495         int r1 = rand() % (180*2*100);
496         if (r1<=180) r1 = -r1;
497         else r1 = r1 - 180*100;
498
499         int r2 = rand() % (85*2*100);
500         if (r2<=85) r2 = -r2;
501         else r2 = r2 - 85*100;
502
503         int style = rand() % 3;
504         if (!style) m_clas = itc1;
505         else if (style == 1) m_clas = itc2;
506         else
507           {
508              m_clas = itc_parking;
509              d = &parking;
510           }
511
512         style = rand() % 2;
513         if (!style) g_clas = itc_group1;
514         else g_clas = itc_group2;
515
516         markers[i] = elm_map_marker_add(data, r1/100., r2/100., m_clas, g_clas, d);
517      }
518    nb_elts += 1000;
519    printf("nb elements: %d\n", nb_elts);
520 }
521
522 static void
523 map_marker_remove(void *data __UNUSED__)
524 {
525    int i;
526
527    for (i = 0; i<MARKER_MAX; i++)
528      {
529         if (markers[i])
530           {
531              elm_map_marker_remove(markers[i]);
532              markers[i] = NULL;
533           }
534      }
535 }
536
537 static void
538 my_map_entry_focused(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
539 {
540    const char *s = elm_scrolled_entry_entry_get(obj);
541    if (!strcmp(s, NAME_ENTRY_TEXT)) elm_scrolled_entry_entry_set(obj, "");
542 }
543
544 static void
545 my_map_entry_activated(void *data, Evas_Object *obj, void *event_info __UNUSED__)
546 {
547    const char *s = elm_scrolled_entry_entry_get(obj);
548    char *addr = strdup(s);
549    name = elm_map_utils_convert_name_into_coord(data, addr);
550    if (addr) free (addr);
551 }
552 */
553
554 static Evas_Object *
555 _box_get(Evas_Object *obj, Overlay_Data *data)
556 {
557    Evas_Object *bx, *img, *label;
558    bx = elm_box_add(obj);
559    evas_object_show(bx);
560
561    img = evas_object_image_add(evas_object_evas_get(obj));
562    evas_object_image_file_set(img, data->file, NULL);
563    evas_object_image_filled_set(img, EINA_TRUE);
564    evas_object_size_hint_min_set(img, 64, 64);
565    evas_object_show(img);
566    elm_box_pack_end(bx, img);
567
568    label = elm_label_add(obj);
569    elm_object_text_set(label, "Wolves go!!");
570    evas_object_show(label);
571    elm_box_pack_end(bx, label);
572    return bx;
573 }
574
575 static Evas_Object *
576 _icon_get(Evas_Object *obj, Overlay_Data *data)
577 {
578    Evas_Object *icon = elm_icon_add(obj);
579    elm_icon_file_set(icon, data->file, NULL);
580    evas_object_show(icon);
581
582    return icon;
583 }
584
585 static void
586 _populate(void *data, Elm_Object_Item *menu_it)
587 {
588    int idx;
589
590    if ((!data) || (!menu_it) || (!source_names)) return;
591    for (idx = 0; source_names[idx]; idx++)
592      {
593         if (idx >= SOURCE_MAX) break;
594         ms[idx].map = data;
595         ms[idx].source_name = strdup(source_names[idx]);
596         elm_menu_item_add(menu, menu_it, "", source_names[idx], map_source,
597                           &ms[idx]);
598      }
599 }
600
601 static void
602 _map_mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
603 {
604    Evas_Event_Mouse_Down *down = event_info;
605    Elm_Object_Item *menu_it;
606    if (!down) return;
607
608    if (down->button == 2)
609      {
610         old_x = down->canvas.x;
611         old_y = down->canvas.y;
612         old_d = 0.0;
613      }
614    else if (down->button == 3)
615      {
616         menu = elm_menu_add(obj);
617         menu_it = elm_menu_item_add(menu, NULL, NULL, "Source", NULL, NULL);
618         _populate(data, menu_it);
619         elm_menu_item_add(menu, NULL, NULL, "Show Urmatt", map_show_urmatt, data);
620         elm_menu_item_add(menu, NULL, NULL, "Bring Seoul", map_bring_seoul, data);
621         elm_menu_item_add(menu, NULL, NULL, "Paused Set", map_paused_set, data);
622         elm_menu_item_add(menu, NULL, NULL, "Paused Unset", map_paused_unset, data);
623         elm_menu_item_add(menu, NULL, NULL, "Zoom +", map_zoom_in, data);
624         elm_menu_item_add(menu, NULL, NULL, "Zoom -", map_zoom_out, data);
625         elm_menu_item_add(menu, NULL, NULL, "Zoom Fit", map_zoom_fit, data);
626         elm_menu_item_add(menu, NULL, NULL, "Zoom Fill", map_zoom_fill, data);
627         elm_menu_item_add(menu, NULL, NULL, "Add Track", map_track_add, data);
628         elm_menu_item_add(menu, NULL, NULL, "Remove Track", map_track_remove, data);
629         elm_menu_item_add(menu, NULL, NULL, "Add Marker", NULL, NULL);
630         elm_menu_item_add(menu, NULL, NULL, "Rotate CW", map_rotate_cw, data);
631         elm_menu_item_add(menu, NULL, NULL, "Rotate CCW", map_rotate_ccw, data);
632         elm_menu_item_add(menu, NULL, NULL, "Reset Rotate", map_rotate_reset, data);
633         elm_menu_item_add(menu, NULL, NULL, "Set Zoom Min to 1", map_zoom_min_set, data);
634         elm_menu_item_add(menu, NULL, NULL, "Set Zoom Max to 10", map_zoom_max_set, data);
635
636         elm_menu_move(menu, down->canvas.x, down->canvas.y);
637         evas_object_show(menu);
638      }
639 }
640
641 static void
642 _map_mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
643 {
644    Evas_Event_Mouse_Move *move = event_info;
645    Evas_Coord x, y, w, h;
646    float half_w, half_h;
647    int d, d_diff;
648    double cur_d;
649    if (!move) return;
650
651    if (move->buttons == 2)
652      {
653         evas_object_geometry_get(data, &x, &y, &w, &h);
654         half_w = (float)w * 0.5;
655         half_h = (float)h * 0.5;
656         elm_map_rotate_get(data, &cur_d, NULL, NULL);
657
658         d = move->cur.canvas.x - old_x;
659         if (!old_d) old_d = d;
660         else
661           {
662              d_diff = old_d - d;
663              if (d_diff > 0)
664                {
665                   old_d --;
666                   cur_d += 1.0;
667                }
668              else if (d_diff < 0)
669                {
670                   old_d ++;
671                   cur_d -= 1.0;
672                }
673              old_d = d;
674              elm_map_rotate_set(data, cur_d, x + half_w, y + half_h);
675           }
676      }
677 }
678
679 static void
680 _map_mouse_up(void *data __UNUSED__, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
681 {
682    Evas_Event_Mouse_Up *up = event_info;
683    if (!up) return;
684
685    if (up->button == 2)
686      {
687         old_x = 0;
688         old_y = 0;
689      }
690 }
691
692 static void
693 _overlay_cb(void *data __UNUSED__, Evas_Object *map, void *ev)
694 {
695    printf("Overlay clicked: ");
696    Elm_Map_Overlay *overlay = ev;
697    Evas_Object *bx;
698
699    Overlay_Data *od = elm_map_overlay_data_get(overlay);
700    if (!od)
701      {
702         printf("No overlay data\n");
703      }
704    else if (elm_map_overlay_type_get(overlay) == ELM_MAP_OVERLAY_TYPE_DEFAULT)
705      {
706         // prevent duplication
707         if (!bubble_img)  bubble_img = elm_map_overlay_bubble_add(map);
708
709         elm_map_overlay_bubble_follow(bubble_img, overlay);
710         bx = _box_get(map, od);
711         elm_map_overlay_bubble_content_clear(bubble_img);
712         elm_map_overlay_bubble_content_append(bubble_img, bx);
713         printf("overlay rendered\n");
714      }
715    else printf("not default type\n");
716 }
717
718 static void
719 _parking_cb(void *data __UNUSED__, Evas_Object *map, const Elm_Map_Overlay *ovl)
720 {
721    printf("Parking clicked\n");
722    if (elm_map_overlay_type_get(ovl) != ELM_MAP_OVERLAY_TYPE_DEFAULT) return;
723
724    double lon, lat;
725    elm_map_overlay_region_get(ovl, &lon, &lat);
726    if (!bubble_parking)
727      {
728         Evas_Object *bubble, *label;
729         bubble = elm_bubble_add(map);
730         elm_bubble_pos_set(bubble, ELM_BUBBLE_POS_BOTTOM_LEFT);
731         elm_object_text_set(bubble, "Overlay object");
732         elm_object_part_text_set(bubble, "info", "Bubble is overlayed");
733
734         label = elm_label_add(bubble);
735         elm_object_text_set(label, "Parking Here !!");
736         evas_object_show(label);
737         elm_object_content_set(bubble, label);
738
739         evas_object_resize(bubble, 125, 50);
740         evas_object_show(bubble);
741
742         bubble_parking = elm_map_overlay_add(map, lon + 0.0006, lat + 0.0006);
743         elm_map_overlay_content_set(bubble_parking, bubble);
744      }
745    elm_map_overlay_region_set(bubble_parking, lon + 0.0006, lat + 0.0006);
746 }
747
748 static void
749 _del_map(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *ei __UNUSED__)
750 {
751    if (route_start)    elm_map_overlay_del(route_start);
752    if (route_end)      elm_map_overlay_del(route_end);
753    if (route_clas)     elm_map_overlay_del(route_clas);
754    if (bubble_img)     elm_map_overlay_del(bubble_img);
755    if (bubble_parking) elm_map_overlay_del(bubble_parking);
756    if (route_ovl)      elm_map_overlay_del(route_ovl);
757    route_start = NULL;
758    route_end = NULL;
759    route_clas = NULL;
760    bubble_img = NULL;
761    bubble_parking = NULL;
762    route_ovl = NULL;
763
764 // FIXME: deprecated        
765 //   if (route) elm_map_route_remove(route);
766 // FIXME: deprecated        
767 //   if (name) elm_map_name_remove(name);
768    route = NULL;
769    name = NULL;
770 }
771
772 void
773 test_map(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
774 {
775    Evas_Object *win, *bg, *map;
776    int idx = 0;
777
778    win = elm_win_add(NULL, "map", ELM_WIN_BASIC);
779    elm_win_title_set(win, "Map");
780    elm_win_autodel_set(win, EINA_TRUE);
781
782    bg = elm_bg_add(win);
783    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
784    elm_win_resize_object_add(win, bg);
785    evas_object_show(bg);
786
787    map = elm_map_add(win);
788    if (map)
789      {
790         Elm_Map_Overlay *ovl_1, *ovl_2, *ovl_3, *ovl_4, *ovl_5, *ovl6;
791         Elm_Map_Overlay *ovl_7, *ovl_8, *ovl_9, *ovl_10, *ovl_11;
792         Elm_Map_Overlay *parking1, *parking2, *parking3, *parking4, *parking5;
793         Elm_Map_Overlay *grp1, *grp2, *grp_parking;
794
795         evas_object_event_callback_add(map, EVAS_CALLBACK_DEL, _del_map, NULL);
796
797         srand(time(NULL));
798
799         source_names = elm_map_sources_get(map, ELM_MAP_SOURCE_TYPE_TILE);
800
801         if (!source_names) return;
802         printf("map sources [ ");
803         for (idx = 0; source_names[idx] ; idx++) printf("%s, ", source_names[idx]);
804         printf("]\n");
805
806         evas_object_size_hint_weight_set(map, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
807         elm_win_resize_object_add(win, map);
808         evas_object_data_set(map, "window", win);
809
810         evas_object_event_callback_add(map, EVAS_CALLBACK_MOUSE_DOWN,
811                                        _map_mouse_down, map);
812         evas_object_event_callback_add(map, EVAS_CALLBACK_MOUSE_MOVE,
813                                        _map_mouse_move, map);
814         evas_object_event_callback_add(map, EVAS_CALLBACK_MOUSE_UP,
815                                        _map_mouse_up, map);
816
817         evas_object_smart_callback_add(map, "clicked", _map_clicked, map);
818         evas_object_smart_callback_add(map, "clicked,double", _map_clicked_double, map);
819         evas_object_smart_callback_add(map, "press", _map_press, map);
820         evas_object_smart_callback_add(map, "longpressed", _map_longpressed, map);
821         evas_object_smart_callback_add(map, "scroll", _map_scroll, map);
822         evas_object_smart_callback_add(map, "scroll,drag,start", _map_drag_start, map);
823         evas_object_smart_callback_add(map, "scroll,drag,stop", _map_drag_stop, map);
824         evas_object_smart_callback_add(map, "scroll,anim,start", _map_anim_start, map);
825         evas_object_smart_callback_add(map, "scroll,anim,stop", _map_anim_stop, map);
826         evas_object_smart_callback_add(map, "zoom,start", _map_zoom_start, map);
827         evas_object_smart_callback_add(map, "zoom,stop", _map_zoom_stop, map);
828         evas_object_smart_callback_add(map, "zoom,change", _map_zoom_change, map);
829         evas_object_smart_callback_add(map, "tile,load", _map_tile_load, map);
830         evas_object_smart_callback_add(map, "tile,loaded", _map_tile_loaded, map);
831         evas_object_smart_callback_add(map, "tile,loaded,fail", _map_tile_loaded_fail, map);
832         evas_object_smart_callback_add(map, "route,load", _map_route_load, map);
833         evas_object_smart_callback_add(map, "route,loaded", _map_route_loaded, map);
834         evas_object_smart_callback_add(map, "route,loaded,fail", _map_route_loaded_fail, map);
835         evas_object_smart_callback_add(map, "name,load", _map_name_load, map);
836         evas_object_smart_callback_add(map, "name,loaded", _map_name_loaded, map);
837         evas_object_smart_callback_add(map, "name,loaded,fail", _map_name_loaded_fail, map);
838         evas_object_smart_callback_add(map, "overlay,clicked", _overlay_cb, map);
839
840         // Create Overlays
841         ovl_1 = elm_map_overlay_add(map, 2.352, 48.857);
842         ovl_2 = elm_map_overlay_add(map, 3, 48.857);
843         ovl_3 = elm_map_overlay_add(map, 2.352, 49);
844         ovl_4 = elm_map_overlay_add(map, 7.31451, 48.857127);
845         ovl_5 = elm_map_overlay_add(map, 7.314704, 48.857119);
846         ovl6 = elm_map_overlay_add(map, 7.31432, 48.856785);
847         ovl_7 = elm_map_overlay_add(map, 7.3148, 48.85725);
848         ovl_8 = elm_map_overlay_add(map, 7.316445, 48.8572210000694);
849         ovl_9 = elm_map_overlay_add(map, 7.316527000125, 48.85609);
850         ovl_10 = elm_map_overlay_add(map, 7.3165409990833, 48.856078);
851         ovl_11 = elm_map_overlay_add(map, 7.319812, 48.856561);
852         elm_map_overlay_data_set(ovl_1, &data1);
853         elm_map_overlay_data_set(ovl_2, &data2);
854         elm_map_overlay_data_set(ovl_3, &data3);
855         elm_map_overlay_data_set(ovl_4, &data4);
856         elm_map_overlay_data_set(ovl_5, &data5);
857         elm_map_overlay_data_set(ovl6, &data6);
858         elm_map_overlay_data_set(ovl_7, &data7);
859         elm_map_overlay_data_set(ovl_8, &data8);
860         elm_map_overlay_data_set(ovl_9, &data9);
861         elm_map_overlay_data_set(ovl_10, &data10);
862         elm_map_overlay_data_set(ovl_11, &data11);
863
864         // Append overlays to groups
865         grp1 = elm_map_overlay_class_add(map);
866         elm_map_overlay_displayed_zoom_min_set(grp1, 3);
867         elm_map_overlay_class_append(grp1, ovl_1);
868         elm_map_overlay_class_append(grp1, ovl_2);
869         elm_map_overlay_class_append(grp1, ovl_3);
870         elm_map_overlay_class_append(grp1, ovl_4);
871         elm_map_overlay_class_append(grp1, ovl_5);
872         elm_map_overlay_class_append(grp1, ovl6);
873         evas_object_smart_callback_add(map, "overlay,clicked", _overlay_cb, map);
874
875         // Append overlays to groups
876         grp2 = elm_map_overlay_class_add(map);
877         elm_map_overlay_class_append(grp2, ovl_7);
878         elm_map_overlay_class_append(grp2, ovl_8);
879         elm_map_overlay_class_append(grp2, ovl_9);
880         elm_map_overlay_class_append(grp2, ovl_10);
881         elm_map_overlay_class_append(grp2, ovl_11);
882
883         // Create overlays
884         parking1 = elm_map_overlay_add(map, 127.04871, 37.25730);
885         parking2 = elm_map_overlay_add(map, 127.05578, 37.25545);
886         parking3 = elm_map_overlay_add(map, 127.05515, 37.25439);
887         parking4 = elm_map_overlay_add(map, 127.05328, 37.25721);
888         parking5 = elm_map_overlay_add(map, 127.05431, 37.25873);
889         elm_map_overlay_icon_set(parking4, _icon_get(map, &icon_data));
890         elm_map_overlay_get_cb_set(parking1, _parking_cb, NULL);
891         elm_map_overlay_get_cb_set(parking2, _parking_cb, NULL);
892         elm_map_overlay_get_cb_set(parking3, _parking_cb, NULL);
893         elm_map_overlay_get_cb_set(parking4, _parking_cb, NULL);
894         elm_map_overlay_get_cb_set(parking5, _parking_cb, NULL);
895
896         // Append overlays to groups
897         grp_parking = elm_map_overlay_class_add(map);
898         elm_map_overlay_icon_set(grp_parking, _icon_get(map, &parking));
899         elm_map_overlay_class_append(grp_parking, parking1);
900         elm_map_overlay_class_append(grp_parking, parking2);
901         elm_map_overlay_class_append(grp_parking, parking3);
902         elm_map_overlay_class_append(grp_parking, parking4);
903         elm_map_overlay_class_append(grp_parking, parking5);
904
905         evas_object_show(map);
906      }
907
908    evas_object_resize(win, 800, 800);
909    evas_object_show(win);
910 }
911 #endif