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