Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Maps / Tizen.Maps / Marker.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 ElmSharp;
19
20 namespace Tizen.Maps
21 {
22     /// <summary>
23     /// Marker map object
24     /// </summary>
25     /// <since_tizen>3</since_tizen>
26     public class Marker : MapObject, IDisposable
27     {
28         internal Interop.MarkerHandle handle;
29
30         internal Marker(Geocoordinates coordinates, string imagePath, Interop.ViewMarkerType type)
31         {
32             var err = Interop.ErrorCode.InvalidParameter;
33             if (coordinates == null || imagePath == null)
34             {
35                 err.ThrowIfFailed("given coordinates or imagePath is null");
36             }
37             handle = new Interop.MarkerHandle(coordinates.handle, imagePath, type);
38         }
39
40         /// <summary>
41         /// Gets or sets clicked event handlers.
42         /// </summary>
43         /// <since_tizen>3</since_tizen>
44         public event EventHandler Clicked;
45
46         /// <summary>
47         /// Gets or sets marker's visibility.
48         /// </summary>
49         /// <since_tizen>3</since_tizen>
50         public override bool IsVisible
51         {
52             get
53             {
54                 return handle.IsVisible;
55             }
56             set
57             {
58                 handle.IsVisible = value;
59             }
60         }
61
62         /// <summary>
63         /// Gets or sets geographical coordinates for this marker.
64         /// </summary>
65         /// <since_tizen>3</since_tizen>
66         public Geocoordinates Coordinates
67         {
68             get
69             {
70                 return new Geocoordinates(handle.Coordinates);
71             }
72             set
73             {
74                 handle.Coordinates = value.handle;
75
76                 // Marker takes ownership of the native handle.
77                 value.handle.HasOwnership = false;
78             }
79         }
80
81         /// <summary>
82         /// Gets or sets a string representing image file path for this marker.
83         /// </summary>
84         /// <since_tizen>3</since_tizen>
85         public string ImagePath
86         {
87             get
88             {
89                 return handle.ImageFile;
90             }
91             set
92             {
93                 handle.ImageFile = value;
94             }
95         }
96
97         /// <summary>
98         /// Gets or sets screen size for this marker.
99         /// </summary>
100         /// <since_tizen>3</since_tizen>
101         public Size MarkerSize
102         {
103             get
104             {
105                 return handle.MarkerSize;
106             }
107             set
108             {
109                 handle.MarkerSize = value;
110             }
111         }
112
113         /// <summary>
114         /// Gets or sets z-order for this marker.
115         /// </summary>
116         /// <since_tizen>3</since_tizen>
117         /// <value>The integer value is 0 in default, and must be in range of from -100 to 100.</value>
118         public int ZOrder
119         {
120             get
121             {
122                 return handle.ZOrder;
123             }
124             set
125             {
126                 handle.ZOrder = value;
127             }
128         }
129
130         /// <summary>
131         /// Changes marker size.
132         /// </summary>
133         /// <since_tizen>3</since_tizen>
134         /// <param name="newSize">New size</param>
135         public void Resize(Size newSize)
136         {
137             MarkerSize = newSize;
138         }
139
140         /// <summary>
141         /// Changes marker coordinates.
142         /// </summary>
143         /// <since_tizen>3</since_tizen>
144         /// <param name="newPosition">New position for marker</param>
145         public void Move(Geocoordinates newPosition)
146         {
147             Coordinates = newPosition;
148         }
149
150         internal override void HandleClickedEvent()
151         {
152             Clicked?.Invoke(this, EventArgs.Empty);
153         }
154
155         internal override void InvalidateMapObject()
156         {
157             handle = null;
158         }
159
160         internal override Interop.ViewObjectHandle GetHandle()
161         {
162             return handle;
163         }
164
165         #region IDisposable Support
166         private bool _disposedValue = false;
167
168         protected virtual void Dispose(bool disposing)
169         {
170             if (!_disposedValue)
171             {
172                 handle.Dispose();
173                 _disposedValue = true;
174             }
175         }
176
177         /// <summary>
178         /// Releases all resources used by this object.
179         /// </summary>
180         /// <since_tizen>3</since_tizen>
181         public void Dispose()
182         {
183             Dispose(true);
184             GC.SuppressFinalize(this);
185         }
186
187
188         #endregion
189     }
190
191     /// <summary>
192     /// Pin type marker map object
193     /// </summary>
194     /// <since_tizen>3</since_tizen>
195     public class Pin : Marker
196     {
197         private const string defaultImagePath = "/usr/share/dotnet.tizen/framework/res/maps_marker_pin_48.png";
198
199         /// <summary>
200         /// Creates a Pin type marker.
201         /// </summary>
202         /// <since_tizen>3</since_tizen>
203         /// <param name="coordinates">Marker coordinates</param>
204         /// <exception cref="System.ArgumentException">Thrown when input coordinates are invalid.</exception>
205         public Pin(Geocoordinates coordinates)
206             : base(coordinates, defaultImagePath, Interop.ViewMarkerType.Pin)
207         {
208         }
209
210         /// <summary>
211         /// Creates a Pin type marker.
212         /// </summary>
213         /// <since_tizen>3</since_tizen>
214         /// <param name="coordinates">Marker coordinates</param>
215         /// <param name="imagePath">Image file path for Marker</param>
216         /// <remarks>
217         /// http://tizen.org/privilege/mediastorage is needed if the file path are relevant to media storage.
218         /// http://tizen.org/privilege/externalstorage is needed if the file path are relevant to external storage.
219         /// </remarks>
220         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
221         /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
222         /// <exception cref="System.ArgumentException">Thrown when input coordinates or imagePath are invalid.</exception>
223         public Pin(Geocoordinates coordinates, string imagePath)
224             : base(coordinates, imagePath, Interop.ViewMarkerType.Pin)
225         {
226         }
227     }
228
229     /// <summary>
230     /// Sticker type marker map object
231     /// </summary>
232     /// <since_tizen>3</since_tizen>
233     public class Sticker : Marker
234     {
235         private const string defaultImagePath = "/usr/share/dotnet.tizen/framework/res/maps_marker_sticker_48.png";
236
237         /// <summary>
238         /// Creates a Sticker type marker.
239         /// </summary>
240         /// <since_tizen>3</since_tizen>
241         /// <param name="coordinates">Marker coordinates</param>
242         /// <exception cref="System.ArgumentException">Thrown when input coordinates are invalid.</exception>
243         public Sticker(Geocoordinates coordinates)
244             : base(coordinates, defaultImagePath, Interop.ViewMarkerType.Sticker)
245         {
246         }
247
248         /// <summary>
249         /// Creates a Sticker type marker.
250         /// </summary>
251         /// <since_tizen>3</since_tizen>
252         /// <param name="coordinates">Marker coordinates</param>
253         /// <param name="imagePath">Image file path for Marker</param>
254         /// <remarks>
255         /// http://tizen.org/privilege/mediastorage is needed if input or output path are relevant to media storage.
256         /// http://tizen.org/privilege/externalstorage is needed if input or output path are relevant to external storage.
257         /// </remarks>
258         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
259         /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
260         /// <exception cref="System.ArgumentException">Thrown when input coordinates or imagePath are invalid.</exception>
261         public Sticker(Geocoordinates coordinates, string imagePath)
262             : base(coordinates, imagePath, Interop.ViewMarkerType.Sticker)
263         {
264         }
265     }
266 }