[Maps] Modify diposing routines
[platform/core/csapi/tizenfx.git] / src / Tizen.Maps / Tizen.Maps / MapView.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 using Layout = ElmSharp.Layout;
20 using EvasObject = ElmSharp.EvasObject;
21 using System.Collections.Generic;
22
23 namespace Tizen.Maps
24 {
25     /// <summary>
26     /// Map View class to show a map on the screen.
27     /// </summary>
28     /// <since_tizen> 3 </since_tizen>
29     public class MapView : Layout, IDisposable
30     {
31         internal Interop.ViewHandle handle;
32         private MapService _service;
33
34         private Dictionary<IntPtr, MapObject> _handleToObjectTable = new Dictionary<IntPtr, MapObject>();
35
36         private Interop.ViewOnEventCallback _gestureEventCallback;
37         private Interop.ViewOnEventCallback _objectEventCallback;
38         private Interop.ViewOnEventCallback _viewReadyEventCallback;
39
40         private event EventHandler<MapGestureEventArgs> _scrolledEventHandler;
41         private event EventHandler<MapGestureEventArgs> _twoFingerZoomedEventHandler;
42         private event EventHandler<MapGestureEventArgs> _clickedEventHandler;
43         private event EventHandler<MapGestureEventArgs> _doubleClickedEventHandler;
44         private event EventHandler<MapGestureEventArgs> _twoFingerClickedEventHandler;
45         private event EventHandler<MapGestureEventArgs> _twoFingerRotatedEventHandler;
46         private event EventHandler<MapGestureEventArgs> _longPressedEventHandler;
47         private event EventHandler _viewReadyEventHandler;
48
49         /// <summary>
50         /// Creates a view and links it to the instance of a map service.
51         /// </summary>
52         /// <since_tizen> 3 </since_tizen>
53         /// <param name="parent">An instance of <see cref="EvasObject"/> object for which a map view will be drawn.</param>
54         /// <param name="service">An instance of <see cref="MapService"/> object.</param>
55         /// <privilege>http://tizen.org/privilege/mapservice</privilege>
56         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
57         /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
58         /// <exception cref="System.ArgumentException">Thrown when parameters are invalid.</exception>
59         /// <exception cref="System.InvalidOperationException">Thrown when a native operation failed to allocate memory, and connect to the service.</exception>
60         public MapView(EvasObject parent, MapService service) : base(parent)
61         {
62             handle = new Interop.ViewHandle(service.handle, this);
63             Log.Info(string.Format("MapView is created"));
64
65             _service = service;
66             this.Resize(1, 1);
67
68             // We need to keep Gesture Tap event enabled for object event to work
69             handle.SetGestureEnabled(Interop.ViewGesture.Click, true);
70             SetObjectEventCallback();
71         }
72
73         /// <summary>
74         /// Destroy the MapView object.
75         /// </summary>
76         ~MapView()
77         {
78             Dispose(false);
79         }
80
81         /// <summary>
82         /// Adds or removes event handlers to deliver a scrolled gesture event.
83         /// </summary>
84         /// <value>Event handlers to get a scrolled gesture event.</value>
85         /// <since_tizen> 3 </since_tizen>
86         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
87         public event EventHandler<MapGestureEventArgs> Scrolled
88         {
89             add
90             {
91                 SetGestureEventCallback();
92                 handle.SetGestureEnabled(Interop.ViewGesture.Scroll, true);
93                 _scrolledEventHandler += value;
94                 Log.Info(string.Format("Scrolled event handler is added"));
95             }
96             remove
97             {
98                 _scrolledEventHandler -= value;
99                 Log.Info(string.Format("Scrolled event handler is removed"));
100                 if (_scrolledEventHandler == null)
101                 {
102                     handle.SetGestureEnabled(Interop.ViewGesture.Scroll, false);
103                     UnsetGestureEventCallback();
104                 }
105             }
106         }
107
108         /// <summary>
109         /// Adds or removes event handlers to deliver a zoomed gesture event.
110         /// </summary>
111         /// <value>Event handlers to get a zoomed gesture event.</value>
112         /// <since_tizen> 3 </since_tizen>
113         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
114         public event EventHandler<MapGestureEventArgs> TwoFingerZoomed
115         {
116             add
117             {
118                 SetGestureEventCallback();
119                 handle.SetGestureEnabled(Interop.ViewGesture.Zoom, true);
120                 _twoFingerZoomedEventHandler += value;
121                 Log.Info(string.Format("TwoFingerZoomed event handler is added"));
122             }
123             remove
124             {
125                 _twoFingerZoomedEventHandler -= value;
126                 Log.Info(string.Format("TwoFingerZoomed event handler is removed"));
127                 if (_twoFingerZoomedEventHandler == null)
128                 {
129                     handle.SetGestureEnabled(Interop.ViewGesture.Zoom, false);
130                     UnsetGestureEventCallback();
131                 }
132             }
133         }
134
135         /// <summary>
136         /// Adds or removes event handlers to deliver a clicked gesture event.
137         /// </summary>
138         /// <value>Event handlers to get a clicked gesture event.</value>
139         /// <since_tizen> 3 </since_tizen>
140         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
141         public event EventHandler<MapGestureEventArgs> Clicked
142         {
143             add
144             {
145                 SetGestureEventCallback();
146                 //handle.SetGestureEnabled(Interop.ViewGesture.Click, true);
147                 _clickedEventHandler += value;
148                 Log.Info(string.Format("Clicked event handler is added"));
149             }
150             remove
151             {
152                 _clickedEventHandler -= value;
153                 Log.Info(string.Format("Clicked event handler is removed"));
154                 if (_clickedEventHandler == null)
155                 {
156                     //handle.SetGestureEnabled(Interop.ViewGesture.Click, false);
157                     UnsetGestureEventCallback();
158                 }
159             }
160         }
161
162         /// <summary>
163         /// Adds or removes event handlers to deliver a double-clicked gesture event.
164         /// </summary>
165         /// <value>Event handlers to get a double-clicked gesture event.</value>
166         /// <since_tizen> 3 </since_tizen>
167         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
168         public event EventHandler<MapGestureEventArgs> DoubleClicked
169         {
170             add
171             {
172                 SetGestureEventCallback();
173                 handle.SetGestureEnabled(Interop.ViewGesture.DoubleClick, true);
174                 _doubleClickedEventHandler += value;
175                 Log.Info(string.Format("DoubleClicked event handler is removed"));
176             }
177             remove
178             {
179                 _doubleClickedEventHandler -= value;
180                 Log.Info(string.Format("DoubleClicked event handler is removed"));
181                 if (_doubleClickedEventHandler == null)
182                 {
183                     handle.SetGestureEnabled(Interop.ViewGesture.DoubleClick, false);
184                     UnsetGestureEventCallback();
185                 }
186             }
187         }
188
189         /// <summary>
190         /// Adds or removes event handlers to deliver a clicked gesture event with two-fingers.
191         /// </summary>
192         /// <value>Event handlers to get a clicked gesture event.</value>
193         /// <since_tizen> 3 </since_tizen>
194         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
195         public event EventHandler<MapGestureEventArgs> TwoFingerClicked
196         {
197             add
198             {
199                 SetGestureEventCallback();
200                 handle.SetGestureEnabled(Interop.ViewGesture.TwoFingerClick, true);
201                 _twoFingerClickedEventHandler += value;
202                 Log.Info(string.Format("TwoFingerClicked event handler is added"));
203             }
204             remove
205             {
206                 _twoFingerClickedEventHandler -= value;
207                 Log.Info(string.Format("TwoFingerClicked event handler is removed"));
208                 if (_twoFingerClickedEventHandler == null)
209                 {
210                     handle.SetGestureEnabled(Interop.ViewGesture.TwoFingerClick, false);
211                     UnsetGestureEventCallback();
212                 }
213             }
214         }
215
216         /// <summary>
217         /// Adds or removes event handlers to deliver a rotated gesture event.
218         /// </summary>
219         /// <value>Event handlers to get a rotated gesture event.</value>
220         /// <since_tizen> 3 </since_tizen>
221         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
222         public event EventHandler<MapGestureEventArgs> TwoFingerRotated
223         {
224             add
225             {
226                 SetGestureEventCallback();
227                 handle.SetGestureEnabled(Interop.ViewGesture.Rotation, true);
228                 _twoFingerRotatedEventHandler += value;
229                 Log.Info(string.Format("Rotated event handler is added"));
230             }
231             remove
232             {
233                 _twoFingerRotatedEventHandler -= value;
234                 Log.Info(string.Format("Rotated event handler is removed"));
235                 if (_twoFingerRotatedEventHandler == null)
236                 {
237                     handle.SetGestureEnabled(Interop.ViewGesture.Rotation, false);
238                     UnsetGestureEventCallback();
239                 }
240             }
241         }
242
243
244         /// <summary>
245         /// Adds or removes event handlers to deliver a long-pressed gesture event.
246         /// </summary>
247         /// <value>Event handlers to get a long-pressed gesture event.</value>
248         /// <since_tizen> 3 </since_tizen>
249         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
250         public event EventHandler<MapGestureEventArgs> LongPressed
251         {
252             add
253             {
254                 SetGestureEventCallback();
255                 handle.SetGestureEnabled(Interop.ViewGesture.LongPress, true);
256                 _longPressedEventHandler += value;
257                 Log.Info(string.Format("LongPressed event handler is added"));
258             }
259             remove
260             {
261                 _longPressedEventHandler -= value;
262                 Log.Info(string.Format("LongPressed event handler is removed"));
263                 if (_longPressedEventHandler == null)
264                 {
265                     handle.SetGestureEnabled(Interop.ViewGesture.LongPress, false);
266                     UnsetGestureEventCallback();
267                 }
268             }
269         }
270
271         /// <summary>
272         /// Adds or removes event handlers to deliver an event representing a view ready to be used.
273         /// </summary>
274         /// <value>Event handlers to get a view ready event.</value>
275         /// <since_tizen> 3 </since_tizen>
276         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
277         public event EventHandler ViewReady
278         {
279             add
280             {
281                 SetViewReadyEventCallback();
282                 _viewReadyEventHandler += value;
283                 Log.Info(string.Format("ViewReady event handler is added"));
284             }
285             remove
286             {
287                 _viewReadyEventHandler -= value;
288                 Log.Info(string.Format("ViewReady event handler is removed"));
289                 UnsetGestureEventCallback();
290             }
291         }
292
293         /// <summary>
294         /// Gets or sets the current zoom level.
295         /// </summary>
296         /// <value>It is an integer value representing the current zoom level.</value>
297         /// <since_tizen> 3 </since_tizen>
298         /// <privilege>http://tizen.org/privilege/mapservice</privilege>
299         /// <privilege>http://tizen.org/privilege/internet</privilege>
300         /// <privilege>http://tizen.org/privilege/network.get</privilege>
301         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
302         /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
303         public int ZoomLevel
304         {
305             get
306             {
307                 return handle.ZoomLevel;
308             }
309             set
310             {
311                 Log.Info(string.Format("ZoomLevel is changed from {0} to {1}", handle.ZoomLevel, value));
312                 handle.ZoomLevel = value;
313             }
314         }
315
316         /// <summary>
317         /// Gets or sets the minimum zoom level.
318         /// </summary>
319         /// <value>It is an integer value that limits minimal zoom level within a range of the current map plug-in support.</value>
320         /// <since_tizen> 3 </since_tizen>
321         /// <privilege>http://tizen.org/privilege/mapservice</privilege>
322         /// <privilege>http://tizen.org/privilege/internet</privilege>
323         /// <privilege>http://tizen.org/privilege/network.get</privilege>
324         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
325         /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
326         public int MinimumZoomLevel
327         {
328             get
329             {
330                 return handle.MinimumZoomLevel;
331             }
332             set
333             {
334                 Log.Info(string.Format("MinimumZoomLevel is changed from {0} to {1}", handle.MinimumZoomLevel, value));
335                 handle.MinimumZoomLevel = value;
336             }
337         }
338
339         /// <summary>
340         /// Gets or sets the maximum zoom level.
341         /// </summary>
342         /// <value>It is an integer value that limits maximum zoom level within a range of the current map plug-in support.</value>
343         /// <since_tizen> 3 </since_tizen>
344         /// <privilege>http://tizen.org/privilege/mapservice</privilege>
345         /// <privilege>http://tizen.org/privilege/internet</privilege>
346         /// <privilege>http://tizen.org/privilege/network.get</privilege>
347         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
348         /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
349         public int MaximumZoomLevel
350         {
351             get
352             {
353                 return handle.MaximumZoomLevel;
354             }
355             set
356             {
357                 Log.Info(string.Format("MaximumZoomLevel is changed from {0} to {1}", handle.MaximumZoomLevel, value));
358                 handle.MaximumZoomLevel = value;
359             }
360         }
361
362         /// <summary>
363         /// Gets or sets the orientation on the map view.
364         /// </summary>
365         /// <value>It is an integer value from 0 to 360 that indicates the orientation of the map view.</value>
366         /// <since_tizen> 3 </since_tizen>
367         /// <privilege>http://tizen.org/privilege/mapservice</privilege>
368         /// <privilege>http://tizen.org/privilege/internet</privilege>
369         /// <privilege>http://tizen.org/privilege/network.get</privilege>
370         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
371         /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
372         public double Orientation
373         {
374             get
375             {
376                 return handle.Orientation;
377             }
378             set
379             {
380                 Log.Info(string.Format("Orientation is changed from {0} to {1}", handle.Orientation, value));
381                 handle.Orientation = value;
382             }
383         }
384
385         /// <summary>
386         /// Gets or sets theme type of the map view.
387         /// </summary>
388         /// <since_tizen> 3 </since_tizen>
389         /// <privilege>http://tizen.org/privilege/mapservice</privilege>
390         /// <privilege>http://tizen.org/privilege/internet</privilege>
391         /// <privilege>http://tizen.org/privilege/network.get</privilege>
392         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
393         /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
394         public MapTypes MapType
395         {
396             get
397             {
398                 return (MapTypes)handle.MapType;
399             }
400             set
401             {
402                 Log.Info(string.Format("MapType is changed from {0} to {1}", handle.MapType, value));
403                 handle.MapType = (Interop.ViewType)value;
404             }
405         }
406
407         /// <summary>
408         /// Indicates whether the map should show the 3D buildings layer.
409         /// </summary>
410         /// <since_tizen> 3 </since_tizen>
411         /// <privilege>http://tizen.org/privilege/mapservice</privilege>
412         /// <privilege>http://tizen.org/privilege/internet</privilege>
413         /// <privilege>http://tizen.org/privilege/network.get</privilege>
414         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
415         /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
416         public bool BuildingsEnabled
417         {
418             get
419             {
420                 return handle.BuildingsEnabled;
421             }
422             set
423             {
424                 Log.Info(string.Format("Showing the 3D buildings is {0}", (value ? "enabled" : "disabled")));
425                 handle.BuildingsEnabled = value;
426             }
427         }
428
429         /// <summary>
430         /// Indicates whether the map should show the traffic layer.
431         /// </summary>
432         /// <since_tizen> 3 </since_tizen>
433         /// <privilege>http://tizen.org/privilege/mapservice</privilege>
434         /// <privilege>http://tizen.org/privilege/internet</privilege>
435         /// <privilege>http://tizen.org/privilege/network.get</privilege>
436         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
437         /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
438         public bool TrafficEnabled
439         {
440             get
441             {
442                 return handle.TrafficEnabled;
443             }
444             set
445             {
446                 Log.Info(string.Format("Showing the traffic is {0}", (value ? "enabled" : "disabled")));
447                 handle.TrafficEnabled = value;
448             }
449         }
450
451         /// <summary>
452         /// Indicates whether the map should show the public transit layer.
453         /// </summary>
454         /// <since_tizen> 3 </since_tizen>
455         /// <privilege>http://tizen.org/privilege/mapservice</privilege>
456         /// <privilege>http://tizen.org/privilege/internet</privilege>
457         /// <privilege>http://tizen.org/privilege/network.get</privilege>
458         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
459         /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
460         public bool PublicTransitEnabled
461         {
462             get
463             {
464                 return handle.PublicTransitEnabled;
465             }
466             set
467             {
468                 Log.Info(string.Format("Showing the public transit is {0}", (value ? "enabled" : "disabled")));
469                 handle.PublicTransitEnabled = value;
470             }
471         }
472
473         /// <summary>
474         /// Indicates whether the scale-bar is enabled or not.
475         /// </summary>
476         /// <since_tizen> 4 </since_tizen>
477         /// <privilege>http://tizen.org/privilege/mapservice</privilege>
478         /// <privilege>http://tizen.org/privilege/internet</privilege>
479         /// <privilege>http://tizen.org/privilege/network.get</privilege>
480         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
481         /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
482         public bool ScaleBarEnabled
483         {
484             get
485             {
486                 return handle.ScaleBarEnabled;
487             }
488             set
489             {
490                 Log.Info(string.Format("Showing the scale-bar is {0}", (value ? "enabled" : "disabled")));
491                 handle.ScaleBarEnabled = value;
492             }
493         }
494
495         /// <summary>
496         /// Sets language of map view.
497         /// </summary>
498         /// <value>The display language in the map.
499         /// A language is specified as an ISO 3166 alpha-2 two letter country-code
500         /// followed by ISO 639-1 for the two-letter language code.
501         /// Each language tag is composed of one or more "subtags" separated by hyphens (-).
502         /// Each subtag is composed of basic Latin letters or digits only.
503         /// For example, "ko-KR" for Korean, "en-US" for American English.</value>
504         /// <since_tizen> 3 </since_tizen>
505         /// <privilege>http://tizen.org/privilege/mapservice</privilege>
506         /// <privilege>http://tizen.org/privilege/internet</privilege>
507         /// <privilege>http://tizen.org/privilege/network.get</privilege>
508         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
509         /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
510         /// <exception cref="System.ArgumentException">Thrown when the value is invalid.</exception>
511         public string Language
512         {
513             get
514             {
515                 return handle.Language;
516             }
517             set
518             {
519                 Log.Info(string.Format("Language is changed from {0} to {1}", handle.Language, value));
520                 handle.Language = value;
521             }
522         }
523
524         /// <summary>
525         /// Gets or sets geographical coordinates for map view's center.
526         /// </summary>
527         /// <since_tizen> 3 </since_tizen>
528         /// <privilege>http://tizen.org/privilege/mapservice</privilege>
529         /// <privilege>http://tizen.org/privilege/internet</privilege>
530         /// <privilege>http://tizen.org/privilege/network.get</privilege>
531         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
532         /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
533         /// <exception cref="System.ArgumentException">Thrown when the value is invalid.</exception>
534         public Geocoordinates Center
535         {
536             get
537             {
538                 return new Geocoordinates(handle.Center);
539             }
540             set
541             {
542                 Log.Info(string.Format("Center is changed from {0} to {1}", handle.Center.ToString(), value.ToString()));
543                 handle.Center = value.handle;
544             }
545         }
546
547         /// <summary>
548         /// Gets a list of the map object added to map view.
549         /// </summary>
550         /// <since_tizen> 3 </since_tizen>
551         public new IEnumerable<MapObject> Children
552         {
553             get
554             {
555                 return _handleToObjectTable.Values;
556             }
557         }
558
559         /// <summary>
560         /// Changes the geographical coordinates to screen coordinates.
561         /// </summary>
562         /// <since_tizen> 3 </since_tizen>
563         /// <param name="coordinates">Geographical coordinates.</param>
564         /// <returns>Returns an instance of the screen coordinates on the current screen.</returns>
565         /// <privilege>http://tizen.org/privilege/mapservice</privilege>
566         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
567         /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
568         /// <exception cref="System.ArgumentException">Thrown when the value is invalid.</exception>
569         /// <exception cref="System.InvalidOperationException">Thrown when a native operation failed to allocate memory and connect to the service.</exception>
570         public Point GeolocationToScreen(Geocoordinates coordinates)
571         {
572             return handle.GeolocationToScreen(coordinates.handle);
573         }
574
575         /// <summary>
576         /// Changes the screen coordinates to geographical coordinates.
577         /// </summary>
578         /// <since_tizen> 3 </since_tizen>
579         /// <param name="screenCoordinates">Screen coordinates.</param>
580         /// <returns>Returns an instance of the geographical coordinates object.</returns>
581         /// <privilege>http://tizen.org/privilege/mapservice</privilege>
582         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
583         /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
584         /// <exception cref="System.ArgumentException">Thrown when the value is invalid.</exception>
585         /// <exception cref="System.InvalidOperationException">Thrown when a native operation failed to allocate memory and connect to the service.</exception>
586         public Geocoordinates ScreenToGeolocation(Point screenCoordinates)
587         {
588             return new Geocoordinates(handle.ScreenToGeolocation(screenCoordinates));
589         }
590
591         /// <summary>
592         /// Adds a map object to map view.
593         /// </summary>
594         /// <since_tizen> 3 </since_tizen>
595         /// <param name="child">An instance of the map object to be added.</param>
596         /// <privilege>http://tizen.org/privilege/mapservice</privilege>
597         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
598         /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
599         /// <exception cref="System.ArgumentException">Thrown when the value is invalid.</exception>
600         /// <exception cref="System.InvalidOperationException">Thrown when a native operation failed to allocate memory and connect to the service.</exception>
601         public void Add(MapObject child)
602         {
603             Log.Info(string.Format("Add a object"));
604             var objectHandle = child.GetHandle();
605             if (!_handleToObjectTable.ContainsKey(objectHandle))
606             {
607                 _handleToObjectTable[objectHandle] = child;
608                 handle.AddObject(objectHandle);
609
610                 // MapView take ownership of added map objects
611                 objectHandle.HasOwnership = false;
612             }
613         }
614
615         /// <summary>
616         /// Removes a map object from the map view.
617         /// </summary>
618         /// <since_tizen> 3 </since_tizen>
619         /// <param name="child">An instance of the map object to be removed.</param>
620         /// <remarks>Once removed, the child object will be become invalid.</remarks>
621         /// <privilege>http://tizen.org/privilege/mapservice</privilege>
622         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
623         /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
624         /// <exception cref="System.ArgumentException">Thrown when the value is invalid.</exception>
625         /// <exception cref="System.InvalidOperationException">Thrown when native operation failed to allocate memory and connect to the service.</exception>
626         public void Remove(MapObject child)
627         {
628             Log.Info(string.Format("Remove a object"));
629             var objectHandle = child.GetHandle();
630             if (_handleToObjectTable.Remove(objectHandle))
631             {
632                 handle.RemoveObject(child.GetHandle());
633
634                 // The object handle will be released automatically by the View, once RemoveObject call is successful
635                 child.InvalidateMapObject();
636             }
637         }
638
639         /// <summary>
640         /// Removes all map objects from the map view.
641         /// </summary>
642         /// <since_tizen> 3 </since_tizen>
643         /// <privilege>http://tizen.org/privilege/mapservice</privilege>
644         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
645         /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
646         /// <exception cref="System.InvalidOperationException">Thrown when a native operation failed to allocate memory and connect to the service.</exception>
647         public void RemoveAll()
648         {
649             Log.Info(string.Format("Remove all of objects"));
650             foreach (var child in _handleToObjectTable.Values)
651             {
652                 child.InvalidateMapObject();
653             }
654             _handleToObjectTable.Clear();
655             handle.RemoveAllObjects();
656         }
657
658         /// <summary>
659         /// Captures a snapshot of the map view.
660         /// </summary>
661         /// <since_tizen> 3 </since_tizen>
662         /// <param name="type">Type of file format.</param>
663         /// <param name="quality">An integer value representing the quality for encoding from 1 to 100.</param>
664         /// <param name="path">A string representing the file path for a snapshot.</param>
665         /// <privilege>http://tizen.org/privilege/mapservice</privilege>
666         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
667         /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
668         /// <exception cref="System.ArgumentException">Thrown when the value is invalid.</exception>
669         /// <exception cref="System.InvalidOperationException">Thrown when a native operation failed to allocate memory and connect to the service.</exception>
670         public void CaptureSnapshot(SnapshotType type, int quality, string path)
671         {
672             var err = Interop.ViewSnapshot.ViewCaptureSnapshot(handle, (Interop.ViewSnapshotFormatType)type, quality, path);
673             err.ThrowIfFailed("Failed to create snapshot for the view");
674         }
675
676         private void SetGestureEventCallback()
677         {
678             if (_gestureEventCallback == null)
679             {
680                 _gestureEventCallback = (type, eventData, userData) =>
681                 {
682                     if (type != Interop.ViewEventType.Gesture) return;
683                     var eventArg = new MapGestureEventArgs(eventData);
684                     switch (eventArg.GestureType)
685                     {
686                         case GestureType.Scroll: _scrolledEventHandler?.Invoke(this, eventArg); break;
687                         case GestureType.Zoom: _twoFingerZoomedEventHandler?.Invoke(this, eventArg); break;
688                         case GestureType.Click: _clickedEventHandler?.Invoke(this, eventArg); break;
689                         case GestureType.DoubleClick: _doubleClickedEventHandler?.Invoke(this, eventArg); break;
690                         case GestureType.TwoFingerClick: _twoFingerClickedEventHandler?.Invoke(this, eventArg); break;
691                         case GestureType.Rotation: _twoFingerRotatedEventHandler?.Invoke(this, eventArg); break;
692                         case GestureType.LongPress: _longPressedEventHandler?.Invoke(this, eventArg); break;
693                     }
694                 };
695                 handle.SetEventCb(Interop.ViewEventType.Gesture, _gestureEventCallback, IntPtr.Zero);
696                 Log.Info(string.Format("Gesture event callback is set"));
697             }
698         }
699
700         private void UnsetGestureEventCallback()
701         {
702             if (_scrolledEventHandler != null || _twoFingerZoomedEventHandler != null
703                 || _clickedEventHandler != null || _doubleClickedEventHandler != null
704                 || _twoFingerClickedEventHandler != null || _twoFingerRotatedEventHandler != null
705                 || _longPressedEventHandler != null)
706             {
707                 return;
708             }
709
710             handle.UnsetEventCb(Interop.ViewEventType.Gesture);
711             _gestureEventCallback = null;
712             Log.Info(string.Format("Gesture event callback is unset"));
713         }
714
715         private void SetObjectEventCallback()
716         {
717             if (_objectEventCallback == null)
718             {
719                 _objectEventCallback = (type, eventData, userData) =>
720                 {
721                     if (type != Interop.ViewEventType.Object) return;
722                     var eventArg = new Interop.ObjectEventDataHandle(eventData);
723                     switch (eventArg.GestureType)
724                     {
725                         case Interop.ViewGesture.Click:
726                         {
727                             var mapObject = _handleToObjectTable[eventArg.ViewObject];
728                             mapObject?.HandleClickedEvent();
729                             break;
730                         }
731                     }
732                 };
733                 handle.SetEventCb(Interop.ViewEventType.Object, _objectEventCallback, IntPtr.Zero);
734                 Log.Info(string.Format("Object event callback is set"));
735             }
736         }
737
738         private void SetViewReadyEventCallback()
739         {
740             if (_viewReadyEventCallback == null)
741             {
742                 _viewReadyEventCallback = (type, eventData, userData) =>
743                 {
744                     _viewReadyEventHandler?.Invoke(this, EventArgs.Empty);
745                 };
746                 handle.SetEventCb(Interop.ViewEventType.Ready, _viewReadyEventCallback, IntPtr.Zero);
747                 Log.Info(string.Format("ViewReady event callback is set"));
748             }
749         }
750
751         private void UnsetViewReadyEventCallback()
752         {
753             if (_viewReadyEventHandler == null)
754             {
755                 handle.UnsetEventCb(Interop.ViewEventType.Ready);
756                 _viewReadyEventCallback = null;
757                 Log.Info(string.Format("ViewReady event callback is unset"));
758             }
759         }
760
761         #region IDisposable Support
762         private bool _disposedValue = false;
763
764         /// <summary>
765         /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
766         /// </summary>
767         /// <param name="disposing">If true, managed and unmanaged resources can be disposed, otherwise only unmanaged resources can be disposed.</param>
768         /// <since_tizen> 3 </since_tizen>
769         protected virtual void Dispose(bool disposing)
770         {
771             if (!_disposedValue)
772             {
773                 if (disposing)
774                 {
775                     _handleToObjectTable?.Clear();
776                 }
777                 handle?.Dispose();
778                 _disposedValue = true;
779             }
780         }
781
782         /// <summary>
783         /// Releases all the resources used by this object.
784         /// </summary>
785         /// <since_tizen> 3 </since_tizen>
786         public void Dispose()
787         {
788             Dispose(true);
789             GC.SuppressFinalize(this);
790         }
791         #endregion
792     }
793 }