[TCAPI-2244]fixed code as code review
[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     /// <summary>
23     /// Overlay map object
24     /// </summary>
25     public class Overlay : MapObject, IDisposable
26     {
27         internal Interop.OverlayHandle handle;
28
29         /// <summary>
30         /// Creates normal overlay map object
31         /// </summary>
32         /// <param name="coordinates"></param>
33         /// <param name="objectToContain"></param>
34         /// <exception cref="ArgumentException">Throws if input coordinates or objectToContain are invalid</exception>
35         public Overlay(Geocoordinates coordinates, EvasObject objectToContain) : this(coordinates, objectToContain, Interop.ViewOverlayType.Normal)
36         {
37         }
38
39         internal Overlay(Geocoordinates coordinates, EvasObject objectToContain, Interop.ViewOverlayType type)
40         {
41             var err = Interop.ErrorCode.InvalidParameter;
42             if (coordinates == null || objectToContain == null)
43             {
44                 err.ThrowIfFailed("given coordinates or parent evas object is null");
45             }
46             handle = new Interop.OverlayHandle(coordinates.handle, objectToContain, type);
47         }
48
49         public override bool IsVisible
50         {
51             get { return handle.IsVisible; }
52             set { handle.IsVisible = value; }
53         }
54
55         /// <summary>
56         /// Geographical coordinates for overlay
57         /// </summary>
58         public Geocoordinates Coordinates
59         {
60             get
61             {
62                 return new Geocoordinates(handle.Coordinates);
63             }
64             set
65             {
66                 // Overlay takes ownership of the native handle.
67                 handle.Coordinates = value.handle;
68                 value.handle.HasOwnership = false;
69             }
70         }
71
72         /// <summary>
73         /// Minimum zoom level for overlay
74         /// </summary>
75         public int MinimumZoomLevel
76         {
77             get
78             {
79                 return handle.MinZoomLevel;
80             }
81             set
82             {
83                 handle.MinZoomLevel = value;
84             }
85         }
86
87         /// <summary>
88         /// Maximum zoom lever for overlay
89         /// </summary>
90         public int MaximumZoomLevel
91         {
92             get
93             {
94                 return handle.MaxZoomLevel;
95             }
96             set
97             {
98                 handle.MaxZoomLevel = value;
99             }
100         }
101
102         // Overlay object does not support click events
103         internal override void HandleClickedEvent()
104         {
105             throw new NotSupportedException("Overlay object does not support click events");
106         }
107
108         internal override void InvalidateMapObject()
109         {
110             handle = null;
111         }
112
113         internal override Interop.ViewObjectHandle GetHandle()
114         {
115             return handle;
116         }
117
118         #region IDisposable Support
119         private bool _disposedValue = false;
120
121         protected virtual void Dispose(bool disposing)
122         {
123             if (!_disposedValue)
124             {
125                 handle.Dispose();
126                 _disposedValue = true;
127             }
128         }
129
130         public void Dispose()
131         {
132             Dispose(true);
133             GC.SuppressFinalize(this);
134         }
135         #endregion
136     }
137
138     /// <summary>
139     /// Bubble overlay map object
140     /// </summary>
141     public class BubbleOverlay : Overlay
142     {
143         /// <summary>
144         /// Creates Box overlay
145         /// </summary>
146         /// <exception cref="ArgumentException">Throws if input coordinates or objectToContain are invalid</exception>
147         public BubbleOverlay(Geocoordinates coordinates, EvasObject objectToContain) : base(coordinates, objectToContain, Interop.ViewOverlayType.Bubble)
148         {
149         }
150     }
151
152     /// <summary>
153     /// Box Overlay map object
154     /// </summary>
155     public class BoxOverlay : Overlay
156     {
157         /// <summary>
158         /// Creates Box overlay
159         /// </summary>
160         /// <exception cref="ArgumentException">Throws if input coordinates or objectToContain are invalid</exception>
161         public BoxOverlay(Geocoordinates coordinates, EvasObject objectToContain) : base(coordinates, objectToContain, Interop.ViewOverlayType.Box)
162         {
163         }
164     }
165 }