Release 4.0.0-preview1-00279
[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     /// The 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 the clicked event handlers.
42         /// </summary>
43         /// <since_tizen> 3 </since_tizen>
44         public event EventHandler Clicked;
45
46         /// <summary>
47         /// Gets or sets the 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 the 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 the 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 the 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 the z-order for this marker.
115         /// </summary>
116         /// <since_tizen> 3 </since_tizen>
117         /// <value>The integer value is 0 by default, and must be in the range of -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 the 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 the marker coordinates.
142         /// </summary>
143         /// <since_tizen> 3 </since_tizen>
144         /// <param name="newPosition">New position for the 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         /// <summary>
169         /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
170         /// </summary>
171         /// <param name="disposing">If true, managed and unmanaged resources can be disposed, otherwise only unmanaged resources can be disposed.</param>
172         protected virtual void Dispose(bool disposing)
173         {
174             if (!_disposedValue)
175             {
176                 handle.Dispose();
177                 _disposedValue = true;
178             }
179         }
180
181         /// <summary>
182         /// Releases all the resources used by this object.
183         /// </summary>
184         /// <since_tizen> 3 </since_tizen>
185         public void Dispose()
186         {
187             Dispose(true);
188             GC.SuppressFinalize(this);
189         }
190
191
192         #endregion
193     }
194
195     /// <summary>
196     /// Pin type the marker map object.
197     /// </summary>
198     /// <since_tizen> 3 </since_tizen>
199     public class Pin : Marker
200     {
201         private const string defaultImagePath = "/usr/share/dotnet.tizen/framework/res/maps_marker_pin_48.png";
202
203         /// <summary>
204         /// Creates a pin type marker.
205         /// </summary>
206         /// <since_tizen> 3 </since_tizen>
207         /// <param name="coordinates">Marker coordinates.</param>
208         /// <exception cref="System.ArgumentException">Thrown when input coordinates are invalid.</exception>
209         public Pin(Geocoordinates coordinates)
210             : base(coordinates, defaultImagePath, Interop.ViewMarkerType.Pin)
211         {
212         }
213
214         /// <summary>
215         /// Creates a pin type marker.
216         /// </summary>
217         /// <since_tizen> 3 </since_tizen>
218         /// <param name="coordinates">Marker coordinates.</param>
219         /// <param name="imagePath">Image file path for the Marker.</param>
220         /// <remarks>
221         /// http://tizen.org/privilege/mediastorage is needed if the file path is relevant to media storage.
222         /// http://tizen.org/privilege/externalstorage is needed if the file path is relevant to external storage.
223         /// </remarks>
224         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
225         /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
226         /// <exception cref="System.ArgumentException">Thrown when the input coordinates or imagePath is invalid.</exception>
227         public Pin(Geocoordinates coordinates, string imagePath)
228             : base(coordinates, imagePath, Interop.ViewMarkerType.Pin)
229         {
230         }
231     }
232
233     /// <summary>
234     /// Sticker type marker map object.
235     /// </summary>
236     /// <since_tizen> 3 </since_tizen>
237     public class Sticker : Marker
238     {
239         private const string defaultImagePath = "/usr/share/dotnet.tizen/framework/res/maps_marker_sticker_48.png";
240
241         /// <summary>
242         /// Creates a sticker type marker.
243         /// </summary>
244         /// <since_tizen> 3 </since_tizen>
245         /// <param name="coordinates">Marker coordinates.</param>
246         /// <exception cref="System.ArgumentException">Thrown when input coordinates are invalid.</exception>
247         public Sticker(Geocoordinates coordinates)
248             : base(coordinates, defaultImagePath, Interop.ViewMarkerType.Sticker)
249         {
250         }
251
252         /// <summary>
253         /// Creates a sticker type marker.
254         /// </summary>
255         /// <since_tizen> 3 </since_tizen>
256         /// <param name="coordinates">Marker coordinates.</param>
257         /// <param name="imagePath">Image file path for Marker.</param>
258         /// <remarks>
259         /// http://tizen.org/privilege/mediastorage is needed if the input or output path are relevant to media storage.
260         /// http://tizen.org/privilege/externalstorage is needed if the input or output path are relevant to external storage.
261         /// </remarks>
262         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
263         /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
264         /// <exception cref="System.ArgumentException">Thrown when the input coordinates or imagePath is invalid.</exception>
265         public Sticker(Geocoordinates coordinates, string imagePath)
266             : base(coordinates, imagePath, Interop.ViewMarkerType.Sticker)
267         {
268         }
269     }
270 }