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.
18 using System.Runtime.InteropServices;
21 internal static partial class Interop
23 internal enum ViewType
25 Normal, // MAPS_VIEW_TYPE_NORMAL
26 Satellite, // MAPS_VIEW_TYPE_SATELLITE
27 Terrain, // MAPS_VIEW_TYPE_TERRAIN
28 Hybrid, // MAPS_VIEW_TYPE_HYBRID
31 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
32 internal delegate void ViewOnEventCallback(ViewEventType /* maps_view_event_type_e */ type, IntPtr /* maps_view_event_data_h */ eventData, IntPtr /* void */ userData);
35 [DllImport(Libraries.MapService, EntryPoint = "maps_view_get_zoom_level")]
36 internal static extern ErrorCode GetZoomLevel(this ViewHandle /* maps_view_h */ view, out int level);
38 [DllImport(Libraries.MapService, EntryPoint = "maps_view_set_zoom_level")]
39 internal static extern ErrorCode SetZoomLevel(this ViewHandle /* maps_view_h */ view, int level);
41 [DllImport(Libraries.MapService, EntryPoint = "maps_view_get_min_zoom_level")]
42 internal static extern ErrorCode GetMinZoomLevel(this ViewHandle /* maps_view_h */ view, out int minZoomLevel);
44 [DllImport(Libraries.MapService, EntryPoint = "maps_view_set_min_zoom_level")]
45 internal static extern ErrorCode SetMinZoomLevel(this ViewHandle /* maps_view_h */ view, int minZoomLevel);
47 [DllImport(Libraries.MapService, EntryPoint = "maps_view_get_max_zoom_level")]
48 internal static extern ErrorCode GetMaxZoomLevel(this ViewHandle /* maps_view_h */ view, out int maxZoomLevel);
50 [DllImport(Libraries.MapService, EntryPoint = "maps_view_set_max_zoom_level")]
51 internal static extern ErrorCode SetMaxZoomLevel(this ViewHandle /* maps_view_h */ view, int maxZoomLevel);
53 [DllImport(Libraries.MapService, EntryPoint = "maps_view_get_orientation")]
54 internal static extern ErrorCode GetOrientation(this ViewHandle /* maps_view_h */ view, out double rotationAngle);
56 [DllImport(Libraries.MapService, EntryPoint = "maps_view_set_orientation")]
57 internal static extern ErrorCode SetOrientation(this ViewHandle /* maps_view_h */ view, double rotationAngle);
59 [DllImport(Libraries.MapService, EntryPoint = "maps_view_get_language")]
60 internal static extern ErrorCode GetLanguage(this ViewHandle /* maps_view_h */ view, out string language);
62 [DllImport(Libraries.MapService, EntryPoint = "maps_view_set_language")]
63 internal static extern ErrorCode SetLanguage(this ViewHandle /* maps_view_h */ view, string language);
65 [DllImport(Libraries.MapService, EntryPoint = "maps_view_set_type")]
66 internal static extern ErrorCode SetMapType(this ViewHandle /* maps_view_h */ view, ViewType /* maps_view_type_e */ type);
68 [DllImport(Libraries.MapService, EntryPoint = "maps_view_get_type")]
69 internal static extern ErrorCode GetMapType(this ViewHandle /* maps_view_h */ view, out ViewType /* maps_view_type_e */ type);
71 [DllImport(Libraries.MapService, EntryPoint = "maps_view_get_buildings_enabled")]
72 internal static extern ErrorCode GetBuildingsEnabled(this ViewHandle /* maps_view_h */ view, out bool enable);
74 [DllImport(Libraries.MapService, EntryPoint = "maps_view_set_buildings_enabled")]
75 internal static extern ErrorCode SetBuildingsEnabled(this ViewHandle /* maps_view_h */ view, bool enable);
77 [DllImport(Libraries.MapService, EntryPoint = "maps_view_get_traffic_enabled")]
78 internal static extern ErrorCode GetTrafficEnabled(this ViewHandle /* maps_view_h */ view, out bool enable);
80 [DllImport(Libraries.MapService, EntryPoint = "maps_view_set_traffic_enabled")]
81 internal static extern ErrorCode SetTrafficEnabled(this ViewHandle /* maps_view_h */ view, bool enable);
83 [DllImport(Libraries.MapService, EntryPoint = "maps_view_get_public_transit_enabled")]
84 internal static extern ErrorCode GetPublicTransitEnabled(this ViewHandle /* maps_view_h */ view, out bool enable);
86 [DllImport(Libraries.MapService, EntryPoint = "maps_view_set_public_transit_enabled")]
87 internal static extern ErrorCode SetPublicTransitEnabled(this ViewHandle /* maps_view_h */ view, bool enable);
89 [DllImport(Libraries.MapService, EntryPoint = "maps_view_get_scalebar_enabled")]
90 internal static extern ErrorCode GetScaleBarEnabled(this ViewHandle /* maps_view_h */ view, out bool enabled);
92 [DllImport(Libraries.MapService, EntryPoint = "maps_view_set_scalebar_enabled")]
93 internal static extern ErrorCode SetScaleBarEnabled(this ViewHandle /* maps_view_h */ view, bool enable);
95 [DllImport(Libraries.MapService, EntryPoint = "maps_view_get_screen_location")]
96 internal static extern ErrorCode GetScreenLocation(this ViewHandle /* maps_view_h */ view, out int x, out int y, out int width, out int height);
98 [DllImport(Libraries.MapService, EntryPoint = "maps_view_set_screen_location")]
99 internal static extern ErrorCode SetScreenLocation(this ViewHandle /* maps_view_h */ view, int x, int y, int width, int height);
101 [DllImport(Libraries.MapService, EntryPoint = "maps_view_get_visibility")]
102 internal static extern ErrorCode GetVisibility(this ViewHandle /* maps_view_h */ view, out bool visible);
104 [DllImport(Libraries.MapService, EntryPoint = "maps_view_set_visibility")]
105 internal static extern ErrorCode SetVisibility(this ViewHandle /* maps_view_h */ view, bool visible);
107 [DllImport(Libraries.MapService, EntryPoint = "maps_view_get_viewport")]
108 internal static extern ErrorCode GetViewport(this ViewHandle /* maps_view_h */ view, out IntPtr viewport);
110 [DllImport(Libraries.MapService, EntryPoint = "maps_view_get_center")]
111 internal static extern ErrorCode GetCenter(this ViewHandle /* maps_view_h */ view, out IntPtr /* maps_coordinates_h */ coordinates);
113 [DllImport(Libraries.MapService, EntryPoint = "maps_view_set_center")]
114 internal static extern ErrorCode SetCenter(this ViewHandle /* maps_view_h */ view, CoordinatesHandle /* maps_coordinates_h */ coordinates);
117 [DllImport(Libraries.MapService, EntryPoint = "maps_view_get_gesture_enabled")]
118 internal static extern ErrorCode GetGestureEnabled(this ViewHandle /* maps_view_h */ view, ViewGesture /* maps_view_gesture_e */ gesture, out bool enabled);
120 [DllImport(Libraries.MapService, EntryPoint = "maps_view_set_gesture_enabled")]
121 internal static extern ErrorCode SetGestureEnabled(this ViewHandle /* maps_view_h */ view, ViewGesture /* maps_view_gesture_e */ gesture, bool enabled);
123 [DllImport(Libraries.MapService, EntryPoint = "maps_view_set_event_cb")]
124 internal static extern ErrorCode SetEventCb(this ViewHandle /* maps_view_h */ view, ViewEventType /* maps_view_event_type_e */ type, ViewOnEventCallback callback, IntPtr /* void */ userData);
126 [DllImport(Libraries.MapService, EntryPoint = "maps_view_unset_event_cb")]
127 internal static extern ErrorCode UnsetEventCb(this ViewHandle /* maps_view_h */ view, ViewEventType /* maps_view_event_type_e */ type);
129 [DllImport(Libraries.MapService, EntryPoint = "maps_view_screen_to_geolocation")]
130 internal static extern ErrorCode ScreenToGeolocation(this ViewHandle /* maps_view_h */ view, int x, int y, out IntPtr /* maps_coordinates_h */ coordinates);
132 [DllImport(Libraries.MapService, EntryPoint = "maps_view_geolocation_to_screen")]
133 internal static extern ErrorCode GeolocationToScreen(this ViewHandle /* maps_view_h */ view, CoordinatesHandle /* maps_coordinates_h */ coordinates, out int x, out int y);
135 [DllImport(Libraries.MapService, EntryPoint = "maps_view_move")]
136 internal static extern ErrorCode Move(this ViewHandle /* maps_view_h */ view, int x, int y);
138 [DllImport(Libraries.MapService, EntryPoint = "maps_view_resize")]
139 internal static extern ErrorCode Resize(this ViewHandle /* maps_view_h */ view, int width, int height);
141 [DllImport(Libraries.MapService, EntryPoint = "maps_view_add_object")]
142 internal static extern ErrorCode AddObject(this ViewHandle /* maps_view_h */ view, ViewObjectHandle /* maps_view_object_h */ viewObject);
144 [DllImport(Libraries.MapService, EntryPoint = "maps_view_remove_object")]
145 internal static extern ErrorCode RemoveObject(this ViewHandle /* maps_view_h */ view, ViewObjectHandle /* maps_view_object_h */ viewObject);
147 [DllImport(Libraries.MapService, EntryPoint = "maps_view_remove_all_objects")]
148 internal static extern ErrorCode RemoveAllObjects(this ViewHandle /* maps_view_h */ view);
150 internal class ViewHandle : SafeMapsHandle
152 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
153 internal delegate bool ViewObjectCallback(int index, int total, IntPtr /* maps_view_object_h */ viewObject, IntPtr /* void */ userData);
155 [DllImport(Libraries.MapService, EntryPoint = "maps_view_foreach_object")]
156 internal static extern ErrorCode ForeachObject(ViewHandle /* maps_view_h */ view, ViewObjectCallback callback, IntPtr /* void */ userData);
158 [DllImport(Libraries.MapService, EntryPoint = "maps_view_create")]
159 internal static extern ErrorCode Create(ServiceHandle /* maps_service_h */ maps, IntPtr obj, out IntPtr /* maps_view_h */ view);
161 [DllImport(Libraries.MapService, EntryPoint = "maps_view_destroy")]
162 internal static extern ErrorCode Destroy(IntPtr /* maps_view_h */ view);
164 internal int ZoomLevel
166 get { return NativeGet<int>(this.GetZoomLevel); }
167 set { NativeSet(this.SetZoomLevel, value); }
170 internal int MinimumZoomLevel
172 get { return NativeGet<int>(this.GetMinZoomLevel); }
173 set { NativeSet(this.SetMinZoomLevel, value); }
176 internal int MaximumZoomLevel
178 get { return NativeGet<int>(this.GetMaxZoomLevel); }
179 set { NativeSet(this.SetMaxZoomLevel, value); }
182 internal double Orientation
184 get { return NativeGet<double>(this.GetOrientation); }
185 set { NativeSet(this.SetOrientation, value); }
188 internal ViewType MapType
190 get { return NativeGet<ViewType>(this.GetMapType); }
191 set { NativeSet(this.SetMapType, value); }
194 internal bool BuildingsEnabled
196 get { return NativeGet<bool>(this.GetBuildingsEnabled); }
197 set { NativeSet(this.SetBuildingsEnabled, value); }
200 internal bool TrafficEnabled
202 get { return NativeGet<bool>(this.GetTrafficEnabled); }
203 set { NativeSet(this.SetTrafficEnabled, value); }
206 internal bool PublicTransitEnabled
208 get { return NativeGet<bool>(this.GetPublicTransitEnabled); }
209 set { NativeSet(this.SetPublicTransitEnabled, value); }
211 internal bool ScaleBarEnabled
213 get { return NativeGet<bool>(this.GetScaleBarEnabled); }
214 set { NativeSet(this.SetScaleBarEnabled, value); }
217 internal string Language
219 get { return NativeGet(this.GetLanguage); }
220 set { NativeSet(this.SetLanguage, value); }
223 internal bool IsVisible
225 get { return NativeGet<bool>(this.GetVisibility); }
226 set { NativeSet(this.SetVisibility, value); }
229 internal CoordinatesHandle Center
231 get { return NativeGet(this.GetCenter, CoordinatesHandle.Create); }
232 set { NativeSet(this.SetCenter, value); }
235 public ViewHandle(IntPtr handle, bool needToRelease) : base(handle, needToRelease, Destroy)
239 public ViewHandle(ServiceHandle maps, IntPtr evasObject) : this(IntPtr.Zero, true)
241 Create(maps, evasObject, out handle).ThrowIfFailed("Failed to create native handle");
244 internal CoordinatesHandle ScreenToGeolocation(Point position)
247 this.ScreenToGeolocation(position.X, position.Y, out coordinates).WarnIfFailed("Failed to convert screen position to geocoordinates");
248 return CoordinatesHandle.Create(coordinates);
251 internal Point GeolocationToScreen(CoordinatesHandle coordinates)
254 this.GeolocationToScreen(coordinates, out x, out y).WarnIfFailed("Failed to convert geocoordinates to screen position");
255 return new Point() { X = x, Y = y };