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