Loading...
Searching...
No Matches
location_window_interaction_example.dart
Go to the documentation of this file.
1import 'dart:ffi';
2import 'dart:math' as math;
3import 'package:meta/meta.dart';
4import 'package:navigine_sdk/com/_library_context.dart' as __lib;
5import 'package:navigine_sdk/com/_native_base.dart' as __lib;
6import 'package:navigine_sdk/com/_weak_map.dart';
7import 'package:navigine_sdk/com/builtin_types__conversion.dart';
8import 'package:navigine_sdk/com/navigine/idl/input_listener.dart';
9import 'package:navigine_sdk/com/navigine/idl/pick_listener.dart';
10import 'package:navigine_sdk/com/navigine/idl/map_object_pick_result.dart';
11import 'package:navigine_sdk/com/navigine/idl/location_point.dart';
12import 'package:navigine_sdk/com/navigine/idl/map_object.dart';
13import 'package:navigine_sdk/com/navigine/idl/point.dart';
14import 'package:navigine_sdk/screen_point.dart';
15
22class LocationWindowInteractionExample {
23 LocationWindow? _locationWindow;
24 InputListener? _inputListener;
25 PickListener? _pickListener;
26
27 LocationWindowInteractionExample() {
28 _demonstrateLocationWindowInteractionMethods();
29 }
30
34 void _demonstrateLocationWindowInteractionMethods() {
35 print("=== LocationWindowInteraction Example ===");
36
37 _demonstrateGestureProperties();
38 _demonstratePickProperties();
39 _demonstratePickMethods();
40 _demonstrateInputListeners();
41 _demonstratePickListeners();
42 _cleanup();
43 }
44
48 void _demonstrateGestureProperties() {
49 print("--- Gesture Properties ---");
50
51 if (_locationWindow == null) {
52 print("LocationWindow not available yet");
53 return;
54 }
55
56 // [dart_LocationWindow_setStickToBorder]
57 // Set stick to border property
58 _locationWindow!.stickToBorder = true;
59 print("Set stick to border to true");
60 // [dart_LocationWindow_setStickToBorder]
61
62 // [dart_LocationWindow_setRotateGestureEnabled]
63 // Set rotate gesture enabled
64 _locationWindow!.rotateGestureEnabled = true;
65 print("Set rotate gesture enabled to true");
66 // [dart_LocationWindow_setRotateGestureEnabled]
67
68 // [dart_LocationWindow_setTiltGesturesEnabled]
69 // Set tilt gestures enabled
70 _locationWindow!.tiltGesturesEnabled = true;
71 print("Set tilt gestures enabled to true");
72 // [dart_LocationWindow_setTiltGesturesEnabled]
73
74 // [dart_LocationWindow_setScrollGesturesEnabled]
75 // Set scroll gestures enabled
76 _locationWindow!.scrollGesturesEnabled = true;
77 print("Set scroll gestures enabled to true");
78 // [dart_LocationWindow_setScrollGesturesEnabled]
79
80 // [dart_LocationWindow_setZoomGesturesEnabled]
81 // Set zoom gestures enabled
82 _locationWindow!.zoomGesturesEnabled = true;
83 print("Set zoom gestures enabled to true");
84 // [dart_LocationWindow_setZoomGesturesEnabled]
85
86 // Test different gesture combinations
87 List<Map<String, dynamic>> gestureTests = [
88 {"rotate": true, "tilt": true, "scroll": true, "zoom": true, "stick": true},
89 {"rotate": false, "tilt": true, "scroll": true, "zoom": true, "stick": false},
90 {"rotate": true, "tilt": false, "scroll": true, "zoom": false, "stick": true},
91 {"rotate": false, "tilt": false, "scroll": false, "zoom": false, "stick": false},
92 ];
93
94 for (int i = 0; i < gestureTests.length; i++) {
95 Map<String, dynamic> test = gestureTests[i];
96 _locationWindow!.rotateGestureEnabled = test["rotate"];
97 _locationWindow!.tiltGesturesEnabled = test["tilt"];
98 _locationWindow!.scrollGesturesEnabled = test["scroll"];
99 _locationWindow!.zoomGesturesEnabled = test["zoom"];
100 _locationWindow!.stickToBorder = test["stick"];
101 print("Gesture test $i: Rotate=${test["rotate"]}, Tilt=${test["tilt"]}, Scroll=${test["scroll"]}, Zoom=${test["zoom"]}, Stick=${test["stick"]}");
102 }
103 }
104
108 void _demonstratePickProperties() {
109 print("--- Pick Properties ---");
110
111 if (_locationWindow == null) {
112 print("LocationWindow not available yet");
113 return;
114 }
115
116 // [dart_LocationWindow_setPickRadius]
117 // Set pick radius
118 _locationWindow!.pickRadius = 10.0;
119 print("Set pick radius to 10.0 pixels");
120 // [dart_LocationWindow_setPickRadius]
121
122 // Test different pick radius values
123 List<double> pickRadiusTests = [5.0, 10.0, 20.0, 50.0, 100.0];
124
125 for (int i = 0; i < pickRadiusTests.length; i++) {
126 double radius = pickRadiusTests[i];
127 _locationWindow!.pickRadius = radius;
128 print("Pick radius test $i: ${radius} pixels");
129 }
130 }
131
135 void _demonstratePickMethods() {
136 print("--- Pick Methods ---");
137
138 if (_locationWindow == null) {
139 print("LocationWindow not available yet");
140 return;
141 }
142
143 // [dart_LocationWindow_pickMapObjectAt]
144 // Pick map object at screen position
145 math.Point<double> screenPoint = math.Point<double>(100.0, 200.0);
146 _locationWindow!.pickMapObjectAt(screenPoint);
147 print("Picked map object at screen position (${screenPoint.x}, ${screenPoint.y})");
148 // [dart_LocationWindow_pickMapObjectAt]
149
150 // [dart_LocationWindow_pickMapFeatureAt]
151 // Pick map feature at screen position
152 math.Point<double> featurePoint = math.Point<double>(150.0, 250.0);
153 _locationWindow!.pickMapFeatureAt(featurePoint);
154 print("Picked map feature at screen position (${featurePoint.x}, ${featurePoint.y})");
155 // [dart_LocationWindow_pickMapFeatureAt]
156
157 // Test pick at different positions
158 List<math.Point<double>> pickTests = [
159 math.Point<double>(50.0, 50.0),
160 math.Point<double>(200.0, 300.0),
161 math.Point<double>(400.0, 100.0),
162 math.Point<double>(300.0, 400.0),
163 ];
164
165 for (int i = 0; i < pickTests.length; i++) {
166 math.Point<double> point = pickTests[i];
167 _locationWindow!.pickMapObjectAt(point);
168 _locationWindow!.pickMapFeatureAt(point);
169 print("Pick test $i: Object and feature at (${point.x}, ${point.y})");
170 }
171 }
172
176 void _demonstrateInputListeners() {
177 print("--- Input Listeners ---");
178
179 if (_locationWindow == null) {
180 print("LocationWindow not available yet");
181 return;
182 }
183
184 // [dart_LocationWindow_addInputListener]
185 // Add input listener
186 _inputListener = InputListenerImpl();
187 _locationWindow!.addInputListener(_inputListener!);
188 print("Added input listener");
189 // [dart_LocationWindow_addInputListener]
190
191 // [dart_LocationWindow_removeInputListener]
192 // Remove input listener
193 _locationWindow!.removeInputListener(_inputListener!);
194 _inputListener = null;
195 print("Removed input listener");
196 // [dart_LocationWindow_removeInputListener]
197
198 // Test multiple listeners
199 List<InputListener> listeners = [
200 InputListenerImpl(),
201 InputListenerImpl(),
202 InputListenerImpl(),
203 ];
204
205 for (int i = 0; i < listeners.length; i++) {
206 _locationWindow!.addInputListener(listeners[i]);
207 print("Added input listener $i");
208 }
209
210 for (int i = 0; i < listeners.length; i++) {
211 _locationWindow!.removeInputListener(listeners[i]);
212 print("Removed input listener $i");
213 }
214 }
215
219 void _demonstratePickListeners() {
220 print("--- Pick Listeners ---");
221
222 if (_locationWindow == null) {
223 print("LocationWindow not available yet");
224 return;
225 }
226
227 // [dart_LocationWindow_addPickListener]
228 // Add pick listener
229 _pickListener = PickListenerImpl();
230 _locationWindow!.addPickListener(_pickListener!);
231 print("Added pick listener");
232 // [dart_LocationWindow_addPickListener]
233
234 // Test multiple pick listeners
235 List<PickListener> listeners = [
236 PickListenerImpl(),
237 PickListenerImpl(),
238 PickListenerImpl(),
239 ];
240
241 for (int i = 0; i < listeners.length; i++) {
242 _locationWindow!.addPickListener(listeners[i]);
243 print("Added pick listener $i");
244 }
245
246 for (int i = 0; i < listeners.length; i++) {
247 // [dart_LocationWindow_removePickListener]
248 _locationWindow!.removePickListener(listeners[i]);
249 print("Removed pick listener $i");
250 // [dart_LocationWindow_removePickListener]
251 }
252 }
253
257 void _cleanup() {
258 if (_inputListener != null) {
259 _locationWindow?.removeInputListener(_inputListener!);
260 _inputListener = null;
261 }
262 if (_pickListener != null) {
263 _locationWindow?.removePickListener(_pickListener!);
264 _pickListener = null;
265 }
266 print("LocationWindowInteraction example cleanup completed");
267 }
268}
269
270// Input listener implementation
271class InputListenerImpl implements InputListener {
272 // [dart_InputListener_onViewTap]
273 @override
274 void onViewTap(math.Point<double> screenPoint) {
275 print("View tapped at screen position (${screenPoint.x}, ${screenPoint.y})");
276 }
277 // [dart_InputListener_onViewTap]
278
279 // [dart_InputListener_onViewDoubleTap]
280 @override
281 void onViewDoubleTap(math.Point<double> screenPoint) {
282 print("View double tapped at screen position (${screenPoint.x}, ${screenPoint.y})");
283 }
284 // [dart_InputListener_onViewDoubleTap]
285
286 // [dart_InputListener_onViewLongTap]
287 @override
288 void onViewLongTap(math.Point<double> screenPoint) {
289 print("View long tapped at screen position (${screenPoint.x}, ${screenPoint.y})");
290 }
291 // [dart_InputListener_onViewLongTap]
292}
293
294// Pick listener implementation
295class PickListenerImpl implements PickListener {
296 // [dart_PickListener_onMapObjectPickComplete]
297 @override
298 void onMapObjectPickComplete(MapObjectPickResult? mapObjectPickResult, math.Point<double> screenPosition) {
299 if (mapObjectPickResult != null) {
300 // [dart_MapObjectPickResult_getPoint]
301 LocationPoint point = mapObjectPickResult.point;
302 print("Map object picked at screen position (${screenPosition.x}, ${screenPosition.y})");
303 print(" Object location: (${point.x}, ${point.y})");
304 // [dart_MapObjectPickResult_getPoint]
305
306 // [dart_MapObjectPickResult_getMapObject]
307 MapObject mapObject = mapObjectPickResult.mapObject;
308 print(" Object type: ${mapObject.runtimeType}");
309 // [dart_MapObjectPickResult_getMapObject]
310 } else {
311 print("No map object found at screen position (${screenPosition.x}, ${screenPosition.y})");
312 }
313 }
314 // [dart_PickListener_onMapObjectPickComplete]
315
316 // [dart_PickListener_onMapFeaturePickComplete]
317 @override
318 void onMapFeaturePickComplete(Map<String, String>? mapFeaturePickResult, math.Point<double> screenPosition) {
319 if (mapFeaturePickResult != null) {
320 print("Map feature picked at screen position (${screenPosition.x}, ${screenPosition.y})");
321 print(" Feature properties: $mapFeaturePickResult");
322 } else {
323 print("No map feature found at screen position (${screenPosition.x}, ${screenPosition.y})");
324 }
325 }
326 // [dart_PickListener_onMapFeaturePickComplete]
327}
328
329// Main function
330void main() {
332}