Loading...
Searching...
No Matches
LocationWindowCameraExample.m
Go to the documentation of this file.
1#import <Foundation/Foundation.h>
2#import <NavigineSDK/NavigineSDK.h>
3
9@interface LocationWindowCameraExample : NSObject
10
11@property (nonatomic, strong) NCLocationWindow *locationWindow;
12@property (nonatomic, strong) id<NCCameraListener> cameraListener;
13
14- (instancetype)init;
16- (void)cleanup;
17
18@end
19
20@implementation LocationWindowCameraExample
21
22- (instancetype)init {
23 self = [super init];
24 if (self) {
26 }
27 return self;
28}
29
31 NSLog(@"=== LocationWindowCamera Example ===");
32
34 [self getCurrentCamera];
35 [self setCameraPosition];
36 [self addCameraListener];
37 [self flyToPosition];
38 [self moveToWithAnimation];
39 [self removeCameraListener];
40}
41
43 // [objc_LocationWindow_zoomFactor]
44 // Set zoom factor
45 _locationWindow.zoomFactor = 100.0f;
46 NSLog(@"Set zoom factor to 100.0 pixels per meter");
47 // [objc_LocationWindow_zoomFactor]
48
49 // [objc_LocationWindow_minZoomFactor]
50 // Set minimum zoom factor
51 _locationWindow.minZoomFactor = 10.0f;
52 NSLog(@"Set minimum zoom factor to 10.0 pixels per meter");
53 // [objc_LocationWindow_minZoomFactor]
54
55 // [objc_LocationWindow_maxZoomFactor]
56 // Set maximum zoom factor
57 _locationWindow.maxZoomFactor = 1000.0f;
58 NSLog(@"Set maximum zoom factor to 1000.0 pixels per meter");
59 // [objc_LocationWindow_maxZoomFactor]
60}
61
62- (void)getCurrentCamera {
63 // [objc_LocationWindow_getCamera]
64 // Get current camera position
65 NCCamera *currentCamera = _locationWindow.camera;
66 NSLog(@"Current camera position:");
67 NSLog(@" Point: (%.2f, %.2f)", currentCamera.point.x, currentCamera.point.y);
68 NSLog(@" Zoom: %.2f", currentCamera.zoom);
69 NSLog(@" Rotation: %.2f°", currentCamera.rotation);
70 // [objc_LocationWindow_getCamera]
71}
72
73- (void)setCameraPosition {
74 // [objc_Camera_constructor]
75 // Create camera with constructor
76 NCPoint *newPoint = [[NCPoint alloc] initWithX:100.0 y:200.0];
77 NCCamera *newCamera = [[NCCamera alloc] initWithPoint:newPoint zoom:50.0 rotation:0.0];
78 NSLog(@"Created camera with point (%.2f, %.2f), zoom 50.0, rotation 0°", newPoint.x, newPoint.y);
79 // [objc_Camera_constructor]
80
81 // [objc_Camera_access]
82 // Access camera properties
83 NSLog(@"Camera properties:");
84 NSLog(@" Point: (%.2f, %.2f)", newCamera.point.x, newCamera.point.y);
85 NSLog(@" Zoom: %.2f", newCamera.zoom);
86 NSLog(@" Rotation: %.2f°", newCamera.rotation);
87 // [objc_Camera_access]
88
89 // [objc_LocationWindow_setCamera]
90 // Set camera position without animation
91 _locationWindow.camera = newCamera;
92 NSLog(@"Set camera position to (%.2f, %.2f) with zoom 50.0 and rotation 0°", newPoint.x, newPoint.y);
93 // [objc_LocationWindow_setCamera]
94
95 // [objc_LocationWindow_setCamera_2]
96 // Set camera position with rotation
97 NCPoint *rotatedPoint = [[NCPoint alloc] initWithX:150.0 y:250.0];
98 NCCamera *rotatedCamera = [[NCCamera alloc] initWithPoint:rotatedPoint zoom:75.0 rotation:45.0];
99 _locationWindow.camera = rotatedCamera;
100 NSLog(@"Set camera position to (%.2f, %.2f) with zoom 75.0 and rotation 45°", rotatedPoint.x, rotatedPoint.y);
101 // [objc_LocationWindow_setCamera_2]
102
103 // Test different camera positions
104 NSArray *testCameras = @[
105 [[NCCamera alloc] initWithPoint:[[NCPoint alloc] initWithX:0.0 y:0.0] zoom:10.0 rotation:0.0], // Overview camera
106 [[NCCamera alloc] initWithPoint:[[NCPoint alloc] initWithX:50.0 y:75.0] zoom:500.0 rotation:0.0], // Detail camera
107 [[NCCamera alloc] initWithPoint:[[NCPoint alloc] initWithX:100.0 y:150.0] zoom:100.0 rotation:30.0], // Angled camera
108 ];
109
110 for (int i = 0; i < testCameras.count; i++) {
111 NCCamera *camera = testCameras[i];
112 _locationWindow.camera = camera;
113 NSLog(@"Test camera %d: Point (%.2f, %.2f), Zoom %.2f, Rotation %.2f°", i, camera.point.x, camera.point.y, camera.zoom, camera.rotation);
114 }
115}
116
117- (void)addCameraListener {
118 // [objc_LocationWindow_addCameraListener]
119 // Add camera listener
120 _cameraListener = [[CameraListenerImpl alloc] init];
121 [_locationWindow addCameraListener:_cameraListener];
122 NSLog(@"Added camera listener");
123 // [objc_LocationWindow_addCameraListener]
124
125 // Test multiple listeners
126 NSArray *listeners = @[
127 [[CameraListenerImpl alloc] init],
128 [[CameraListenerImpl alloc] init],
129 [[CameraListenerImpl alloc] init],
130 ];
131
132 for (int i = 0; i < listeners.count; i++) {
133 [_locationWindow addCameraListener:listeners[i]];
134 NSLog(@"Added camera listener %d", i);
135 }
136
137 for (int i = 0; i < listeners.count; i++) {
138 [_locationWindow removeCameraListener:listeners[i]];
139 NSLog(@"Removed camera listener %d", i);
140 }
141}
142
143- (void)flyToPosition {
144 // [objc_LocationWindow_flyTo]
145 // Fly to position with smooth animation
146 NCPoint *targetPoint = [[NCPoint alloc] initWithX:150.0 y:250.0];
147 NCCamera *targetCamera = [[NCCamera alloc] initWithPoint:targetPoint zoom:75.0 rotation:45.0];
148 CameraCallbackImpl *callback = [[CameraCallbackImpl alloc] init];
149
150 [_locationWindow flyToWithCamera:targetCamera duration:2000 callback:callback];
151 NSLog(@"Started fly to animation to point (%.2f, %.2f)", targetPoint.x, targetPoint.y);
152 // [objc_LocationWindow_flyTo]
153
154 // [objc_LocationWindow_flyTo_2]
155 // Fly to another position with different duration
156 NCPoint *targetPoint2 = [[NCPoint alloc] initWithX:300.0 y:400.0];
157 NCCamera *targetCamera2 = [[NCCamera alloc] initWithPoint:targetPoint2 zoom:25.0 rotation:180.0];
158 CameraCallbackImpl *callback2 = [[CameraCallbackImpl alloc] init];
159
160 [_locationWindow flyToWithCamera:targetCamera2 duration:3000 callback:callback2];
161 NSLog(@"Started fly to animation to point (%.2f, %.2f) with 3 second duration", targetPoint2.x, targetPoint2.y);
162 // [objc_LocationWindow_flyTo_2]
163
164 // Test fly to with different parameters
165 NSArray *flyToTests = @[
166 @{@"point": [[NCPoint alloc] initWithX:50.0 y:50.0], @"zoom": @100.0, @"rotation": @0.0, @"duration": @1000},
167 @{@"point": [[NCPoint alloc] initWithX:200.0 y:300.0], @"zoom": @200.0, @"rotation": @90.0, @"duration": @1500},
168 @{@"point": [[NCPoint alloc] initWithX:400.0 y:100.0], @"zoom": @50.0, @"rotation": @270.0, @"duration": @2500},
169 ];
170
171 for (int i = 0; i < flyToTests.count; i++) {
172 NSDictionary *test = flyToTests[i];
173 NCPoint *point = test[@"point"];
174 double zoom = [test[@"zoom"] doubleValue];
175 double rotation = [test[@"rotation"] doubleValue];
176 int duration = [test[@"duration"] intValue];
177
178 NCCamera *camera = [[NCCamera alloc] initWithPoint:point zoom:zoom rotation:rotation];
179 CameraCallbackImpl *testCallback = [[CameraCallbackImpl alloc] init];
180 [_locationWindow flyToWithCamera:camera duration:duration callback:testCallback];
181 NSLog(@"Fly to test %d: Point (%.2f, %.2f), Zoom %.2f, Rotation %.2f°, Duration %dms", i, point.x, point.y, zoom, rotation, duration);
182 }
183}
184
185- (void)moveToWithAnimation {
186 // [objc_LocationWindow_moveTo]
187 // Move to position with linear animation
188 NCPoint *targetPoint = [[NCPoint alloc] initWithX:200.0 y:300.0];
189 NCCamera *targetCamera = [[NCCamera alloc] initWithPoint:targetPoint zoom:100.0 rotation:90.0];
190 CameraCallbackImpl *callback = [[CameraCallbackImpl alloc] init];
191
192 [_locationWindow moveToWithCamera:targetCamera duration:1500 animationType:NCAnimationTypeLinear callback:callback];
193 NSLog(@"Started move to with linear animation");
194 // [objc_LocationWindow_moveTo]
195
196 // [objc_LocationWindow_moveTo_2]
197 // Move to position with cubic animation
198 CameraCallbackImpl *callback2 = [[CameraCallbackImpl alloc] init];
199 [_locationWindow moveToWithCamera:targetCamera duration:1500 animationType:NCAnimationTypeCubic callback:callback2];
200 NSLog(@"Started move to with cubic animation");
201 // [objc_LocationWindow_moveTo_2]
202
203 // [objc_LocationWindow_moveTo_3]
204 // Move to position with sine animation
205 CameraCallbackImpl *callback3 = [[CameraCallbackImpl alloc] init];
206 [_locationWindow moveToWithCamera:targetCamera duration:1500 animationType:NCAnimationTypeSine callback:callback3];
207 NSLog(@"Started move to with sine animation");
208 // [objc_LocationWindow_moveTo_3]
209
210 // [objc_LocationWindow_moveTo_4]
211 // Move to position without animation
212 NCPoint *instantPoint = [[NCPoint alloc] initWithX:300.0 y:400.0];
213 NCCamera *instantCamera = [[NCCamera alloc] initWithPoint:instantPoint zoom:25.0 rotation:180.0];
214 CameraCallbackImpl *instantCallback = [[CameraCallbackImpl alloc] init];
215
216 [_locationWindow moveToWithCamera:instantCamera duration:0 animationType:NCAnimationTypeNone callback:instantCallback];
217 NSLog(@"Executed instant move to position (%.2f, %.2f)", instantPoint.x, instantPoint.y);
218 // [objc_LocationWindow_moveTo_4]
219
220 // Test move to with different animation types
221 NSArray *animationTypes = @[
222 @(NCAnimationTypeLinear),
223 @(NCAnimationTypeCubic),
224 @(NCAnimationTypeQuint),
225 @(NCAnimationTypeSine),
226 @(NCAnimationTypeNone),
227 ];
228
229 for (int i = 0; i < animationTypes.count; i++) {
230 NCAnimationType animationType = [animationTypes[i] integerValue];
231 CameraCallbackImpl *testCallback = [[CameraCallbackImpl alloc] init];
232 [_locationWindow moveToWithCamera:targetCamera duration:1000 animationType:animationType callback:testCallback];
233 NSLog(@"Move to test with animation type %d", (int)animationType);
234 }
235}
236
237- (void)removeCameraListener {
238 // [objc_LocationWindow_removeCameraListener]
239 // Remove camera listener
240 [_locationWindow removeCameraListener:_cameraListener];
241 _cameraListener = nil;
242 NSLog(@"Removed camera listener");
243 // [objc_LocationWindow_removeCameraListener]
244}
245
246- (void)cleanup {
247 if (_cameraListener != nil) {
248 [_locationWindow removeCameraListener:_cameraListener];
249 _cameraListener = nil;
250 }
251 NSLog(@"LocationWindowCamera example cleanup completed");
252}
253
254@end
255
256// Camera listener implementation
257@interface CameraListenerImpl : NSObject <NCCameraListener>
258@end
259
260@implementation CameraListenerImpl
261
262// [objc_CameraListener_onCameraPositionChanged]
263- (void)onCameraPositionChangedWithReason:(NCCameraUpdateReason)reason finished:(BOOL)finished {
264 NSString *reasonString = @"";
265 switch (reason) {
266 case NCCameraUpdateReasonUser:
267 reasonString = @"User";
268 break;
269 case NCCameraUpdateReasonAnimation:
270 reasonString = @"Animation";
271 break;
272 case NCCameraUpdateReasonProgrammatic:
273 reasonString = @"Programmatic";
274 break;
275 }
276 NSLog(@"Camera position changed - Reason: %@, Finished: %@", reasonString, finished ? @"Yes" : @"No");
277}
278// [objc_CameraListener_onCameraPositionChanged]
279
280@end
281
282// Camera callback implementation
283@interface CameraCallbackImpl : NSObject <NCCameraCallback>
284@end
285
286@implementation CameraCallbackImpl
287
288- (void)onMoveFinishedWithCompleted:(BOOL)completed {
289 NSLog(@"Camera move animation %@", completed ? @"completed" : @"cancelled");
290}
291
292@end
293
294// Main function
295int main(int argc, const char * argv[]) {
296 @autoreleasepool {
298 [example cleanup];
299 }
300 return 0;
301}