68c2fac7bf48cb975ddd35dc2981beb36896234e
[platform/core/api/maps-service.git] / src / view / marker_constructor.cpp
1 /* Copyright (c) 2010-2014 Samsung Electronics Co., Ltd. All rights reserved.
2  *
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17
18 #include "marker_constructor.h"
19
20 extern int _maps_view_object_create(const maps_view_object_type_e type, maps_view_object_h *object);
21
22 extern int _maps_view_object_marker_set_type(maps_view_object_h marker, maps_view_marker_type_e type);
23
24 maps_view_object_h view::marker_constructor::construct(maps_coordinates_h coordinates,
25                                                 const char *image_file_path, maps_view_marker_type_e type)
26 {
27         if (!coordinates || !image_file_path) {
28                 __error = MAPS_ERROR_INVALID_PARAMETER;
29                 return NULL;
30         }
31
32         if ((type < MAPS_VIEW_MARKER_PIN) || (type > MAPS_VIEW_MARKER_STICKER)) {
33                 __error = MAPS_ERROR_INVALID_PARAMETER;
34                 return NULL;
35         }
36
37         __error = MAPS_ERROR_NONE;
38
39         maps_view_object_h marker = NULL;
40         do {
41                 /* 1. Create a visual object for marker */
42                 __error = _maps_view_object_create(MAPS_VIEW_OBJECT_MARKER, &marker);
43                 if (__error != MAPS_ERROR_NONE)
44                         break;
45
46                 /* 2. Set the marker image file pathe */
47                 __error = maps_view_object_marker_set_image_file(marker, image_file_path);
48                 if (__error != MAPS_ERROR_NONE)
49                         break;
50
51                 /* 3. Set the marker type */
52                 __error = _maps_view_object_marker_set_type(marker, type);
53                 if (__error != MAPS_ERROR_NONE)
54                         break;
55
56                 /* 4 Move the marker to the given coordinates */
57                 __error = maps_view_object_marker_set_coordinates(marker, coordinates);
58                 if (__error != MAPS_ERROR_NONE)
59                         break;
60
61                 /* SUCCESS */
62                 return marker;
63         } while (false);
64
65         /* FAILURE: Releasing objects */
66         maps_view_object_destroy(marker);
67         return NULL;
68 }