summaryrefslogtreecommitdiff
path: root/Tizen.Maps/Tizen.Maps/MapView.cs
blob: a9cd3a4afc793375ca4ab82e2c6c6f360cfddcdf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
/*
 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

using System;
using ElmSharp;
using Layout = ElmSharp.Layout;
using EvasObject = ElmSharp.EvasObject;
using System.Collections.Generic;

namespace Tizen.Maps
{
    /// <summary>
    /// Map View class to show a map on the screen.
    /// </summary>
    public class MapView : Layout, IDisposable
    {
        internal Interop.ViewHandle handle;
        private MapService _service;

        private Dictionary<IntPtr, MapObject> _handleToObjectTable = new Dictionary<IntPtr, MapObject>();

        private Interop.ViewOnEventCallback _gestureEventCallback;
        private Interop.ViewOnEventCallback _objectEventCallback;
        private Interop.ViewOnEventCallback _viewReadyEventCallback;

        private event EventHandler<MapGestureEventArgs> _scrolledEventHandler;
        private event EventHandler<MapGestureEventArgs> _zoomedEventHandler;
        private event EventHandler<MapGestureEventArgs> _tappedEventHandler;
        private event EventHandler<MapGestureEventArgs> _doubleTappedEventHandler;
        private event EventHandler<MapGestureEventArgs> _twoFingerTappedEventHandler;
        private event EventHandler<MapGestureEventArgs> _rotatedEventHandler;
        private event EventHandler<MapGestureEventArgs> _longPressedEventHandler;
        private event EventHandler _viewReadyEventHandler;

        /// <summary>
        /// Creates the view and link it to the instance of map service.
        /// </summary>
        /// <param name="parent">An instance of <see cref="EvasObject"/> object which map view will be drawn</param>
        /// <param name="service">An instance of <see cref="MapService"/> object</param>
        /// <privilege>http://tizen.org/privilege/mapservice</privilege>
        /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
        /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
        /// <exception cref="System.ArgumentException">Thrown when parameters are invalid</exception>
        /// <exception cref="System.InvalidOperationException">Thrown when native operation failed to allocate memory, connect to service</exception>
        public MapView(EvasObject parent, MapService service) : base(parent)
        {
            handle = new Interop.ViewHandle(service.handle, this);
            Log.Info(string.Format("MapView is created"));

            _service = service;
            this.Resize(1, 1);

            // We need to keep Gesture Tap event enabled for object event to work
            handle.SetGestureEnabled(Interop.ViewGesture.Tap, true);
            SetObjectEventCallback();
        }

        /// <summary>
        /// Adds or removes event handlers to deliver scrolled gesture event.
        /// </summary>
        /// <value>Event handlers to get scrolled gesture event</value>
        /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
        public event EventHandler<MapGestureEventArgs> Scrolled
        {
            add
            {
                SetGestureEventCallback();
                handle.SetGestureEnabled(Interop.ViewGesture.Scroll, true);
                _scrolledEventHandler += value;
                Log.Info(string.Format("Scrolled event handler is added"));
            }
            remove
            {
                _scrolledEventHandler -= value;
                Log.Info(string.Format("Scrolled event handler is removed"));
                if (_scrolledEventHandler == null)
                {
                    handle.SetGestureEnabled(Interop.ViewGesture.Scroll, false);
                    UnsetGestureEventCallback();
                }
            }
        }

        /// <summary>
        /// Adds or removes event handlers to deliver zoomed gesture event.
        /// </summary>
        /// <value>Event handlers to get zoomed gesture event</value>
        /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
        public event EventHandler<MapGestureEventArgs> ZoomChanged
        {
            add
            {
                SetGestureEventCallback();
                handle.SetGestureEnabled(Interop.ViewGesture.Zoom, true);
                _zoomedEventHandler += value;
                Log.Info(string.Format("ZoomChanged event handler is added"));
            }
            remove
            {
                _zoomedEventHandler -= value;
                Log.Info(string.Format("ZoomChanged event handler is removed"));
                if (_zoomedEventHandler == null)
                {
                    handle.SetGestureEnabled(Interop.ViewGesture.Zoom, false);
                    UnsetGestureEventCallback();
                }
            }
        }

        /// <summary>
        /// Adds or removes event handlers to deliver clicked gesture event.
        /// </summary>
        /// <value>Event handlers to get clicked gesture event</value>
        /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
        public event EventHandler<MapGestureEventArgs> Clicked
        {
            add
            {
                SetGestureEventCallback();
                //handle.SetGestureEnabled(Interop.ViewGesture.Tap, true);
                _tappedEventHandler += value;
                Log.Info(string.Format("Clicked event handler is added"));
            }
            remove
            {
                _tappedEventHandler -= value;
                Log.Info(string.Format("Clicked event handler is removed"));
                if (_tappedEventHandler == null)
                {
                    //handle.SetGestureEnabled(Interop.ViewGesture.Tap, false);
                    UnsetGestureEventCallback();
                }
            }
        }

        /// <summary>
        /// Adds or removes event handlers to deliver double-clicked gesture event.
        /// </summary>
        /// <value>Event handlers to get double-clicked gesture event</value>
        /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
        public event EventHandler<MapGestureEventArgs> DoubleClicked
        {
            add
            {
                SetGestureEventCallback();
                handle.SetGestureEnabled(Interop.ViewGesture.DoubleTap, true);
                _doubleTappedEventHandler += value;
                Log.Info(string.Format("DoubleClicked event handler is removed"));
            }
            remove
            {
                _doubleTappedEventHandler -= value;
                Log.Info(string.Format("DoubleClicked event handler is removed"));
                if (_doubleTappedEventHandler == null)
                {
                    handle.SetGestureEnabled(Interop.ViewGesture.DoubleTap, false);
                    UnsetGestureEventCallback();
                }
            }
        }

        /// <summary>
        /// Adds or removes event handlers to deliver clicked gesture event with two-fingers.
        /// </summary>
        /// <value>Event handlers to get clicked gesture event</value>
        /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
        public event EventHandler<MapGestureEventArgs> TwoFingerPressed
        {
            add
            {
                SetGestureEventCallback();
                handle.SetGestureEnabled(Interop.ViewGesture.TwoFingerTap, true);
                _twoFingerTappedEventHandler += value;
                Log.Info(string.Format("TwoFingerPressed event handler is added"));
            }
            remove
            {
                _twoFingerTappedEventHandler -= value;
                Log.Info(string.Format("TwoFingerPressed event handler is removed"));
                if (_twoFingerTappedEventHandler == null)
                {
                    handle.SetGestureEnabled(Interop.ViewGesture.TwoFingerTap, false);
                    UnsetGestureEventCallback();
                }
            }
        }

        /// <summary>
        /// Adds or removes event handlers to deliver rotated gesture event.
        /// </summary>
        /// <value>Event handlers to get rotated gesture event</value>
        /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
        public event EventHandler<MapGestureEventArgs> Rotated
        {
            add
            {
                SetGestureEventCallback();
                handle.SetGestureEnabled(Interop.ViewGesture.Rotate, true);
                _rotatedEventHandler += value;
                Log.Info(string.Format("Rotated event handler is added"));
            }
            remove
            {
                _rotatedEventHandler -= value;
                Log.Info(string.Format("Rotated event handler is removed"));
                if (_rotatedEventHandler == null)
                {
                    handle.SetGestureEnabled(Interop.ViewGesture.Rotate, false);
                    UnsetGestureEventCallback();
                }
            }
        }


        /// <summary>
        /// Adds or removes event handlers to deliver long-pressed gesture event.
        /// </summary>
        /// <value>Event handlers to get long-pressed gesture event</value>
        /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
        public event EventHandler<MapGestureEventArgs> LongPressed
        {
            add
            {
                SetGestureEventCallback();
                handle.SetGestureEnabled(Interop.ViewGesture.LongPress, true);
                _longPressedEventHandler += value;
                Log.Info(string.Format("LongPressed event handler is added"));
            }
            remove
            {
                _longPressedEventHandler -= value;
                Log.Info(string.Format("LongPressed event handler is removed"));
                if (_longPressedEventHandler == null)
                {
                    handle.SetGestureEnabled(Interop.ViewGesture.LongPress, false);
                    UnsetGestureEventCallback();
                }
            }
        }

        /// <summary>
        /// Adds or removes event handlers to deliver a event representing the view is ready to be used.
        /// </summary>
        /// <value>Event handlers to get view ready event</value>
        /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
        public event EventHandler ViewReady
        {
            add
            {
                SetViewReadyEventCallback();
                _viewReadyEventHandler += value;
                Log.Info(string.Format("ViewReady event handler is added"));
            }
            remove
            {
                _viewReadyEventHandler -= value;
                Log.Info(string.Format("ViewReady event handler is removed"));
                UnsetGestureEventCallback();
            }
        }

        /// <summary>
        /// Gets or sets current zoom level.
        /// </summary>
        /// <value>It is an integer value that representing current zoom level.</value>
        /// <privilege>http://tizen.org/privilege/mapservice</privilege>
        /// <privilege>http://tizen.org/privilege/internet</privilege>
        /// <privilege>http://tizen.org/privilege/network.get</privilege>
        /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
        /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
        public int ZoomLevel
        {
            get
            {
                return handle.ZoomLevel;
            }
            set
            {
                Log.Info(string.Format("ZoomLevel is changed from {0} to {1}", handle.ZoomLevel, value));
                handle.ZoomLevel = value;
            }
        }

        /// <summary>
        /// Gets or sets minimum zoom level.
        /// </summary>
        /// <value>It is an integer value that limits minimal zoom level within range of current map plug-in supported.</value>
        /// <privilege>http://tizen.org/privilege/mapservice</privilege>
        /// <privilege>http://tizen.org/privilege/internet</privilege>
        /// <privilege>http://tizen.org/privilege/network.get</privilege>
        /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
        /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
        public int MinimumZoomLevel
        {
            get
            {
                return handle.MinimumZoomLevel;
            }
            set
            {
                Log.Info(string.Format("MinimumZoomLevel is changed from {0} to {1}", handle.MinimumZoomLevel, value));
                handle.MinimumZoomLevel = value;
            }
        }

        /// <summary>
        /// Gets or sets maximum zoom level.
        /// </summary>
        /// <value>It is an integer value that limits maximum zoom level within range of current map plug-in supported.</value>
        /// <privilege>http://tizen.org/privilege/mapservice</privilege>
        /// <privilege>http://tizen.org/privilege/internet</privilege>
        /// <privilege>http://tizen.org/privilege/network.get</privilege>
        /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
        /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
        public int MaximumZoomLevel
        {
            get
            {
                return handle.MaximumZoomLevel;
            }
            set
            {
                Log.Info(string.Format("MaximumZoomLevel is changed from {0} to {1}", handle.MaximumZoomLevel, value));
                handle.MaximumZoomLevel = value;
            }
        }

        /// <summary>
        /// Gets or sets orientation on the map view.
        /// </summary>
        /// <value>It is an integer value from 0 to 360 that indicates orientation of the map view</value>
        /// <privilege>http://tizen.org/privilege/mapservice</privilege>
        /// <privilege>http://tizen.org/privilege/internet</privilege>
        /// <privilege>http://tizen.org/privilege/network.get</privilege>
        /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
        /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
        public double Orientation
        {
            get
            {
                return handle.Orientation;
            }
            set
            {
                Log.Info(string.Format("Orientation is changed from {0} to {1}", handle.Orientation, value));
                handle.Orientation = value;
            }
        }

        /// <summary>
        /// Gets or sets theme type of the map view.
        /// </summary>
        /// <privilege>http://tizen.org/privilege/mapservice</privilege>
        /// <privilege>http://tizen.org/privilege/internet</privilege>
        /// <privilege>http://tizen.org/privilege/network.get</privilege>
        /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
        /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
        public MapTypes MapType
        {
            get
            {
                return (MapTypes)handle.MapType;
            }
            set
            {
                Log.Info(string.Format("MapType is changed from {0} to {1}", handle.MapType, value));
                handle.MapType = (Interop.ViewType)value;
            }
        }

        /// <summary>
        /// Indicates whether the map should show the 3D buildings layer.
        /// </summary>
        /// <privilege>http://tizen.org/privilege/mapservice</privilege>
        /// <privilege>http://tizen.org/privilege/internet</privilege>
        /// <privilege>http://tizen.org/privilege/network.get</privilege>
        /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
        /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
        public bool BuildingsEnabled
        {
            get
            {
                return handle.BuildingsEnabled;
            }
            set
            {
                Log.Info(string.Format("Showing the 3D buildings is {0}", (value ? "enabled" : "disabled")));
                handle.BuildingsEnabled = value;
            }
        }

        /// <summary>
        /// Indicates whether the map should show the traffic layer.
        /// </summary>
        /// <privilege>http://tizen.org/privilege/mapservice</privilege>
        /// <privilege>http://tizen.org/privilege/internet</privilege>
        /// <privilege>http://tizen.org/privilege/network.get</privilege>
        /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
        /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
        public bool TrafficEnabled
        {
            get
            {
                return handle.TrafficEnabled;
            }
            set
            {
                Log.Info(string.Format("Showing the traffic is {0}", (value ? "enabled" : "disabled")));
                handle.TrafficEnabled = value;
            }
        }

        /// <summary>
        /// Indicates whether the map should show the public transit layer.
        /// </summary>
        /// <privilege>http://tizen.org/privilege/mapservice</privilege>
        /// <privilege>http://tizen.org/privilege/internet</privilege>
        /// <privilege>http://tizen.org/privilege/network.get</privilege>
        /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
        /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
        public bool PublicTransitEnabled
        {
            get
            {
                return handle.PublicTransitEnabled;
            }
            set
            {
                Log.Info(string.Format("Showing the public transit is {0}", (value ? "enabled" : "disabled")));
                handle.PublicTransitEnabled = value;
            }
        }

        /// <summary>
        /// Indicates whether the scale-bar is enabled or not.
        /// </summary>
        /// <privilege>http://tizen.org/privilege/mapservice</privilege>
        /// <privilege>http://tizen.org/privilege/internet</privilege>
        /// <privilege>http://tizen.org/privilege/network.get</privilege>
        /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
        /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
        public bool ScalebarEnabled
        {
            get
            {
                return handle.ScalebarEnabled;
            }
            set
            {
                Log.Info(string.Format("Showing the scale-bar is {0}", (value ? "enabled" : "disabled")));
                handle.ScalebarEnabled = value;
            }
        }

        /// <summary>
        /// Sets language of map view.
        /// </summary>
        /// <value>The display language in the map.
        /// A language is specified as an ISO 3166 alpha-2 two letter country-code
        /// followed by ISO 639-1 for the two-letter language code.
        /// Each language tag is composed of one or more "subtags" separated by hyphens (-).
        /// Each subtag is composed of basic Latin letters or digits only.
        /// For example, "ko-KR" for Korean, "en-US" for American English.</value>
        /// <privilege>http://tizen.org/privilege/mapservice</privilege>
        /// <privilege>http://tizen.org/privilege/internet</privilege>
        /// <privilege>http://tizen.org/privilege/network.get</privilege>
        /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
        /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
        /// <exception cref="System.ArgumentException">Thrown when the value is invalid.</exception>
        public string Language
        {
            get
            {
                return handle.Language;
            }
            set
            {
                Log.Info(string.Format("Language is changed from {0} to {1}", handle.Language, value));
                handle.Language = value;
            }
        }

        /// <summary>
        /// Gets or sets geographical coordinates for map view's center.
        /// </summary>
        /// <privilege>http://tizen.org/privilege/mapservice</privilege>
        /// <privilege>http://tizen.org/privilege/internet</privilege>
        /// <privilege>http://tizen.org/privilege/network.get</privilege>
        /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
        /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
        /// <exception cref="System.ArgumentException">Thrown when the value is invalid.</exception>
        public Geocoordinates Center
        {
            get
            {
                return new Geocoordinates(handle.Center);
            }
            set
            {
                Log.Info(string.Format("Center is changed from {0} to {1}", handle.Center, value.handle));
                handle.Center = value.handle;
            }
        }

        /// <summary>
        /// Gets a list of map object added to map view.
        /// </summary>
        public IEnumerable<MapObject> Children
        {
            get
            {
                return _handleToObjectTable.Values;
            }
        }

        /// <summary>
        /// Changes geographical coordinates to screen coordinates.
        /// </summary>
        /// <param name="coordinates">Geographical coordinates</param>
        /// <returns>Returns an instance of screen coordinates on the current screen</returns>
        /// <privilege>http://tizen.org/privilege/mapservice</privilege>
        /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
        /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
        /// <exception cref="System.ArgumentException">Thrown when the value is invalid.</exception>
        /// <exception cref="System.InvalidOperationException">Thrown when native operation failed to allocate memory, connect to service.</exception>
        public Point GeolocationToScreen(Geocoordinates coordinates)
        {
            return handle.GeolocationToScreen(coordinates.handle);
        }

        /// <summary>
        /// Changes screen coordinates to geographical coordinates.
        /// </summary>
        /// <param name="screenCoordinates">Screen coordinates</param>
        /// <returns>Returns an instance of geographical coordinates object.</returns>
        /// <privilege>http://tizen.org/privilege/mapservice</privilege>
        /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
        /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
        /// <exception cref="System.ArgumentException">Thrown when the value is invalid.</exception>
        /// <exception cref="System.InvalidOperationException">Thrown when native operation failed to allocate memory, connect to service.</exception>
        public Geocoordinates ScreenToGeolocation(Point screenCoordinates)
        {
            return new Geocoordinates(handle.ScreenToGeolocation(screenCoordinates));
        }

        /// <summary>
        /// Adds a map object to map view.
        /// </summary>
        /// <param name="child">An instance of map object to be added</param>
        /// <privilege>http://tizen.org/privilege/mapservice</privilege>
        /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
        /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
        /// <exception cref="System.ArgumentException">Thrown when the value is invalid.</exception>
        /// <exception cref="System.InvalidOperationException">Thrown when native operation failed to allocate memory, connect to service.</exception>
        public void Add(MapObject child)
        {
            Log.Info(string.Format("Add a object"));
            var objectHandle = child.GetHandle();
            if (!_handleToObjectTable.ContainsKey(objectHandle))
            {
                _handleToObjectTable[objectHandle] = child;
                handle.AddObject(objectHandle);

                // MapView take ownership of added map objects
                objectHandle.HasOwnership = false;
            }
        }

        /// <summary>
        /// Removes a map object from map view.
        /// </summary>
        /// <param name="child">An instance of map object to be removed</param>
        /// <remarks>Once removed, the child object will be become invalid</remarks>
        /// <privilege>http://tizen.org/privilege/mapservice</privilege>
        /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
        /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
        /// <exception cref="System.ArgumentException">Thrown when the value is invalid.</exception>
        /// <exception cref="System.InvalidOperationException">Thrown when native operation failed to allocate memory, connect to service.</exception>
        public void Remove(MapObject child)
        {
            Log.Info(string.Format("Remove a object"));
            var objectHandle = child.GetHandle();
            if (_handleToObjectTable.Remove(objectHandle))
            {
                handle.RemoveObject(child.GetHandle());

                // The object handle will be released automatically by the View, once RemoveObject call is successful
                child.InvalidateMapObject();
            }
        }

        /// <summary>
        /// Removes all map objects from map view.
        /// </summary>
        /// <privilege>http://tizen.org/privilege/mapservice</privilege>
        /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
        /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
        /// <exception cref="System.InvalidOperationException">Thrown when native operation failed to allocate memory, connect to service.</exception>
        public void RemoveAll()
        {
            Log.Info(string.Format("Remove all of objects"));
            foreach (var child in _handleToObjectTable.Values)
            {
                child.InvalidateMapObject();
            }
            _handleToObjectTable.Clear();
            handle.RemoveAllObjects();
        }

        /// <summary>
        /// Captures a snapshot of map view
        /// </summary>
        /// <param name="type">Type of file format</param>
        /// <param name="quality">A integer value which representing quality for encoding, from 1 to 100</param>
        /// <param name="path">A string which representing The file path for snapshot</param>
        /// <privilege>http://tizen.org/privilege/mapservice</privilege>
        /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
        /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
        /// <exception cref="System.ArgumentException">Thrown when the value is invalid.</exception>
        /// <exception cref="System.InvalidOperationException">Thrown when native operation failed to allocate memory, connect to service.</exception>
        public void CaptureSnapshot(SnapshotType type, int quality, string path)
        {
            var err = Interop.ViewSnapshot.ViewCaptureSnapshot(handle, (Interop.ViewSnapshotFormatType)type, quality, path);
            err.ThrowIfFailed("Failed to create snapshot for the view");
        }

        private void SetGestureEventCallback()
        {
            if (_gestureEventCallback == null)
            {
                _gestureEventCallback = (type, eventData, userData) =>
                {
                    if (type != Interop.ViewEventType.Gesture) return;
                    var eventArg = new MapGestureEventArgs(eventData);
                    switch (eventArg.GestureType)
                    {
                        case GestureType.Scroll: _scrolledEventHandler?.Invoke(this, eventArg); break;
                        case GestureType.Zoom: _zoomedEventHandler?.Invoke(this, eventArg); break;
                        case GestureType.Tap: _tappedEventHandler?.Invoke(this, eventArg); break;
                        case GestureType.DoubleTap: _doubleTappedEventHandler?.Invoke(this, eventArg); break;
                        case GestureType.TwoFingerTap: _twoFingerTappedEventHandler?.Invoke(this, eventArg); break;
                        case GestureType.Rotate: _rotatedEventHandler?.Invoke(this, eventArg); break;
                        case GestureType.LongPress: _longPressedEventHandler?.Invoke(this, eventArg); break;
                    }
                };
                handle.SetEventCb(Interop.ViewEventType.Gesture, _gestureEventCallback, IntPtr.Zero);
                Log.Info(string.Format("Gesture event callback is set"));
            }
        }

        private void UnsetGestureEventCallback()
        {
            if (_scrolledEventHandler != null || _zoomedEventHandler != null
                || _tappedEventHandler != null || _doubleTappedEventHandler != null
                || _twoFingerTappedEventHandler != null || _rotatedEventHandler != null
                || _longPressedEventHandler != null)
            {
                return;
            }

            handle.UnsetEventCb(Interop.ViewEventType.Gesture);
            _gestureEventCallback = null;
            Log.Info(string.Format("Gesture event callback is unset"));
        }

        private void SetObjectEventCallback()
        {
            if (_objectEventCallback == null)
            {
                _objectEventCallback = (type, eventData, userData) =>
                {
                    if (type != Interop.ViewEventType.Object) return;
                    var eventArg = new Interop.ObjectEventDataHandle(eventData);
                    switch (eventArg.GestureType)
                    {
                        case Interop.ViewGesture.Tap:
                            {
                                var mapObject = _handleToObjectTable[eventArg.ViewObject];
                                mapObject?.HandleClickedEvent();
                                break;
                            }
                    }
                };
                handle.SetEventCb(Interop.ViewEventType.Object, _objectEventCallback, IntPtr.Zero);
                Log.Info(string.Format("Object event callback is set"));
            }
        }

        private void SetViewReadyEventCallback()
        {
            if (_viewReadyEventCallback == null)
            {
                _viewReadyEventCallback = (type, eventData, userData) =>
                {
                    _viewReadyEventHandler?.Invoke(this, EventArgs.Empty);
                };
                handle.SetEventCb(Interop.ViewEventType.Ready, _viewReadyEventCallback, IntPtr.Zero);
                Log.Info(string.Format("ViewReady event callback is set"));
            }
        }

        private void UnsetViewReadyEventCallback()
        {
            if (_viewReadyEventHandler == null)
            {
                handle.UnsetEventCb(Interop.ViewEventType.Ready);
                _viewReadyEventCallback = null;
                Log.Info(string.Format("ViewReady event callback is unset"));
            }
        }

        #region IDisposable Support
        private bool _disposedValue = false;

        protected virtual void Dispose(bool disposing)
        {
            if (!_disposedValue)
            {
                if (disposing)
                {
                    _service.Dispose();
                }
                handle.Dispose();
                _disposedValue = true;
            }
        }

        /// <summary>
        /// Releases all resources used by this object.
        /// </summary>
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
        #endregion
    }
}