Tizen.Maps Setup
[platform/core/csapi/tizenfx.git] / src / Tizen.Maps / Tizen.Maps / Overlay.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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 using System;
18 using EvasObject = ElmSharp.EvasObject;
19
20 namespace Tizen.Maps
21 {
22     public class Overlay : MapObject
23     {
24         private EvasObject _containedObject;
25
26         public Overlay(Geocoordinates coordinates, EvasObject objectToContain) : this(coordinates, objectToContain, Interop.ViewOverlayType.Normal)
27         {
28         }
29
30         internal Overlay(Interop.ViewObjectHandle nativeHandle) : base(nativeHandle)
31         {
32         }
33
34         internal Overlay(Geocoordinates coordinates, EvasObject objectToContain, Interop.ViewOverlayType type) : base(CreateNativeHandle(coordinates, objectToContain, type))
35         {
36             var err = Interop.ErrorCode.InvalidParameter;
37             if (coordinates == null || objectToContain == null)
38             {
39                 err.ThrowIfFailed("given coordinates or parent evas object is null");
40             }
41
42             _containedObject = objectToContain;
43         }
44
45         public Geocoordinates Coordinates
46         {
47             get
48             {
49                 IntPtr nativeHandle;
50                 Interop.ViewObject.OverlayGetCoordinates(handle, out nativeHandle);
51                 return new Geocoordinates(nativeHandle);
52             }
53             set
54             {
55                 // Overlay takes ownership of the native handle.
56                 IntPtr nativeHandle;
57                 var err = Interop.Coordinates.Clone(value.handle, out nativeHandle);
58                 err.WarnIfFailed("Failed to clone native handle for coordinates");
59
60                 Interop.CoordinatesHandle clonedHandle = new Interop.CoordinatesHandle(nativeHandle);
61                 err = Interop.ViewObject.OverlaySetCoordinates(handle, clonedHandle);
62                 if (err.WarnIfFailed("Failed to set coordinates to overlay"))
63                 {
64                     clonedHandle.ReleaseOwnership();
65                 }
66             }
67         }
68
69         public int MinimumZoomLevel
70         {
71             get
72             {
73                 int value;
74                 Interop.ViewObject.OverlayGetMinZoomLevel(handle, out value);
75                 return value;
76             }
77             set
78             {
79                 Interop.ViewObject.OverlaySetMinZoomLevel(handle, value);
80             }
81         }
82
83         public int MaximumZoomLevel
84         {
85             get
86             {
87                 int value;
88                 Interop.ViewObject.OverlayGetMaxZoomLevel(handle, out value);
89                 return value;
90             }
91             set
92             {
93                 Interop.ViewObject.OverlaySetMaxZoomLevel(handle, value);
94             }
95         }
96
97         private static Interop.ViewObjectHandle CreateNativeHandle(Geocoordinates coordinates, EvasObject objectToContain, Interop.ViewOverlayType type)
98         {
99             if (coordinates == null || objectToContain == null) return new Interop.ViewObjectHandle(IntPtr.Zero);
100
101             IntPtr nativeHandle;
102             var err = Interop.Coordinates.Clone(coordinates.handle, out nativeHandle);
103             err.ThrowIfFailed("Failed to clone native handle for coordinates");
104
105             Interop.CoordinatesHandle clonedHandle = new Interop.CoordinatesHandle(nativeHandle);
106             err = Interop.ViewObject.CreateOverlay(clonedHandle, objectToContain, type, out nativeHandle);
107             err.ThrowIfFailed("Failed to create native handle for Overlay");
108
109             clonedHandle.ReleaseOwnership();
110             return new Interop.ViewObjectHandle(nativeHandle);
111         }
112     }
113
114     public class BubbleOverlay : Overlay
115     {
116         public BubbleOverlay(Geocoordinates coordinates, EvasObject objectToContain) : base(coordinates, objectToContain, Interop.ViewOverlayType.Bubble)
117         {
118         }
119     }
120
121     public class BoxOverlay : Overlay
122     {
123         public BoxOverlay(Geocoordinates coordinates, EvasObject objectToContain) : base(coordinates, objectToContain, Interop.ViewOverlayType.Box)
124         {
125         }
126     }
127 }