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 NSLog(@" Tilt: %.2f° (0° = straight downward / map from above)", currentCamera.tilt);
71 // [objc_LocationWindow_getCamera]
72}
73
74- (void)setCameraPosition {
75 // [objc_Camera_constructor]
76 // Create camera with constructor
77 NCPoint *newPoint = [[NCPoint alloc] initWithX:100.0 y:200.0];
78 NCCamera *newCamera = [[NCCamera alloc] initWithPoint:newPoint zoom:50.0 rotation:0.0 tilt:0.0];
79 NSLog(@"Created camera with point (%.2f, %.2f), zoom 50.0, rotation 0°, tilt 0°", newPoint.x, newPoint.y);
80 // [objc_Camera_constructor]
81
82 // [objc_Camera_access]
83 // Access camera properties
84 NSLog(@"Camera properties:");
85 NSLog(@" Point: (%.2f, %.2f)", newCamera.point.x, newCamera.point.y);
86 NSLog(@" Zoom: %.2f", newCamera.zoom);
87 NSLog(@" Rotation: %.2f°", newCamera.rotation);
88 NSLog(@" Tilt: %.2f°", newCamera.tilt);
89 // [objc_Camera_access]
90
91 // [objc_LocationWindow_setCamera]
92 // Set camera position without animation
93 _locationWindow.camera = newCamera;
94 NSLog(@"Set camera position to (%.2f, %.2f) with zoom 50.0, rotation 0°, tilt 0°", newPoint.x, newPoint.y);
95 // [objc_LocationWindow_setCamera]
96
97 // [objc_LocationWindow_setCamera_2]
98 // Set camera position with rotation
99 NCPoint *rotatedPoint = [[NCPoint alloc] initWithX:150.0 y:250.0];
100 NCCamera *rotatedCamera = [[NCCamera alloc] initWithPoint:rotatedPoint zoom:75.0 rotation:45.0 tilt:0.0];
101 _locationWindow.camera = rotatedCamera;
102 NSLog(@"Set camera position to (%.2f, %.2f) with zoom 75.0 and rotation 45°", rotatedPoint.x, rotatedPoint.y);
103 // [objc_LocationWindow_setCamera_2]
104
105 NCCamera *tiltedCamera = [[NCCamera alloc] initWithPoint:rotatedPoint zoom:75.0 rotation:45.0 tilt:40.0];
106 _locationWindow.camera = tiltedCamera;
107 NSLog(@"Set camera with tilt %.2f° for a perspective view", tiltedCamera.tilt);
108
109 // Test different camera positions
110 NSArray *testCameras = @[
111 [[NCCamera alloc] initWithPoint:[[NCPoint alloc] initWithX:0.0 y:0.0] zoom:10.0 rotation:0.0 tilt:0.0], // Overview camera
112 [[NCCamera alloc] initWithPoint:[[NCPoint alloc] initWithX:50.0 y:75.0] zoom:500.0 rotation:0.0 tilt:0.0], // Detail camera
113 [[NCCamera alloc] initWithPoint:[[NCPoint alloc] initWithX:100.0 y:150.0] zoom:100.0 rotation:30.0 tilt:0.0], // Angled camera
114 ];
115
116 for (int i = 0; i < testCameras.count; i++) {
117 NCCamera *camera = testCameras[i];
118 _locationWindow.camera = camera;
119 NSLog(@"Test camera %d: Point (%.2f, %.2f), Zoom %.2f, Rotation %.2f°, Tilt %.2f°", i, camera.point.x, camera.point.y, camera.zoom, camera.rotation, camera.tilt);
120 }
121}
122
123- (void)addCameraListener {
124 // [objc_LocationWindow_addCameraListener]
125 // Add camera listener
126 _cameraListener = [[CameraListenerImpl alloc] init];
127 [_locationWindow addCameraListener:_cameraListener];
128 NSLog(@"Added camera listener");
129 // [objc_LocationWindow_addCameraListener]
130
131 // Test multiple listeners
132 NSArray *listeners = @[
133 [[CameraListenerImpl alloc] init],
134 [[CameraListenerImpl alloc] init],
135 [[CameraListenerImpl alloc] init],
136 ];
137
138 for (int i = 0; i < listeners.count; i++) {
139 [_locationWindow addCameraListener:listeners[i]];
140 NSLog(@"Added camera listener %d", i);
141 }
142
143 for (int i = 0; i < listeners.count; i++) {
144 [_locationWindow removeCameraListener:listeners[i]];
145 NSLog(@"Removed camera listener %d", i);
146 }
147}
148
149- (void)flyToPosition {
150 // [objc_LocationWindow_flyTo]
151 // Fly to position with smooth animation
152 NCPoint *targetPoint = [[NCPoint alloc] initWithX:150.0 y:250.0];
153 NCCamera *targetCamera = [[NCCamera alloc] initWithPoint:targetPoint zoom:75.0 rotation:45.0 tilt:30.0];
154 CameraCallbackImpl *callback = [[CameraCallbackImpl alloc] init];
155
156 [_locationWindow flyToWithCamera:targetCamera duration:2000 callback:callback];
157 NSLog(@"Started fly to animation to point (%.2f, %.2f)", targetPoint.x, targetPoint.y);
158 // [objc_LocationWindow_flyTo]
159
160 // [objc_LocationWindow_flyTo_2]
161 // Fly to another position with different duration
162 NCPoint *targetPoint2 = [[NCPoint alloc] initWithX:300.0 y:400.0];
163 NCCamera *targetCamera2 = [[NCCamera alloc] initWithPoint:targetPoint2 zoom:25.0 rotation:180.0 tilt:0.0];
164 CameraCallbackImpl *callback2 = [[CameraCallbackImpl alloc] init];
165
166 [_locationWindow flyToWithCamera:targetCamera2 duration:3000 callback:callback2];
167 NSLog(@"Started fly to animation to point (%.2f, %.2f) with 3 second duration", targetPoint2.x, targetPoint2.y);
168 // [objc_LocationWindow_flyTo_2]
169
170 // Test fly to with different parameters
171 NSArray *flyToTests = @[
172 @{@"point": [[NCPoint alloc] initWithX:50.0 y:50.0], @"zoom": @100.0, @"rotation": @0.0, @"duration": @1000},
173 @{@"point": [[NCPoint alloc] initWithX:200.0 y:300.0], @"zoom": @200.0, @"rotation": @90.0, @"duration": @1500},
174 @{@"point": [[NCPoint alloc] initWithX:400.0 y:100.0], @"zoom": @50.0, @"rotation": @270.0, @"duration": @2500},
175 ];
176
177 for (int i = 0; i < flyToTests.count; i++) {
178 NSDictionary *test = flyToTests[i];
179 NCPoint *point = test[@"point"];
180 double zoom = [test[@"zoom"] doubleValue];
181 double rotation = [test[@"rotation"] doubleValue];
182 int duration = [test[@"duration"] intValue];
183
184 NCCamera *camera = [[NCCamera alloc] initWithPoint:point zoom:zoom rotation:rotation tilt:0.0];
185 CameraCallbackImpl *testCallback = [[CameraCallbackImpl alloc] init];
186 [_locationWindow flyToWithCamera:camera duration:duration callback:testCallback];
187 NSLog(@"Fly to test %d: Point (%.2f, %.2f), Zoom %.2f, Rotation %.2f°, Duration %dms", i, point.x, point.y, zoom, rotation, duration);
188 }
189}
190
191- (void)moveToWithAnimation {
192 // [objc_LocationWindow_moveTo]
193 // Move to position with linear animation
194 NCPoint *targetPoint = [[NCPoint alloc] initWithX:200.0 y:300.0];
195 NCCamera *targetCamera = [[NCCamera alloc] initWithPoint:targetPoint zoom:100.0 rotation:90.0 tilt:0.0];
196 CameraCallbackImpl *callback = [[CameraCallbackImpl alloc] init];
197
198 [_locationWindow moveToWithCamera:targetCamera duration:1500 animationType:NCAnimationTypeLinear callback:callback];
199 NSLog(@"Started move to with linear animation");
200 // [objc_LocationWindow_moveTo]
201
202 // [objc_LocationWindow_moveTo_2]
203 // Move to position with cubic animation
204 CameraCallbackImpl *callback2 = [[CameraCallbackImpl alloc] init];
205 [_locationWindow moveToWithCamera:targetCamera duration:1500 animationType:NCAnimationTypeCubic callback:callback2];
206 NSLog(@"Started move to with cubic animation");
207 // [objc_LocationWindow_moveTo_2]
208
209 // [objc_LocationWindow_moveTo_3]
210 // Move to position with sine animation
211 CameraCallbackImpl *callback3 = [[CameraCallbackImpl alloc] init];
212 [_locationWindow moveToWithCamera:targetCamera duration:1500 animationType:NCAnimationTypeSine callback:callback3];
213 NSLog(@"Started move to with sine animation");
214 // [objc_LocationWindow_moveTo_3]
215
216 // [objc_LocationWindow_moveTo_4]
217 // Move to position without animation
218 NCPoint *instantPoint = [[NCPoint alloc] initWithX:300.0 y:400.0];
219 NCCamera *instantCamera = [[NCCamera alloc] initWithPoint:instantPoint zoom:25.0 rotation:180.0 tilt:0.0];
220 CameraCallbackImpl *instantCallback = [[CameraCallbackImpl alloc] init];
221
222 [_locationWindow moveToWithCamera:instantCamera duration:0 animationType:NCAnimationTypeNone callback:instantCallback];
223 NSLog(@"Executed instant move to position (%.2f, %.2f)", instantPoint.x, instantPoint.y);
224 // [objc_LocationWindow_moveTo_4]
225
226 // Test move to with different animation types
227 // [objc_AnimationType_enum]
228 NSArray *animationTypes = @[
229 @(NCAnimationTypeLinear),
230 @(NCAnimationTypeCubic),
231 @(NCAnimationTypeQuint),
232 @(NCAnimationTypeSine),
233 @(NCAnimationTypeNone),
234 ];
235 // [objc_AnimationType_enum]
236
237 for (int i = 0; i < animationTypes.count; i++) {
238 NCAnimationType animationType = [animationTypes[i] integerValue];
239 CameraCallbackImpl *testCallback = [[CameraCallbackImpl alloc] init];
240 [_locationWindow moveToWithCamera:targetCamera duration:1000 animationType:animationType callback:testCallback];
241 NSLog(@"Move to test with animation type %d", (int)animationType);
242 }
243}
244
245- (void)removeCameraListener {
246 // [objc_LocationWindow_removeCameraListener]
247 // Remove camera listener
248 [_locationWindow removeCameraListener:_cameraListener];
249 _cameraListener = nil;
250 NSLog(@"Removed camera listener");
251 // [objc_LocationWindow_removeCameraListener]
252}
253
254- (void)cleanup {
255 if (_cameraListener != nil) {
256 [_locationWindow removeCameraListener:_cameraListener];
257 _cameraListener = nil;
258 }
259 NSLog(@"LocationWindowCamera example cleanup completed");
260}
261
262@end
263
264// Camera listener implementation
265@interface CameraListenerImpl : NSObject <NCCameraListener>
266@end
267
268@implementation CameraListenerImpl
269
270// [objc_CameraListener_onCameraPositionChanged]
271- (void)onCameraPositionChangedWithReason:(NCCameraUpdateReason)reason finished:(BOOL)finished {
272 NSString *reasonString = @"";
273 switch (reason) {
274 case NCCameraUpdateReasonUser:
275 reasonString = @"User";
276 break;
277 case NCCameraUpdateReasonAnimation:
278 reasonString = @"Animation";
279 break;
280 case NCCameraUpdateReasonProgrammatic:
281 reasonString = @"Programmatic";
282 break;
283 }
284 NSLog(@"Camera position changed - Reason: %@, Finished: %@", reasonString, finished ? @"Yes" : @"No");
285}
286// [objc_CameraListener_onCameraPositionChanged]
287
288@end
289
290// Camera callback implementation
291@interface CameraCallbackImpl : NSObject <NCCameraCallback>
292@end
293
294@implementation CameraCallbackImpl
295
296// [objc_CameraCallback_onMoveFinished]
297- (void)onMoveFinishedWithCompleted:(BOOL)completed {
298 NSLog(@"Camera move animation %@", completed ? @"completed" : @"cancelled");
299}
300// [objc_CameraCallback_onMoveFinished]
301
302@end
303
304// Main function
305int main(int argc, const char * argv[]) {
306 @autoreleasepool {
308 [example cleanup];
309 }
310 return 0;
311}