1 /* Copyright (c) 2010-2014 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "maps_view_object.h"
20 #include "maps_view_object_plugin.h"
21 #include "maps_error.h"
22 #include "maps_util.h"
23 #include "maps_view.h"
24 #include "maps_extra_types.h"
25 #include "maps_condition.h"
26 #include "marker_constructor.h"
27 #include "polyline_constructor.h"
28 #include "polygon_constructor.h"
29 #include "overlay_constructor.h"
32 #define M_PI 3.14159265358979323846
36 * This represents marker visual object information
38 typedef struct _maps_view_marker_data_s {
39 maps_coordinates_h coordinates;
43 maps_view_marker_type_e type;
45 } maps_view_marker_data_s;
47 const gsize _MAPS_VIEW_MARKER_FILE_PATH_MAX_LENGTH = MAPS_BASE_URL_MAX_LEN;
50 * This represents polyline visual object information
52 typedef struct _maps_view_polyline_data_s {
53 /* The list of maps_coordinates_h points, comprising the polyline */
54 maps_coordinates_list_h points;
64 } maps_view_polyline_data_s;
67 * This represents polygon visual object information
69 typedef struct _maps_view_polygon_data_s {
70 /* The list of maps_coordinates_h points, comprising the polygon */
71 maps_coordinates_list_h points;
73 /* The polygon backgraund color */
78 } maps_view_polygon_data_s;
80 typedef struct _maps_view_overlay_data_s {
81 maps_coordinates_h coordinates;
85 maps_view_overlay_type_e type;
88 } maps_view_overlay_data_s;
90 const int _OVERLAY_BUBBLE_MARGIN = 20;
91 const int _OVERLAY_BUBBLE_PIN_SIZE = 20;
94 * This represents visual object information
96 typedef struct _maps_view_object_s {
97 maps_view_object_type_e type; /* marker, polyline, polygon, group */
98 void *shape_data; /* Pointer to the visual object data, such as
99 maps_view_marker_data_s or maps_view_polyline_data_s */
101 maps_view_object_h parent_group; /* The group, owning the object */
102 maps_view_h view; /* Link with the parent Map View */
103 } maps_view_object_s;
105 int _maps_view_on_object_operation(maps_view_h view, maps_view_object_h object,
106 maps_view_object_operation_e operation);
107 int _maps_view_get_parent(const maps_view_h view, Evas_Object **parent);
108 int _maps_view_get_clipper(const maps_view_h view, Evas_Object **clipper);
110 static maps_view_h __get_view(const maps_view_object_h object);
111 static maps_view_polyline_data_s *__get_polyline_data(const maps_view_object_h object);
112 static maps_view_polygon_data_s *__get_polygon_data(const maps_view_object_h object);
113 static maps_view_marker_data_s *__get_marker_data(const maps_view_object_h object);
114 static maps_view_overlay_data_s *__get_overlay_data(const maps_view_object_h object);
116 static int __maps_view_polyline_data_create(void **polyline);
117 static int __maps_view_polygon_data_create(void **polygon);
118 static int __maps_view_marker_data_create(void **marker);
119 static int __maps_view_overlay_data_create(void **marker);
121 static int __maps_view_polyline_data_destroy(void *polyline);
122 static int __maps_view_polygon_data_destroy(void *polygon);
123 static int __maps_view_marker_data_destroy(void *marker);
124 static int __maps_view_overlay_data_destroy(void *marker);
126 static maps_view_h __get_view(const maps_view_object_h object)
130 maps_view_object_s *o = (maps_view_object_s *)object;
134 static maps_view_polyline_data_s *__get_polyline_data(const maps_view_object_h object)
136 maps_view_object_s *o = (maps_view_object_s *)object;
137 if (!o || (o->type != MAPS_VIEW_OBJECT_POLYLINE))
139 return (maps_view_polyline_data_s *)o->shape_data;
142 static int __maps_view_polyline_data_create(void **polyline)
145 return MAPS_ERROR_INVALID_PARAMETER;
147 int error = MAPS_ERROR_NONE;
148 maps_view_polyline_data_s *p = NULL;
151 p = g_slice_new0(maps_view_polyline_data_s);
153 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)",
154 MAPS_ERROR_OUT_OF_MEMORY);
155 return MAPS_ERROR_OUT_OF_MEMORY;
158 error = maps_coordinates_list_create(&p->points);
159 if (error != MAPS_ERROR_NONE)
162 *polyline = (maps_view_polyline_data_s *) p;
163 return MAPS_ERROR_NONE;
166 __maps_view_polyline_data_destroy(p);
170 static int __maps_view_polyline_data_destroy(void *polyline)
173 return MAPS_ERROR_INVALID_PARAMETER;
175 maps_view_polyline_data_s *p = (maps_view_polyline_data_s *)polyline;
177 maps_coordinates_list_destroy(p->points);
179 g_slice_free(maps_view_polyline_data_s, p);
181 return MAPS_ERROR_NONE;
184 static maps_view_polygon_data_s *__get_polygon_data(const maps_view_object_h object)
186 maps_view_object_s *o = (maps_view_object_s *)object;
187 if (!o || (o->type != MAPS_VIEW_OBJECT_POLYGON))
189 return (maps_view_polygon_data_s *)o->shape_data;
192 static int __maps_view_polygon_data_create(void **polygon)
195 return MAPS_ERROR_INVALID_PARAMETER;
197 int error = MAPS_ERROR_NONE;
198 maps_view_polygon_data_s *p = NULL;
201 p = g_slice_new0(maps_view_polygon_data_s);
203 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)",
204 MAPS_ERROR_OUT_OF_MEMORY);
205 return MAPS_ERROR_OUT_OF_MEMORY;
208 error = maps_coordinates_list_create(&p->points);
209 if (error != MAPS_ERROR_NONE)
212 *polygon = (maps_view_polygon_data_s *) p;
213 return MAPS_ERROR_NONE;
216 __maps_view_polygon_data_destroy(p);
220 static int __maps_view_polygon_data_destroy(void *polygon)
223 return MAPS_ERROR_INVALID_PARAMETER;
225 maps_view_polygon_data_s *p = (maps_view_polygon_data_s *)polygon;
227 maps_coordinates_list_destroy(p->points);
229 g_slice_free(maps_view_polygon_data_s, p);
231 return MAPS_ERROR_NONE;
234 static maps_view_marker_data_s *__get_marker_data(const maps_view_object_h object)
236 maps_view_object_s *o = (maps_view_object_s *)object;
237 if (!o || (o->type != MAPS_VIEW_OBJECT_MARKER))
239 return (maps_view_marker_data_s *)o->shape_data;
242 static int __maps_view_marker_data_create(void **marker)
245 return MAPS_ERROR_INVALID_PARAMETER;
248 int error = MAPS_ERROR_NONE;
249 maps_view_marker_data_s *m = NULL;
252 m = g_slice_new0(maps_view_marker_data_s);
254 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)",
255 MAPS_ERROR_OUT_OF_MEMORY);
256 return MAPS_ERROR_OUT_OF_MEMORY;
259 error = maps_coordinates_create(.0, .0, &m->coordinates);
260 if (error != MAPS_ERROR_NONE)
263 m->type = MAPS_VIEW_MARKER_PIN;
267 *marker = (maps_view_marker_data_s *) m;
268 return MAPS_ERROR_NONE;
271 __maps_view_marker_data_destroy(m);
275 static int __maps_view_marker_data_destroy(void *marker)
278 return MAPS_ERROR_INVALID_PARAMETER;
280 maps_view_marker_data_s *m = (maps_view_marker_data_s *)marker;
282 maps_coordinates_destroy(m->coordinates);
285 g_free(m->file_path);
287 g_slice_free(maps_view_marker_data_s, m);
289 return MAPS_ERROR_NONE;
292 static maps_view_overlay_data_s *__get_overlay_data(const maps_view_object_h object)
294 maps_view_object_s *o = (maps_view_object_s *)object;
295 if (!o || (o->type != MAPS_VIEW_OBJECT_OVERLAY))
297 return (maps_view_overlay_data_s *)o->shape_data;
300 static int __maps_view_overlay_data_create(void **overlay)
303 return MAPS_ERROR_INVALID_PARAMETER;
305 int error = MAPS_ERROR_NONE;
306 maps_view_overlay_data_s *m = NULL;
309 m = g_slice_new0(maps_view_overlay_data_s);
311 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)",
312 MAPS_ERROR_OUT_OF_MEMORY);
313 return MAPS_ERROR_OUT_OF_MEMORY;
316 error = maps_coordinates_create(.0, .0, &m->coordinates);
317 if (error != MAPS_ERROR_NONE)
320 *overlay = (maps_view_overlay_data_s *) m;
321 return MAPS_ERROR_NONE;
324 __maps_view_overlay_data_destroy(m);
328 static int __maps_view_overlay_data_destroy(void *overlay)
331 return MAPS_ERROR_INVALID_PARAMETER;
333 maps_view_overlay_data_s *m = (maps_view_overlay_data_s *)overlay;
336 maps_coordinates_destroy(m->coordinates);
339 evas_object_del(m->object);
342 evas_object_del(m->bubble);
345 const Eina_List *clipees = evas_object_clipees_get(m->clipper);
346 if (!clipees || eina_list_count(clipees) == 0) {
347 evas_object_hide(m->clipper);
348 MAPS_LOGD("hide clipper");
352 g_slice_free(maps_view_overlay_data_s, m);
354 return MAPS_ERROR_NONE;
357 int _maps_view_object_create(maps_view_object_type_e type, maps_view_object_h *object)
360 return MAPS_ERROR_INVALID_PARAMETER;
361 if (type < MAPS_VIEW_OBJECT_POLYLINE || type > MAPS_VIEW_OBJECT_OVERLAY)
362 return MAPS_ERROR_INVALID_PARAMETER;
364 int error = MAPS_ERROR_NONE;
365 maps_view_object_s *o = NULL;
368 o = g_slice_new0(maps_view_object_s);
370 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)",
371 MAPS_ERROR_OUT_OF_MEMORY);
372 return MAPS_ERROR_OUT_OF_MEMORY;
379 int error = MAPS_ERROR_NONE;
381 case MAPS_VIEW_OBJECT_POLYLINE:
382 error = __maps_view_polyline_data_create(&o->shape_data);
384 case MAPS_VIEW_OBJECT_POLYGON:
385 error = __maps_view_polygon_data_create(&o->shape_data);
387 case MAPS_VIEW_OBJECT_MARKER:
388 error = __maps_view_marker_data_create(&o->shape_data);
390 case MAPS_VIEW_OBJECT_OVERLAY:
391 error = __maps_view_overlay_data_create(&o->shape_data);
397 if ((!o->shape_data) || (error != MAPS_ERROR_NONE))
400 /* Notify view, that the object was constructed */
402 _maps_view_on_object_operation(view,
404 MAPS_VIEW_OBJECT_ADD);*/
406 *object = (maps_view_object_h) o;
407 return MAPS_ERROR_NONE;
409 maps_view_object_destroy(o);
413 int _maps_view_object_set_view(maps_view_object_h object, maps_view_h view)
415 if (!object || !view)
416 return MAPS_ERROR_INVALID_PARAMETER;
418 maps_view_object_s *o = (maps_view_object_s *) object;
421 maps_view_object_type_e type;
422 maps_view_object_get_type(object, &type);
423 if (type == MAPS_VIEW_OBJECT_OVERLAY) {
424 int min_zoom = 0, max_zoom = 0;
425 maps_view_object_overlay_get_min_zoom_level(object, &min_zoom);
426 maps_view_object_overlay_get_max_zoom_level(object, &max_zoom);
428 maps_view_get_min_zoom_level(view, &min_zoom);
429 maps_view_object_overlay_set_min_zoom_level(object, min_zoom);
432 maps_view_get_max_zoom_level(view, &max_zoom);
433 maps_view_object_overlay_set_max_zoom_level(object, max_zoom);
436 return MAPS_ERROR_NONE;
439 EXPORT_API int maps_view_object_create_marker(maps_coordinates_h coordinates,
440 const char *image_file_path, maps_view_marker_type_e type, maps_view_object_h *marker)
442 if (!maps_condition_check_maps_feature())
443 return MAPS_ERROR_NOT_SUPPORTED;
444 if (!coordinates || !marker)
445 return MAPS_ERROR_INVALID_PARAMETER;
446 if (type < MAPS_VIEW_MARKER_PIN || type > MAPS_VIEW_MARKER_STICKER)
447 return MAPS_ERROR_INVALID_PARAMETER;
449 /* Create a Marker Visual Object */
450 view::marker_constructor mc;
451 *marker = mc.construct(coordinates, image_file_path, type);
452 if (mc.get_error() == MAPS_ERROR_NONE)
453 return mc.get_error();
455 /* Marker create failure */
456 maps_view_object_destroy(*marker);
458 return mc.get_error();
461 EXPORT_API int maps_view_object_create_polyline(maps_coordinates_list_h coordinates,
462 unsigned char r, unsigned char g, unsigned char b, unsigned char a, int width,
463 maps_view_object_h *polyline)
465 if (!maps_condition_check_maps_feature())
466 return MAPS_ERROR_NOT_SUPPORTED;
467 if (!coordinates || !polyline || width < 1 || width > 100)
468 return MAPS_ERROR_INVALID_PARAMETER;
470 /* Create a Polyline Visual Object */
471 view::polyline_constructor pc;
472 *polyline = pc.construct(coordinates, r, g, b, a, width);
473 if (pc.get_error() == MAPS_ERROR_NONE)
474 return pc.get_error();
476 /* Polyline create failure */
477 maps_view_object_destroy(*polyline);
479 return pc.get_error();
482 EXPORT_API int maps_view_object_create_polygon(maps_coordinates_list_h coordinates,
483 unsigned char r, unsigned char g, unsigned char b, unsigned char a, maps_view_object_h *polygon)
485 if (!maps_condition_check_maps_feature())
486 return MAPS_ERROR_NOT_SUPPORTED;
487 if (!coordinates || !polygon)
488 return MAPS_ERROR_INVALID_PARAMETER;
490 /* Create a Polygon Visual Object */
491 view::polygon_constructor pc;
492 *polygon = pc.construct(coordinates, r, g, b, a);
493 if (pc.get_error() == MAPS_ERROR_NONE)
494 return pc.get_error();
496 /* Polygon create failure */
497 maps_view_object_destroy(*polygon);
499 return pc.get_error();
502 EXPORT_API int maps_view_object_create_overlay(maps_coordinates_h coordinates,
503 Evas_Object *object, maps_view_overlay_type_e type, maps_view_object_h *overlay)
505 if (!maps_condition_check_maps_feature())
506 return MAPS_ERROR_NOT_SUPPORTED;
507 if (!overlay || !coordinates)
508 return MAPS_ERROR_INVALID_PARAMETER;
509 if (type < MAPS_VIEW_OVERLAY_NORMAL || type > MAPS_VIEW_OVERLAY_BOX)
510 return MAPS_ERROR_INVALID_PARAMETER;
513 maps_coordinates_get_latitude_longitude(coordinates, &lat, &lon);
515 /* Create a Overlay Visual Object */
516 view::overlay_constructor pc;
517 *overlay = pc.construct(coordinates, object, type);
518 if (pc.get_error() == MAPS_ERROR_NONE)
519 return pc.get_error();
521 /* Overlay create failure */
522 maps_view_object_destroy(*overlay);
524 return pc.get_error();
527 EXPORT_API int maps_view_object_destroy(maps_view_object_h object)
529 if (!maps_condition_check_maps_feature())
530 return MAPS_ERROR_NOT_SUPPORTED;
532 return MAPS_ERROR_INVALID_PARAMETER;
534 maps_view_object_s *o = (maps_view_object_s *) object;
536 /* Notify view, that the object is to be destroyed shortly */
537 _maps_view_on_object_operation(o->view, o, MAPS_VIEW_OBJECT_REMOVE);
539 int error = MAPS_ERROR_NONE;
541 case MAPS_VIEW_OBJECT_POLYLINE:
542 error = __maps_view_polyline_data_destroy(o->shape_data);
544 case MAPS_VIEW_OBJECT_POLYGON:
545 error = __maps_view_polygon_data_destroy(o->shape_data);
547 case MAPS_VIEW_OBJECT_MARKER:
548 error = __maps_view_marker_data_destroy(o->shape_data);
550 case MAPS_VIEW_OBJECT_OVERLAY:
551 error = __maps_view_overlay_data_destroy(o->shape_data);
556 g_slice_free(maps_view_object_s, object);
560 EXPORT_API int maps_view_object_get_type(maps_view_object_h object, maps_view_object_type_e *type)
562 if (!maps_condition_check_maps_feature())
563 return MAPS_ERROR_NOT_SUPPORTED;
564 if (!object || !type)
565 return MAPS_ERROR_INVALID_PARAMETER;
566 *type = ((maps_view_object_s *)object)->type;
567 return MAPS_ERROR_NONE;
572 * Visual Object Operations
575 EXPORT_API int maps_view_object_set_visible(maps_view_object_h object, bool visible)
577 if (!maps_condition_check_maps_feature())
578 return MAPS_ERROR_NOT_SUPPORTED;
580 return MAPS_ERROR_INVALID_PARAMETER;
581 maps_view_object_s *o = (maps_view_object_s *)object;
582 o->visible = visible;
584 /* Notify view, that the object visibility is changed */
585 _maps_view_on_object_operation(o->view, o, MAPS_VIEW_OBJECT_SET_VISIBLE);
587 return MAPS_ERROR_NONE;
590 EXPORT_API int maps_view_object_get_visible(const maps_view_object_h object, bool *visible)
592 if (!maps_condition_check_maps_feature())
593 return MAPS_ERROR_NOT_SUPPORTED;
594 if (!object || !visible)
595 return MAPS_ERROR_INVALID_PARAMETER;
596 maps_view_object_s *o = (maps_view_object_s *)object;
597 *visible = o->visible;
598 return MAPS_ERROR_NONE;
602 /*----------------------------------------------------------------------------*/
607 EXPORT_API int maps_view_object_polyline_set_polyline(maps_view_object_h polyline,
608 maps_coordinates_list_h points)
610 if (!maps_condition_check_maps_feature())
611 return MAPS_ERROR_NOT_SUPPORTED;
612 if (!polyline || !points)
613 return MAPS_ERROR_INVALID_PARAMETER;
615 /* Get the polyline data pointer */
616 maps_view_polyline_data_s *p = __get_polyline_data(polyline);
618 return MAPS_ERROR_INVALID_PARAMETER;
620 /* Set new polyline trajectory */
621 if (p->points != points) {
622 maps_coordinates_list_destroy(p->points);
626 /* Notify view, that the object specific preferences is changed */
627 _maps_view_on_object_operation(__get_view(polyline), polyline, MAPS_VIEW_OBJECT_CHANGE);
629 return MAPS_ERROR_NONE;
632 EXPORT_API int maps_view_object_polyline_foreach_point(maps_view_object_h polyline,
633 maps_coordinates_cb callback, void *user_data)
635 if (!maps_condition_check_maps_feature())
636 return MAPS_ERROR_NOT_SUPPORTED;
637 if (!polyline || !callback)
638 return MAPS_ERROR_INVALID_PARAMETER;
640 /* Get the polyline data pointer */
641 maps_view_polyline_data_s *p = __get_polyline_data(polyline);
643 return MAPS_ERROR_INVALID_PARAMETER;
645 return MAPS_ERROR_NOT_FOUND;
647 /* Iterate over polyline trajectory */
648 return maps_coordinates_list_foreach(p->points, callback, user_data);
651 EXPORT_API int maps_view_object_polyline_set_color(maps_view_object_h polyline,
652 unsigned char r, unsigned char g, unsigned char b, unsigned char a)
654 if (!maps_condition_check_maps_feature())
655 return MAPS_ERROR_NOT_SUPPORTED;
657 return MAPS_ERROR_INVALID_PARAMETER;
659 /* Get the polyline data pointer */
660 maps_view_polyline_data_s *p = __get_polyline_data(polyline);
662 return MAPS_ERROR_INVALID_PARAMETER;
670 /* Notify view, that the object specific preferences is changed */
671 _maps_view_on_object_operation(__get_view(polyline), polyline, MAPS_VIEW_OBJECT_CHANGE);
673 return MAPS_ERROR_NONE;
676 EXPORT_API int maps_view_object_polyline_get_color(const maps_view_object_h polyline,
677 unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a)
679 if (!maps_condition_check_maps_feature())
680 return MAPS_ERROR_NOT_SUPPORTED;
681 if (!polyline || (!r && !g && !b && !a))
682 return MAPS_ERROR_INVALID_PARAMETER;
684 /* Get the polyline data pointer */
685 maps_view_polyline_data_s *p = __get_polyline_data(polyline);
687 return MAPS_ERROR_INVALID_PARAMETER;
689 /* Retrieve the color */
698 return MAPS_ERROR_NONE;
702 EXPORT_API int maps_view_object_polyline_set_width(maps_view_object_h polyline, int width)
704 if (!maps_condition_check_maps_feature())
705 return MAPS_ERROR_NOT_SUPPORTED;
707 return MAPS_ERROR_INVALID_PARAMETER;
708 if (width < 0 || width > 100)
709 return MAPS_ERROR_INVALID_PARAMETER;
711 /* Get the polyline data pointer */
712 maps_view_polyline_data_s *p = __get_polyline_data(polyline);
714 return MAPS_ERROR_INVALID_PARAMETER;
716 /* Update the width of polyline */
719 /* Notify view, that the object specific preferences is changed */
720 _maps_view_on_object_operation(__get_view(polyline), polyline, MAPS_VIEW_OBJECT_CHANGE);
722 return MAPS_ERROR_NONE;
725 EXPORT_API int maps_view_object_polyline_get_width(const maps_view_object_h polyline, int *width)
727 if (!maps_condition_check_maps_feature())
728 return MAPS_ERROR_NOT_SUPPORTED;
729 if (!polyline || !width)
730 return MAPS_ERROR_INVALID_PARAMETER;
732 /* Get the polyline data pointer */
733 maps_view_polyline_data_s *p = __get_polyline_data(polyline);
735 return MAPS_ERROR_INVALID_PARAMETER;
737 /* Retrieve the width of the polyline */
739 return MAPS_ERROR_NONE;
742 /*----------------------------------------------------------------------------*/
747 EXPORT_API int maps_view_object_polygon_set_polygon(maps_view_object_h polygon, maps_coordinates_list_h points)
749 if (!maps_condition_check_maps_feature())
750 return MAPS_ERROR_NOT_SUPPORTED;
751 if (!polygon || !points)
752 return MAPS_ERROR_INVALID_PARAMETER;
754 /* Get the polygon data pointer */
755 maps_view_polygon_data_s *p = __get_polygon_data(polygon);
757 return MAPS_ERROR_INVALID_PARAMETER;
759 /* Set new polygon border */
760 if (p->points != points) {
761 maps_coordinates_list_destroy(p->points);
765 /* Notify view, that the object specific preferences is changed */
766 _maps_view_on_object_operation(__get_view(polygon), polygon, MAPS_VIEW_OBJECT_CHANGE);
768 return MAPS_ERROR_NONE;
771 EXPORT_API int maps_view_object_polygon_foreach_point(maps_view_object_h polygon,
772 maps_coordinates_cb callback, void *user_data)
774 if (!maps_condition_check_maps_feature())
775 return MAPS_ERROR_NOT_SUPPORTED;
776 if (!polygon || !callback)
777 return MAPS_ERROR_INVALID_PARAMETER;
779 /* Get the polygon data pointer */
780 maps_view_polygon_data_s *p = __get_polygon_data(polygon);
782 return MAPS_ERROR_INVALID_PARAMETER;
784 return MAPS_ERROR_NOT_FOUND;
786 /* Iterate over polygon border */
787 return maps_coordinates_list_foreach(p->points, callback, user_data);
791 EXPORT_API int maps_view_object_polygon_set_fill_color(maps_view_object_h polygon,
792 unsigned char r, unsigned char g, unsigned char b, unsigned char a)
794 if (!maps_condition_check_maps_feature())
795 return MAPS_ERROR_NOT_SUPPORTED;
797 return MAPS_ERROR_INVALID_PARAMETER;
799 /* Get the polygon data pointer */
800 maps_view_polygon_data_s *p = __get_polygon_data(polygon);
802 return MAPS_ERROR_INVALID_PARAMETER;
804 /* Set new background color */
810 /* Notify view, that the object specific preferences is changed */
811 _maps_view_on_object_operation(__get_view(polygon), polygon, MAPS_VIEW_OBJECT_CHANGE);
813 return MAPS_ERROR_NONE;
816 EXPORT_API int maps_view_object_polygon_get_fill_color(const maps_view_object_h polygon,
817 unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a)
819 if (!maps_condition_check_maps_feature())
820 return MAPS_ERROR_NOT_SUPPORTED;
821 if (!polygon || (!r && !g && !b && !a))
822 return MAPS_ERROR_INVALID_PARAMETER;
824 /* Get the polygon data pointer */
825 maps_view_polygon_data_s *p = __get_polygon_data(polygon);
827 return MAPS_ERROR_INVALID_PARAMETER;
829 /* Retrieve the background color */
838 return MAPS_ERROR_NONE;
842 /*----------------------------------------------------------------------------*/
847 EXPORT_API int maps_view_object_marker_set_coordinates(maps_view_object_h marker,
848 maps_coordinates_h coordinates)
850 if (!maps_condition_check_maps_feature())
851 return MAPS_ERROR_NOT_SUPPORTED;
852 if (!marker || !coordinates)
853 return MAPS_ERROR_INVALID_PARAMETER;
854 maps_view_marker_data_s *m = __get_marker_data(marker);
856 return MAPS_ERROR_INVALID_PARAMETER;
858 /* Set new coordinates */
859 if (m->coordinates != coordinates) {
860 maps_coordinates_destroy(m->coordinates);
861 m->coordinates = coordinates;
864 /* Notify view, that the object specific preferences is changed */
865 _maps_view_on_object_operation(__get_view(marker), marker, MAPS_VIEW_OBJECT_CHANGE);
867 return MAPS_ERROR_NONE;
870 EXPORT_API int maps_view_object_marker_resize(maps_view_object_h marker, int width, int height)
872 if (!maps_condition_check_maps_feature())
873 return MAPS_ERROR_NOT_SUPPORTED;
874 if (!marker || width < 0 || height < 0)
875 return MAPS_ERROR_INVALID_PARAMETER;
876 maps_view_marker_data_s *m = __get_marker_data(marker);
878 return MAPS_ERROR_INVALID_PARAMETER;
882 /* Notify view, that the object specific preferences is changed */
883 _maps_view_on_object_operation(__get_view(marker), marker, MAPS_VIEW_OBJECT_CHANGE);
885 return MAPS_ERROR_NONE;
888 EXPORT_API int maps_view_object_marker_set_image_file(maps_view_object_h marker, const char *file_path)
890 if (!maps_condition_check_maps_feature())
891 return MAPS_ERROR_NOT_SUPPORTED;
892 if (!marker || !file_path)
893 return MAPS_ERROR_INVALID_PARAMETER;
894 maps_view_marker_data_s *m = __get_marker_data(marker);
896 return MAPS_ERROR_INVALID_PARAMETER;
897 const int error = maps_set_string(file_path, _MAPS_VIEW_MARKER_FILE_PATH_MAX_LENGTH, &m->file_path);
899 /* Notify view, that the object specific preferences is changed */
900 if (error == MAPS_ERROR_NONE) {
901 maps_view_object_marker_set_size(marker, 0, 0);
902 _maps_view_on_object_operation(__get_view(marker), marker, MAPS_VIEW_OBJECT_CHANGE);
908 EXPORT_API int maps_view_object_marker_get_image_file(const maps_view_object_h marker, char **file_path)
910 if (!maps_condition_check_maps_feature())
911 return MAPS_ERROR_NOT_SUPPORTED;
912 if (!marker || !file_path)
913 return MAPS_ERROR_INVALID_PARAMETER;
914 maps_view_marker_data_s *m = __get_marker_data(marker);
916 return MAPS_ERROR_INVALID_PARAMETER;
917 return maps_get_string(m->file_path, _MAPS_VIEW_MARKER_FILE_PATH_MAX_LENGTH, file_path);
920 EXPORT_API int maps_view_object_marker_get_coordinates(const maps_view_object_h marker, maps_coordinates_h *coordinates)
922 if (!maps_condition_check_maps_feature())
923 return MAPS_ERROR_NOT_SUPPORTED;
924 if (!marker || !coordinates)
925 return MAPS_ERROR_INVALID_PARAMETER;
926 maps_view_marker_data_s *m = __get_marker_data(marker);
928 return MAPS_ERROR_INVALID_PARAMETER;
929 return maps_coordinates_clone(m->coordinates, coordinates);
932 EXPORT_API int maps_view_object_marker_set_size(maps_view_object_h marker, int width, int height)
934 if (!maps_condition_check_maps_feature())
935 return MAPS_ERROR_NOT_SUPPORTED;
936 if (!marker || width < 0 || height < 0)
937 return MAPS_ERROR_INVALID_PARAMETER;
938 maps_view_marker_data_s *m = __get_marker_data(marker);
940 return MAPS_ERROR_INVALID_PARAMETER;
943 return MAPS_ERROR_NONE;
946 EXPORT_API int maps_view_object_marker_get_size(const maps_view_object_h marker, int *width, int *height)
948 if (!maps_condition_check_maps_feature())
949 return MAPS_ERROR_NOT_SUPPORTED;
950 if (!marker || (!width && !height))
951 return MAPS_ERROR_INVALID_PARAMETER;
952 maps_view_marker_data_s *m = __get_marker_data(marker);
954 return MAPS_ERROR_INVALID_PARAMETER;
959 return MAPS_ERROR_NONE;
962 int _maps_view_object_marker_set_type(maps_view_object_h marker, maps_view_marker_type_e type)
965 return MAPS_ERROR_INVALID_PARAMETER;
966 if ((type < MAPS_VIEW_MARKER_PIN) || (type > MAPS_VIEW_MARKER_STICKER))
967 return MAPS_ERROR_INVALID_PARAMETER;
968 maps_view_marker_data_s *m = __get_marker_data(marker);
970 return MAPS_ERROR_INVALID_PARAMETER;
972 return MAPS_ERROR_NONE;
975 EXPORT_API int maps_view_object_marker_get_type(const maps_view_object_h marker, maps_view_marker_type_e *type)
977 if (!maps_condition_check_maps_feature())
978 return MAPS_ERROR_NOT_SUPPORTED;
979 if (!marker || !type)
980 return MAPS_ERROR_INVALID_PARAMETER;
981 maps_view_marker_data_s *m = __get_marker_data(marker);
983 return MAPS_ERROR_INVALID_PARAMETER;
985 return MAPS_ERROR_NONE;
988 EXPORT_API int maps_view_object_marker_set_z_order(maps_view_object_h marker, int z_order)
990 if (!maps_condition_check_maps_feature())
991 return MAPS_ERROR_NOT_SUPPORTED;
992 if (!marker || (z_order > 100 || z_order < -100))
993 return MAPS_ERROR_INVALID_PARAMETER;
994 maps_view_marker_data_s *m = __get_marker_data(marker);
996 return MAPS_ERROR_INVALID_PARAMETER;
998 /* Notify view, that the object specific preferences is changed */
999 if (m->z_order != z_order) {
1000 m->z_order = z_order;
1001 _maps_view_on_object_operation(__get_view(marker), marker, MAPS_VIEW_OBJECT_CHANGE);
1004 return MAPS_ERROR_NONE;
1007 EXPORT_API int maps_view_object_marker_get_z_order(const maps_view_object_h marker, int *z_order)
1009 if (!maps_condition_check_maps_feature())
1010 return MAPS_ERROR_NOT_SUPPORTED;
1011 if (!marker || !z_order)
1012 return MAPS_ERROR_INVALID_PARAMETER;
1013 maps_view_marker_data_s *m = __get_marker_data(marker);
1015 return MAPS_ERROR_INVALID_PARAMETER;
1017 *z_order = m->z_order;
1018 return MAPS_ERROR_NONE;
1021 int _maps_view_object_overlay_set_type(maps_view_object_h overlay, maps_view_overlay_type_e type)
1023 if (!overlay || (type < MAPS_VIEW_OVERLAY_NORMAL || type > MAPS_VIEW_OVERLAY_BOX))
1024 return MAPS_ERROR_INVALID_PARAMETER;
1025 maps_view_overlay_data_s *m = __get_overlay_data(overlay);
1027 return MAPS_ERROR_INVALID_PARAMETER;
1029 return MAPS_ERROR_NONE;
1032 int _maps_view_object_overlay_get_bubble(maps_view_object_h overlay, Evas_Object **object)
1034 if (!overlay || !object)
1035 return MAPS_ERROR_INVALID_PARAMETER;
1036 maps_view_overlay_data_s *m = __get_overlay_data(overlay);
1038 return MAPS_ERROR_INVALID_PARAMETER;
1039 *object = m->bubble;
1040 return MAPS_ERROR_NONE;
1043 int _maps_view_object_overlay_set_bubble(maps_view_object_h overlay)
1046 return MAPS_ERROR_INVALID_PARAMETER;
1047 maps_view_overlay_data_s *m = __get_overlay_data(overlay);
1049 return MAPS_ERROR_INVALID_PARAMETER;
1052 evas_object_geometry_get(m->object, &x, &y, &w, &h);
1054 w += _OVERLAY_BUBBLE_MARGIN * 2;
1055 h += _OVERLAY_BUBBLE_MARGIN * 2 + _OVERLAY_BUBBLE_PIN_SIZE;
1057 m->bubble = evas_object_image_filled_add(evas_object_evas_get(m->object));
1058 evas_object_stack_below(m->bubble, m->object);
1059 evas_object_move(m->bubble, x, y);
1060 evas_object_resize(m->bubble, w, h);
1061 evas_object_show(m->bubble);
1063 unsigned char *pixels;
1066 cairo_surface_t *surface;
1068 evas_object_image_alpha_set(m->bubble, EINA_TRUE);
1069 evas_object_image_colorspace_set(m->bubble, EVAS_COLORSPACE_ARGB8888);
1070 evas_object_image_size_set(m->bubble, w, h);
1071 evas_object_image_fill_set(m->bubble, 0, 0, w, h);
1073 pixels = (unsigned char *)evas_object_image_data_get(m->bubble, EINA_TRUE);
1074 row_stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, w);
1075 surface = cairo_image_surface_create_for_data(pixels, CAIRO_FORMAT_ARGB32,
1077 /* Create the cairo context */
1078 cairo = cairo_create(surface);
1081 cairo_set_source_rgba(cairo, 0, 0, 0, 0);
1082 cairo_paint_with_alpha(cairo, 0);
1084 /* set the size of bubble */
1087 int bw = w - bx * 2;
1088 int bh = h - by - _OVERLAY_BUBBLE_PIN_SIZE;
1091 cairo_new_path(cairo);
1092 if (m->type == MAPS_VIEW_OVERLAY_BUBBLE) {
1094 double d = M_PI / 180.;
1095 cairo_arc(cairo, bx + bw - r, by + r, r, -90 * d, 0 * d);
1096 cairo_arc(cairo, bx + bw - r, by + bh - r, r, 0 * d, 90 * d);
1097 cairo_line_to(cairo, bx + bw / 2 + _OVERLAY_BUBBLE_PIN_SIZE, by + bh);
1098 cairo_line_to(cairo, bx + bw / 2, by + bh + _OVERLAY_BUBBLE_PIN_SIZE);
1099 cairo_line_to(cairo, bx + bw / 2 - _OVERLAY_BUBBLE_PIN_SIZE, by + bh);
1100 cairo_arc(cairo, bx + r, by + bh - r, r, 90 * d, 180 * d);
1101 cairo_arc(cairo, bx + r, by + r, r, 180 * d, 270 * d);
1103 cairo_move_to(cairo, 1., 1.);
1104 cairo_line_to(cairo, 1., bh);
1105 cairo_line_to(cairo, bw / 2 - _OVERLAY_BUBBLE_PIN_SIZE, bh);
1106 cairo_line_to(cairo, bw / 2, bh + _OVERLAY_BUBBLE_PIN_SIZE);
1107 cairo_line_to(cairo, bw / 2 + _OVERLAY_BUBBLE_PIN_SIZE, bh);
1108 cairo_line_to(cairo, bw, bh);
1109 cairo_line_to(cairo, bw, 1);
1111 cairo_close_path(cairo);
1114 cairo_clip_preserve(cairo);
1115 cairo_set_source_rgb(cairo, 1., 1., 1.);
1116 cairo_fill_preserve(cairo);
1117 cairo_set_source_rgb(cairo, .1, .1, .1);
1118 cairo_set_line_width(cairo, 3);
1121 cairo_stroke(cairo);
1122 cairo_destroy(cairo);
1123 cairo_surface_destroy(surface);
1125 evas_object_image_data_set(m->bubble, pixels);
1126 evas_object_image_data_update_add(m->bubble, 0, 0, w, h);
1128 return MAPS_ERROR_NONE;
1131 EXPORT_API int maps_view_object_overlay_get_object(maps_view_object_h overlay, Evas_Object **object)
1133 if (!maps_condition_check_maps_feature())
1134 return MAPS_ERROR_NOT_SUPPORTED;
1135 if (!overlay || !object)
1136 return MAPS_ERROR_INVALID_PARAMETER;
1137 maps_view_overlay_data_s *m = __get_overlay_data(overlay);
1139 return MAPS_ERROR_INVALID_PARAMETER;
1140 *object = m->object;
1141 return MAPS_ERROR_NONE;
1144 int _maps_view_object_overlay_set_object(maps_view_object_h overlay, Evas_Object *object)
1146 if (!overlay || !object)
1147 return MAPS_ERROR_INVALID_PARAMETER;
1148 maps_view_overlay_data_s *m = __get_overlay_data(overlay);
1150 return MAPS_ERROR_INVALID_PARAMETER;
1152 if (m->type != MAPS_VIEW_OVERLAY_NORMAL)
1153 _maps_view_object_overlay_set_bubble(overlay);
1155 return MAPS_ERROR_NONE;
1158 EXPORT_API int maps_view_object_overlay_set_coordinates(maps_view_object_h overlay, maps_coordinates_h coordinates)
1160 if (!maps_condition_check_maps_feature())
1161 return MAPS_ERROR_NOT_SUPPORTED;
1162 if (!overlay || !coordinates)
1163 return MAPS_ERROR_INVALID_PARAMETER;
1164 maps_view_overlay_data_s *m = __get_overlay_data(overlay);
1166 return MAPS_ERROR_INVALID_PARAMETER;
1168 if (m->coordinates != coordinates) {
1169 maps_coordinates_destroy(m->coordinates);
1170 m->coordinates = coordinates;
1173 /* Notify view, that the object specific preferences is changed */
1174 _maps_view_on_object_operation(__get_view(overlay), overlay, MAPS_VIEW_OBJECT_CHANGE);
1176 return MAPS_ERROR_NONE;
1179 EXPORT_API int maps_view_object_overlay_get_coordinates(const maps_view_object_h overlay, maps_coordinates_h *coordinates)
1181 if (!maps_condition_check_maps_feature())
1182 return MAPS_ERROR_NOT_SUPPORTED;
1183 if (!overlay || !coordinates)
1184 return MAPS_ERROR_INVALID_PARAMETER;
1185 maps_view_overlay_data_s *m = __get_overlay_data(overlay);
1187 return MAPS_ERROR_INVALID_PARAMETER;
1188 return maps_coordinates_clone(m->coordinates, coordinates);
1191 EXPORT_API int maps_view_object_overlay_set_min_zoom_level(maps_view_object_h overlay, int zoom)
1193 if (!maps_condition_check_maps_feature())
1194 return MAPS_ERROR_NOT_SUPPORTED;
1195 if (!overlay || zoom < 0)
1196 return MAPS_ERROR_INVALID_PARAMETER;
1197 maps_view_overlay_data_s *m = __get_overlay_data(overlay);
1199 return MAPS_ERROR_INVALID_PARAMETER;
1200 int map_min_zoom_level = 0;
1201 maps_view_get_min_zoom_level(__get_view(overlay), &map_min_zoom_level);
1202 if (zoom < map_min_zoom_level)
1203 m->min_zoom_level = map_min_zoom_level;
1205 m->min_zoom_level = zoom;
1206 return MAPS_ERROR_NONE;
1209 EXPORT_API int maps_view_object_overlay_get_max_zoom_level(const maps_view_object_h overlay, int *zoom)
1211 if (!maps_condition_check_maps_feature())
1212 return MAPS_ERROR_NOT_SUPPORTED;
1213 if (!overlay || !zoom)
1214 return MAPS_ERROR_INVALID_PARAMETER;
1215 maps_view_overlay_data_s *m = __get_overlay_data(overlay);
1217 return MAPS_ERROR_INVALID_PARAMETER;
1218 *zoom = m->max_zoom_level;
1219 return MAPS_ERROR_NONE;
1222 EXPORT_API int maps_view_object_overlay_set_max_zoom_level(maps_view_object_h overlay, int zoom)
1224 if (!maps_condition_check_maps_feature())
1225 return MAPS_ERROR_NOT_SUPPORTED;
1226 if (!overlay || zoom < 0)
1227 return MAPS_ERROR_INVALID_PARAMETER;
1228 maps_view_overlay_data_s *m = __get_overlay_data(overlay);
1230 return MAPS_ERROR_INVALID_PARAMETER;
1231 int map_max_zoom_level = 0;
1232 maps_view_get_max_zoom_level(__get_view(overlay), &map_max_zoom_level);
1233 if (zoom < map_max_zoom_level)
1234 m->max_zoom_level = map_max_zoom_level;
1236 m->max_zoom_level = zoom;
1237 return MAPS_ERROR_NONE;
1240 EXPORT_API int maps_view_object_overlay_get_min_zoom_level(const maps_view_object_h overlay, int *zoom)
1242 if (!maps_condition_check_maps_feature())
1243 return MAPS_ERROR_NOT_SUPPORTED;
1244 if (!overlay || !zoom)
1245 return MAPS_ERROR_INVALID_PARAMETER;
1246 maps_view_overlay_data_s *m = __get_overlay_data(overlay);
1248 return MAPS_ERROR_INVALID_PARAMETER;
1249 *zoom = m->min_zoom_level;
1250 return MAPS_ERROR_NONE;
1253 static bool __maps_view_object_overlay_set_visible(maps_view_object_h overlay)
1258 maps_view_overlay_data_s *m = __get_overlay_data(overlay);
1262 maps_view_object_s *o = (maps_view_object_s *)overlay;
1265 maps_view_get_zoom_level(__get_view(overlay), &zoom);
1266 if (zoom < m->min_zoom_level || zoom > m->max_zoom_level) {
1267 evas_object_hide(m->object);
1269 evas_object_hide(m->bubble);
1271 evas_object_show(m->object);
1273 evas_object_show(m->bubble);
1276 evas_object_hide(m->object);
1278 evas_object_hide(m->bubble);
1283 static bool __maps_view_object_overlay_clip(maps_view_object_h overlay, Evas_Object *clipper)
1285 if (!overlay || !clipper)
1289 maps_view_get_screen_location(__get_view(overlay), &x, &y, &w, &h);
1290 maps_view_overlay_data_s *m = __get_overlay_data(overlay);
1293 evas_object_color_set(clipper, 255, 255, 255, 255);
1294 evas_object_move(clipper, x, y);
1295 evas_object_resize(clipper, w, h);
1296 evas_object_clip_set(m->object, clipper);
1298 evas_object_clip_set(m->bubble, clipper);
1299 evas_object_show(clipper);
1301 m->clipper = clipper;
1305 static bool __maps_view_object_overlay_move(maps_view_object_h overlay, maps_coordinates_h coordinates)
1307 if (!overlay || !coordinates)
1311 maps_view_geolocation_to_screen(__get_view(overlay), coordinates, &x, &y);
1312 maps_view_overlay_data_s *m = __get_overlay_data(overlay);
1315 evas_object_geometry_get(m->object, NULL, NULL, &w, &h);
1320 if (m->type != MAPS_VIEW_OVERLAY_NORMAL) {
1321 y -= _OVERLAY_BUBBLE_MARGIN + _OVERLAY_BUBBLE_PIN_SIZE;
1322 evas_object_move(m->object, x, y);
1325 x -= _OVERLAY_BUBBLE_MARGIN;
1326 y -= _OVERLAY_BUBBLE_MARGIN ;
1327 evas_object_move(m->bubble, x, y);
1330 evas_object_move(m->object, x, y);
1335 static bool __maps_view_object_overlay_update(maps_view_object_h overlay, Evas_Object *clipper)
1337 if (!overlay || !clipper)
1341 maps_coordinates_h coordinates = NULL;
1344 ret = __maps_view_object_overlay_set_visible(overlay);
1347 ret = __maps_view_object_overlay_clip(overlay, clipper);
1350 maps_view_object_overlay_get_coordinates(overlay, &coordinates);
1351 ret = __maps_view_object_overlay_move(overlay, coordinates);
1355 maps_coordinates_destroy(coordinates);
1360 bool _maps_view_object_overlay_cb(int index, int total, maps_view_object_h object, void *user_data)
1362 if (!object || !user_data)
1365 maps_view_object_type_e type;
1366 maps_view_object_get_type(object, &type);
1367 if (type != MAPS_VIEW_OBJECT_OVERLAY)
1369 return __maps_view_object_overlay_update(object, (Evas_Object*)user_data);
1372 int _maps_view_object_overlay_operation(maps_view_h view, maps_view_object_h object, maps_view_object_operation_e operation)
1374 if (!view || !object)
1375 return MAPS_ERROR_INVALID_PARAMETER;
1377 Evas_Object *parent = NULL, *clipper = NULL;
1378 maps_view_overlay_data_s *o = __get_overlay_data(object);
1381 return MAPS_ERROR_INVALID_PARAMETER;
1383 if (operation == MAPS_VIEW_OBJECT_ADD) {
1384 _maps_view_get_parent(view, &parent);
1385 evas_object_smart_member_add(o->bubble, parent);
1386 evas_object_smart_member_add(o->object, parent);
1389 if (operation != MAPS_VIEW_OBJECT_REMOVE) {
1390 _maps_view_get_clipper(view, &clipper);
1391 __maps_view_object_overlay_update(object, clipper);
1394 return MAPS_ERROR_NONE;