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