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