2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 using Layout = ElmSharp.Layout;
20 using EvasObject = ElmSharp.EvasObject;
21 using System.Collections.Generic;
26 /// Map View class to show a map on the screen.
28 /// <since_tizen> 3 </since_tizen>
29 public class MapView : Layout, IDisposable
31 internal Interop.ViewHandle handle;
32 private MapService _service;
34 private Dictionary<IntPtr, MapObject> _handleToObjectTable = new Dictionary<IntPtr, MapObject>();
36 private Interop.ViewOnEventCallback _gestureEventCallback;
37 private Interop.ViewOnEventCallback _objectEventCallback;
38 private Interop.ViewOnEventCallback _viewReadyEventCallback;
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;
50 /// Creates a view and links it to the instance of a map service.
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)
62 handle = new Interop.ViewHandle(service.handle, this);
63 Log.Info(string.Format("MapView is created"));
68 // We need to keep Gesture Tap event enabled for object event to work
69 handle.SetGestureEnabled(Interop.ViewGesture.Click, true);
70 SetObjectEventCallback();
74 /// Destroy the MapView object.
82 /// Adds or removes event handlers to deliver a scrolled gesture event.
84 /// <value>Event handlers to get a scrolled gesture event.</value>
85 /// <since_tizen> 3 </since_tizen>
86 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
87 public event EventHandler<MapGestureEventArgs> Scrolled
91 SetGestureEventCallback();
92 handle.SetGestureEnabled(Interop.ViewGesture.Scroll, true);
93 _scrolledEventHandler += value;
94 Log.Info(string.Format("Scrolled event handler is added"));
98 _scrolledEventHandler -= value;
99 Log.Info(string.Format("Scrolled event handler is removed"));
100 if (_scrolledEventHandler == null)
102 handle.SetGestureEnabled(Interop.ViewGesture.Scroll, false);
103 UnsetGestureEventCallback();
109 /// Adds or removes event handlers to deliver a zoomed gesture event.
111 /// <value>Event handlers to get a zoomed gesture event.</value>
112 /// <since_tizen> 3 </since_tizen>
113 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
114 public event EventHandler<MapGestureEventArgs> TwoFingerZoomed
118 SetGestureEventCallback();
119 handle.SetGestureEnabled(Interop.ViewGesture.Zoom, true);
120 _twoFingerZoomedEventHandler += value;
121 Log.Info(string.Format("TwoFingerZoomed event handler is added"));
125 _twoFingerZoomedEventHandler -= value;
126 Log.Info(string.Format("TwoFingerZoomed event handler is removed"));
127 if (_twoFingerZoomedEventHandler == null)
129 handle.SetGestureEnabled(Interop.ViewGesture.Zoom, false);
130 UnsetGestureEventCallback();
136 /// Adds or removes event handlers to deliver a clicked gesture event.
138 /// <value>Event handlers to get a clicked gesture event.</value>
139 /// <since_tizen> 3 </since_tizen>
140 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
141 public event EventHandler<MapGestureEventArgs> Clicked
145 SetGestureEventCallback();
146 //handle.SetGestureEnabled(Interop.ViewGesture.Click, true);
147 _clickedEventHandler += value;
148 Log.Info(string.Format("Clicked event handler is added"));
152 _clickedEventHandler -= value;
153 Log.Info(string.Format("Clicked event handler is removed"));
154 if (_clickedEventHandler == null)
156 //handle.SetGestureEnabled(Interop.ViewGesture.Click, false);
157 UnsetGestureEventCallback();
163 /// Adds or removes event handlers to deliver a double-clicked gesture event.
165 /// <value>Event handlers to get a double-clicked gesture event.</value>
166 /// <since_tizen> 3 </since_tizen>
167 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
168 public event EventHandler<MapGestureEventArgs> DoubleClicked
172 SetGestureEventCallback();
173 handle.SetGestureEnabled(Interop.ViewGesture.DoubleClick, true);
174 _doubleClickedEventHandler += value;
175 Log.Info(string.Format("DoubleClicked event handler is removed"));
179 _doubleClickedEventHandler -= value;
180 Log.Info(string.Format("DoubleClicked event handler is removed"));
181 if (_doubleClickedEventHandler == null)
183 handle.SetGestureEnabled(Interop.ViewGesture.DoubleClick, false);
184 UnsetGestureEventCallback();
190 /// Adds or removes event handlers to deliver a clicked gesture event with two-fingers.
192 /// <value>Event handlers to get a clicked gesture event.</value>
193 /// <since_tizen> 3 </since_tizen>
194 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
195 public event EventHandler<MapGestureEventArgs> TwoFingerClicked
199 SetGestureEventCallback();
200 handle.SetGestureEnabled(Interop.ViewGesture.TwoFingerClick, true);
201 _twoFingerClickedEventHandler += value;
202 Log.Info(string.Format("TwoFingerClicked event handler is added"));
206 _twoFingerClickedEventHandler -= value;
207 Log.Info(string.Format("TwoFingerClicked event handler is removed"));
208 if (_twoFingerClickedEventHandler == null)
210 handle.SetGestureEnabled(Interop.ViewGesture.TwoFingerClick, false);
211 UnsetGestureEventCallback();
217 /// Adds or removes event handlers to deliver a rotated gesture event.
219 /// <value>Event handlers to get a rotated gesture event.</value>
220 /// <since_tizen> 3 </since_tizen>
221 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
222 public event EventHandler<MapGestureEventArgs> TwoFingerRotated
226 SetGestureEventCallback();
227 handle.SetGestureEnabled(Interop.ViewGesture.Rotation, true);
228 _twoFingerRotatedEventHandler += value;
229 Log.Info(string.Format("Rotated event handler is added"));
233 _twoFingerRotatedEventHandler -= value;
234 Log.Info(string.Format("Rotated event handler is removed"));
235 if (_twoFingerRotatedEventHandler == null)
237 handle.SetGestureEnabled(Interop.ViewGesture.Rotation, false);
238 UnsetGestureEventCallback();
245 /// Adds or removes event handlers to deliver a long-pressed gesture event.
247 /// <value>Event handlers to get a long-pressed gesture event.</value>
248 /// <since_tizen> 3 </since_tizen>
249 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
250 public event EventHandler<MapGestureEventArgs> LongPressed
254 SetGestureEventCallback();
255 handle.SetGestureEnabled(Interop.ViewGesture.LongPress, true);
256 _longPressedEventHandler += value;
257 Log.Info(string.Format("LongPressed event handler is added"));
261 _longPressedEventHandler -= value;
262 Log.Info(string.Format("LongPressed event handler is removed"));
263 if (_longPressedEventHandler == null)
265 handle.SetGestureEnabled(Interop.ViewGesture.LongPress, false);
266 UnsetGestureEventCallback();
272 /// Adds or removes event handlers to deliver an event representing a view ready to be used.
274 /// <value>Event handlers to get a view ready event.</value>
275 /// <since_tizen> 3 </since_tizen>
276 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
277 public event EventHandler ViewReady
281 SetViewReadyEventCallback();
282 _viewReadyEventHandler += value;
283 Log.Info(string.Format("ViewReady event handler is added"));
287 _viewReadyEventHandler -= value;
288 Log.Info(string.Format("ViewReady event handler is removed"));
289 UnsetGestureEventCallback();
294 /// Gets or sets the current zoom level.
296 /// <value>It is an integer value representing the current zoom level.</value>
297 /// <since_tizen> 3 </since_tizen>
298 /// <privilege>http://tizen.org/privilege/mapservice</privilege>
299 /// <privilege>http://tizen.org/privilege/internet</privilege>
300 /// <privilege>http://tizen.org/privilege/network.get</privilege>
301 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
302 /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
307 return handle.ZoomLevel;
311 Log.Info(string.Format("ZoomLevel is changed from {0} to {1}", handle.ZoomLevel, value));
312 handle.ZoomLevel = value;
317 /// Gets or sets the minimum zoom level.
319 /// <value>It is an integer value that limits minimal zoom level within a range of the current map plug-in support.</value>
320 /// <since_tizen> 3 </since_tizen>
321 /// <privilege>http://tizen.org/privilege/mapservice</privilege>
322 /// <privilege>http://tizen.org/privilege/internet</privilege>
323 /// <privilege>http://tizen.org/privilege/network.get</privilege>
324 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
325 /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
326 public int MinimumZoomLevel
330 return handle.MinimumZoomLevel;
334 Log.Info(string.Format("MinimumZoomLevel is changed from {0} to {1}", handle.MinimumZoomLevel, value));
335 handle.MinimumZoomLevel = value;
340 /// Gets or sets the maximum zoom level.
342 /// <value>It is an integer value that limits maximum zoom level within a range of the current map plug-in support.</value>
343 /// <since_tizen> 3 </since_tizen>
344 /// <privilege>http://tizen.org/privilege/mapservice</privilege>
345 /// <privilege>http://tizen.org/privilege/internet</privilege>
346 /// <privilege>http://tizen.org/privilege/network.get</privilege>
347 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
348 /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
349 public int MaximumZoomLevel
353 return handle.MaximumZoomLevel;
357 Log.Info(string.Format("MaximumZoomLevel is changed from {0} to {1}", handle.MaximumZoomLevel, value));
358 handle.MaximumZoomLevel = value;
363 /// Gets or sets the orientation on the map view.
365 /// <value>It is an integer value from 0 to 360 that indicates the orientation of the map view.</value>
366 /// <since_tizen> 3 </since_tizen>
367 /// <privilege>http://tizen.org/privilege/mapservice</privilege>
368 /// <privilege>http://tizen.org/privilege/internet</privilege>
369 /// <privilege>http://tizen.org/privilege/network.get</privilege>
370 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
371 /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
372 public double Orientation
376 return handle.Orientation;
380 Log.Info(string.Format("Orientation is changed from {0} to {1}", handle.Orientation, value));
381 handle.Orientation = value;
386 /// Gets or sets theme type of the map view.
388 /// <since_tizen> 3 </since_tizen>
389 /// <privilege>http://tizen.org/privilege/mapservice</privilege>
390 /// <privilege>http://tizen.org/privilege/internet</privilege>
391 /// <privilege>http://tizen.org/privilege/network.get</privilege>
392 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
393 /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
394 public MapTypes MapType
398 return (MapTypes)handle.MapType;
402 Log.Info(string.Format("MapType is changed from {0} to {1}", handle.MapType, value));
403 handle.MapType = (Interop.ViewType)value;
408 /// Indicates whether the map should show the 3D buildings layer.
410 /// <since_tizen> 3 </since_tizen>
411 /// <privilege>http://tizen.org/privilege/mapservice</privilege>
412 /// <privilege>http://tizen.org/privilege/internet</privilege>
413 /// <privilege>http://tizen.org/privilege/network.get</privilege>
414 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
415 /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
416 public bool BuildingsEnabled
420 return handle.BuildingsEnabled;
424 Log.Info(string.Format("Showing the 3D buildings is {0}", (value ? "enabled" : "disabled")));
425 handle.BuildingsEnabled = value;
430 /// Indicates whether the map should show the traffic layer.
432 /// <since_tizen> 3 </since_tizen>
433 /// <privilege>http://tizen.org/privilege/mapservice</privilege>
434 /// <privilege>http://tizen.org/privilege/internet</privilege>
435 /// <privilege>http://tizen.org/privilege/network.get</privilege>
436 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
437 /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
438 public bool TrafficEnabled
442 return handle.TrafficEnabled;
446 Log.Info(string.Format("Showing the traffic is {0}", (value ? "enabled" : "disabled")));
447 handle.TrafficEnabled = value;
452 /// Indicates whether the map should show the public transit layer.
454 /// <since_tizen> 3 </since_tizen>
455 /// <privilege>http://tizen.org/privilege/mapservice</privilege>
456 /// <privilege>http://tizen.org/privilege/internet</privilege>
457 /// <privilege>http://tizen.org/privilege/network.get</privilege>
458 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
459 /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
460 public bool PublicTransitEnabled
464 return handle.PublicTransitEnabled;
468 Log.Info(string.Format("Showing the public transit is {0}", (value ? "enabled" : "disabled")));
469 handle.PublicTransitEnabled = value;
474 /// Indicates whether the scale-bar is enabled or not.
476 /// <since_tizen> 4 </since_tizen>
477 /// <privilege>http://tizen.org/privilege/mapservice</privilege>
478 /// <privilege>http://tizen.org/privilege/internet</privilege>
479 /// <privilege>http://tizen.org/privilege/network.get</privilege>
480 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
481 /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
482 public bool ScaleBarEnabled
486 return handle.ScaleBarEnabled;
490 Log.Info(string.Format("Showing the scale-bar is {0}", (value ? "enabled" : "disabled")));
491 handle.ScaleBarEnabled = value;
496 /// Sets language of map view.
498 /// <value>The display language in the map.
499 /// A language is specified as an ISO 3166 alpha-2 two letter country-code
500 /// followed by ISO 639-1 for the two-letter language code.
501 /// Each language tag is composed of one or more "subtags" separated by hyphens (-).
502 /// Each subtag is composed of basic Latin letters or digits only.
503 /// For example, "ko-KR" for Korean, "en-US" for American English.</value>
504 /// <since_tizen> 3 </since_tizen>
505 /// <privilege>http://tizen.org/privilege/mapservice</privilege>
506 /// <privilege>http://tizen.org/privilege/internet</privilege>
507 /// <privilege>http://tizen.org/privilege/network.get</privilege>
508 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
509 /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
510 /// <exception cref="System.ArgumentException">Thrown when the value is invalid.</exception>
511 public string Language
515 return handle.Language;
519 Log.Info(string.Format("Language is changed from {0} to {1}", handle.Language, value));
520 handle.Language = value;
525 /// Gets or sets geographical coordinates for map view's center.
527 /// <since_tizen> 3 </since_tizen>
528 /// <privilege>http://tizen.org/privilege/mapservice</privilege>
529 /// <privilege>http://tizen.org/privilege/internet</privilege>
530 /// <privilege>http://tizen.org/privilege/network.get</privilege>
531 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
532 /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
533 /// <exception cref="System.ArgumentException">Thrown when the value is invalid.</exception>
534 public Geocoordinates Center
538 return new Geocoordinates(handle.Center);
542 Log.Info(string.Format("Center is changed from {0} to {1}", handle.Center.ToString(), value.ToString()));
543 handle.Center = value.handle;
548 /// Gets a list of the map object added to map view.
550 /// <since_tizen> 3 </since_tizen>
551 public new IEnumerable<MapObject> Children
555 return _handleToObjectTable.Values;
560 /// Changes the geographical coordinates to screen coordinates.
562 /// <since_tizen> 3 </since_tizen>
563 /// <param name="coordinates">Geographical coordinates.</param>
564 /// <returns>Returns an instance of the screen coordinates on the current screen.</returns>
565 /// <privilege>http://tizen.org/privilege/mapservice</privilege>
566 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
567 /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
568 /// <exception cref="System.ArgumentException">Thrown when the value is invalid.</exception>
569 /// <exception cref="System.InvalidOperationException">Thrown when a native operation failed to allocate memory and connect to the service.</exception>
570 public Point GeolocationToScreen(Geocoordinates coordinates)
572 return handle.GeolocationToScreen(coordinates.handle);
576 /// Changes the screen coordinates to geographical coordinates.
578 /// <since_tizen> 3 </since_tizen>
579 /// <param name="screenCoordinates">Screen coordinates.</param>
580 /// <returns>Returns an instance of the geographical coordinates object.</returns>
581 /// <privilege>http://tizen.org/privilege/mapservice</privilege>
582 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
583 /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
584 /// <exception cref="System.ArgumentException">Thrown when the value is invalid.</exception>
585 /// <exception cref="System.InvalidOperationException">Thrown when a native operation failed to allocate memory and connect to the service.</exception>
586 public Geocoordinates ScreenToGeolocation(Point screenCoordinates)
588 return new Geocoordinates(handle.ScreenToGeolocation(screenCoordinates));
592 /// Adds a map object to map view.
594 /// <since_tizen> 3 </since_tizen>
595 /// <param name="child">An instance of the map object to be added.</param>
596 /// <privilege>http://tizen.org/privilege/mapservice</privilege>
597 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
598 /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
599 /// <exception cref="System.ArgumentException">Thrown when the value is invalid.</exception>
600 /// <exception cref="System.InvalidOperationException">Thrown when a native operation failed to allocate memory and connect to the service.</exception>
601 public void Add(MapObject child)
603 Log.Info(string.Format("Add a object"));
604 var objectHandle = child.GetHandle();
605 if (!_handleToObjectTable.ContainsKey(objectHandle))
607 _handleToObjectTable[objectHandle] = child;
608 handle.AddObject(objectHandle);
610 // MapView take ownership of added map objects
611 objectHandle.HasOwnership = false;
616 /// Removes a map object from the map view.
618 /// <since_tizen> 3 </since_tizen>
619 /// <param name="child">An instance of the map object to be removed.</param>
620 /// <remarks>Once removed, the child object will be become invalid.</remarks>
621 /// <privilege>http://tizen.org/privilege/mapservice</privilege>
622 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
623 /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
624 /// <exception cref="System.ArgumentException">Thrown when the value is invalid.</exception>
625 /// <exception cref="System.InvalidOperationException">Thrown when native operation failed to allocate memory and connect to the service.</exception>
626 public void Remove(MapObject child)
628 Log.Info(string.Format("Remove a object"));
629 var objectHandle = child.GetHandle();
630 if (_handleToObjectTable.Remove(objectHandle))
632 handle.RemoveObject(child.GetHandle());
634 // The object handle will be released automatically by the View, once RemoveObject call is successful
635 child.InvalidateMapObject();
640 /// Removes all map objects from the map view.
642 /// <since_tizen> 3 </since_tizen>
643 /// <privilege>http://tizen.org/privilege/mapservice</privilege>
644 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
645 /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
646 /// <exception cref="System.InvalidOperationException">Thrown when a native operation failed to allocate memory and connect to the service.</exception>
647 public void RemoveAll()
649 Log.Info(string.Format("Remove all of objects"));
650 foreach (var child in _handleToObjectTable.Values)
652 child.InvalidateMapObject();
654 _handleToObjectTable.Clear();
655 handle.RemoveAllObjects();
659 /// Captures a snapshot of the map view.
661 /// <since_tizen> 3 </since_tizen>
662 /// <param name="type">Type of file format.</param>
663 /// <param name="quality">An integer value representing the quality for encoding from 1 to 100.</param>
664 /// <param name="path">A string representing the file path for a snapshot.</param>
665 /// <privilege>http://tizen.org/privilege/mapservice</privilege>
666 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
667 /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
668 /// <exception cref="System.ArgumentException">Thrown when the value is invalid.</exception>
669 /// <exception cref="System.InvalidOperationException">Thrown when a native operation failed to allocate memory and connect to the service.</exception>
670 public void CaptureSnapshot(SnapshotType type, int quality, string path)
672 var err = Interop.ViewSnapshot.ViewCaptureSnapshot(handle, (Interop.ViewSnapshotFormatType)type, quality, path);
673 err.ThrowIfFailed("Failed to create snapshot for the view");
676 private void SetGestureEventCallback()
678 if (_gestureEventCallback == null)
680 _gestureEventCallback = (type, eventData, userData) =>
682 if (type != Interop.ViewEventType.Gesture) return;
683 var eventArg = new MapGestureEventArgs(eventData);
684 switch (eventArg.GestureType)
686 case GestureType.Scroll: _scrolledEventHandler?.Invoke(this, eventArg); break;
687 case GestureType.Zoom: _twoFingerZoomedEventHandler?.Invoke(this, eventArg); break;
688 case GestureType.Click: _clickedEventHandler?.Invoke(this, eventArg); break;
689 case GestureType.DoubleClick: _doubleClickedEventHandler?.Invoke(this, eventArg); break;
690 case GestureType.TwoFingerClick: _twoFingerClickedEventHandler?.Invoke(this, eventArg); break;
691 case GestureType.Rotation: _twoFingerRotatedEventHandler?.Invoke(this, eventArg); break;
692 case GestureType.LongPress: _longPressedEventHandler?.Invoke(this, eventArg); break;
695 handle.SetEventCb(Interop.ViewEventType.Gesture, _gestureEventCallback, IntPtr.Zero);
696 Log.Info(string.Format("Gesture event callback is set"));
700 private void UnsetGestureEventCallback()
702 if (_scrolledEventHandler != null || _twoFingerZoomedEventHandler != null
703 || _clickedEventHandler != null || _doubleClickedEventHandler != null
704 || _twoFingerClickedEventHandler != null || _twoFingerRotatedEventHandler != null
705 || _longPressedEventHandler != null)
710 handle.UnsetEventCb(Interop.ViewEventType.Gesture);
711 _gestureEventCallback = null;
712 Log.Info(string.Format("Gesture event callback is unset"));
715 private void SetObjectEventCallback()
717 if (_objectEventCallback == null)
719 _objectEventCallback = (type, eventData, userData) =>
721 if (type != Interop.ViewEventType.Object) return;
722 var eventArg = new Interop.ObjectEventDataHandle(eventData);
723 switch (eventArg.GestureType)
725 case Interop.ViewGesture.Click:
727 var mapObject = _handleToObjectTable[eventArg.ViewObject];
728 mapObject?.HandleClickedEvent();
733 handle.SetEventCb(Interop.ViewEventType.Object, _objectEventCallback, IntPtr.Zero);
734 Log.Info(string.Format("Object event callback is set"));
738 private void SetViewReadyEventCallback()
740 if (_viewReadyEventCallback == null)
742 _viewReadyEventCallback = (type, eventData, userData) =>
744 _viewReadyEventHandler?.Invoke(this, EventArgs.Empty);
746 handle.SetEventCb(Interop.ViewEventType.Ready, _viewReadyEventCallback, IntPtr.Zero);
747 Log.Info(string.Format("ViewReady event callback is set"));
751 private void UnsetViewReadyEventCallback()
753 if (_viewReadyEventHandler == null)
755 handle.UnsetEventCb(Interop.ViewEventType.Ready);
756 _viewReadyEventCallback = null;
757 Log.Info(string.Format("ViewReady event callback is unset"));
761 #region IDisposable Support
762 private bool _disposedValue = false;
765 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
767 /// <param name="disposing">If true, managed and unmanaged resources can be disposed, otherwise only unmanaged resources can be disposed.</param>
768 /// <since_tizen> 3 </since_tizen>
769 protected virtual void Dispose(bool disposing)
775 _handleToObjectTable?.Clear();
778 _disposedValue = true;
783 /// Releases all the resources used by this object.
785 /// <since_tizen> 3 </since_tizen>
786 public void Dispose()
789 GC.SuppressFinalize(this);