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 // [objc_AnimationType_enum]
222 NSArray *animationTypes = @[
223 @(NCAnimationTypeLinear),
224 @(NCAnimationTypeCubic),
225 @(NCAnimationTypeQuint),
226 @(NCAnimationTypeSine),
227 @(NCAnimationTypeNone),
228 ];
229 // [objc_AnimationType_enum]
230
231 for (int i = 0; i < animationTypes.count; i++) {
232 NCAnimationType animationType = [animationTypes[i] integerValue];
233 CameraCallbackImpl *testCallback = [[CameraCallbackImpl alloc] init];
234 [_locationWindow moveToWithCamera:targetCamera duration:1000 animationType:animationType callback:testCallback];
235 NSLog(@"Move to test with animation type %d", (int)animationType);
236 }
237}
238
239- (void)removeCameraListener {
240 // [objc_LocationWindow_removeCameraListener]
241 // Remove camera listener
242 [_locationWindow removeCameraListener:_cameraListener];
243 _cameraListener = nil;
244 NSLog(@"Removed camera listener");
245 // [objc_LocationWindow_removeCameraListener]
246}
247
248- (void)cleanup {
249 if (_cameraListener != nil) {
250 [_locationWindow removeCameraListener:_cameraListener];
251 _cameraListener = nil;
252 }
253 NSLog(@"LocationWindowCamera example cleanup completed");
254}
255
256@end
257
258// Camera listener implementation
259@interface CameraListenerImpl : NSObject <NCCameraListener>
260@end
261
262@implementation CameraListenerImpl
263
264// [objc_CameraListener_onCameraPositionChanged]
265- (void)onCameraPositionChangedWithReason:(NCCameraUpdateReason)reason finished:(BOOL)finished {
266 NSString *reasonString = @"";
267 switch (reason) {
268 case NCCameraUpdateReasonUser:
269 reasonString = @"User";
270 break;
271 case NCCameraUpdateReasonAnimation:
272 reasonString = @"Animation";
273 break;
274 case NCCameraUpdateReasonProgrammatic:
275 reasonString = @"Programmatic";
276 break;
277 }
278 NSLog(@"Camera position changed - Reason: %@, Finished: %@", reasonString, finished ? @"Yes" : @"No");
279}
280// [objc_CameraListener_onCameraPositionChanged]
281
282@end
283
284// Camera callback implementation
285@interface CameraCallbackImpl : NSObject <NCCameraCallback>
286@end
287
288@implementation CameraCallbackImpl
289
290// [objc_CameraCallback_onMoveFinished]
291- (void)onMoveFinishedWithCompleted:(BOOL)completed {
292 NSLog(@"Camera move animation %@", completed ? @"completed" : @"cancelled");
293}
294// [objc_CameraCallback_onMoveFinished]
295
296@end
297
298// Main function
299int main(int argc, const char * argv[]) {
300 @autoreleasepool {
302 [example cleanup];
303 }
304 return 0;
305}