1#import <Foundation/Foundation.h>
2#import <NavigineSDK/NavigineSDK.h>
20@implementation LocationWindowCameraExample
31 NSLog(
@"=== LocationWindowCamera Example ===");
34 [
self getCurrentCamera];
35 [
self setCameraPosition];
36 [
self addCameraListener];
38 [
self moveToWithAnimation];
39 [
self removeCameraListener];
45 _locationWindow.zoomFactor = 100.0f;
46 NSLog(
@"Set zoom factor to 100.0 pixels per meter");
51 _locationWindow.minZoomFactor = 10.0f;
52 NSLog(
@"Set minimum zoom factor to 10.0 pixels per meter");
57 _locationWindow.maxZoomFactor = 1000.0f;
58 NSLog(
@"Set maximum zoom factor to 1000.0 pixels per meter");
62- (void)getCurrentCamera {
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);
73- (void)setCameraPosition {
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);
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);
91 _locationWindow.camera = newCamera;
92 NSLog(
@"Set camera position to (%.2f, %.2f) with zoom 50.0 and rotation 0°", newPoint.x, newPoint.y);
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);
104 NSArray *testCameras = @[
105 [[NCCamera alloc] initWithPoint:[[NCPoint alloc] initWithX:0.0 y:0.0] zoom:10.0 rotation:0.0],
106 [[NCCamera alloc] initWithPoint:[[NCPoint alloc] initWithX:50.0 y:75.0] zoom:500.0 rotation:0.0],
107 [[NCCamera alloc] initWithPoint:[[NCPoint alloc] initWithX:100.0 y:150.0] zoom:100.0 rotation:30.0],
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);
117- (void)addCameraListener {
121 [_locationWindow addCameraListener:_cameraListener];
122 NSLog(
@"Added camera listener");
126 NSArray *listeners = @[
132 for (
int i = 0; i < listeners.count; i++) {
133 [_locationWindow addCameraListener:listeners[i]];
134 NSLog(
@"Added camera listener %d", i);
137 for (
int i = 0; i < listeners.count; i++) {
138 [_locationWindow removeCameraListener:listeners[i]];
139 NSLog(
@"Removed camera listener %d", i);
143- (void)flyToPosition {
146 NCPoint *targetPoint = [[NCPoint alloc] initWithX:150.0 y:250.0];
147 NCCamera *targetCamera = [[NCCamera alloc] initWithPoint:targetPoint zoom:75.0 rotation:45.0];
150 [_locationWindow flyToWithCamera:targetCamera duration:2000 callback:callback];
151 NSLog(
@"Started fly to animation to point (%.2f, %.2f)", targetPoint.x, targetPoint.y);
156 NCPoint *targetPoint2 = [[NCPoint alloc] initWithX:300.0 y:400.0];
157 NCCamera *targetCamera2 = [[NCCamera alloc] initWithPoint:targetPoint2 zoom:25.0 rotation:180.0];
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);
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},
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];
178 NCCamera *camera = [[NCCamera alloc] initWithPoint:point zoom:zoom rotation:rotation];
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);
185- (void)moveToWithAnimation {
188 NCPoint *targetPoint = [[NCPoint alloc] initWithX:200.0 y:300.0];
189 NCCamera *targetCamera = [[NCCamera alloc] initWithPoint:targetPoint zoom:100.0 rotation:90.0];
192 [_locationWindow moveToWithCamera:targetCamera duration:1500 animationType:NCAnimationTypeLinear callback:callback];
193 NSLog(
@"Started move to with linear animation");
199 [_locationWindow moveToWithCamera:targetCamera duration:1500 animationType:NCAnimationTypeCubic callback:callback2];
200 NSLog(
@"Started move to with cubic animation");
206 [_locationWindow moveToWithCamera:targetCamera duration:1500 animationType:NCAnimationTypeSine callback:callback3];
207 NSLog(
@"Started move to with sine 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];
216 [_locationWindow moveToWithCamera:instantCamera duration:0 animationType:NCAnimationTypeNone callback:instantCallback];
217 NSLog(
@"Executed instant move to position (%.2f, %.2f)", instantPoint.x, instantPoint.y);
221 NSArray *animationTypes = @[
222 @(NCAnimationTypeLinear),
223 @(NCAnimationTypeCubic),
224 @(NCAnimationTypeQuint),
225 @(NCAnimationTypeSine),
226 @(NCAnimationTypeNone),
229 for (
int i = 0; i < animationTypes.count; i++) {
230 NCAnimationType animationType = [animationTypes[i] integerValue];
232 [_locationWindow moveToWithCamera:targetCamera duration:1000 animationType:animationType callback:testCallback];
233 NSLog(
@"Move to test with animation type %d", (
int)animationType);
237- (void)removeCameraListener {
240 [_locationWindow removeCameraListener:_cameraListener];
241 _cameraListener = nil;
242 NSLog(
@"Removed camera listener");
247 if (_cameraListener != nil) {
248 [_locationWindow removeCameraListener:_cameraListener];
249 _cameraListener = nil;
251 NSLog(
@"LocationWindowCamera example cleanup completed");
257@interface CameraListenerImpl : NSObject <NCCameraListener>
260@implementation CameraListenerImpl
263- (void)onCameraPositionChangedWithReason:(NCCameraUpdateReason)reason finished:(BOOL)finished {
264 NSString *reasonString =
@"";
266 case NCCameraUpdateReasonUser:
267 reasonString =
@"User";
269 case NCCameraUpdateReasonAnimation:
270 reasonString =
@"Animation";
272 case NCCameraUpdateReasonProgrammatic:
273 reasonString =
@"Programmatic";
276 NSLog(
@"Camera position changed - Reason: %@, Finished: %@", reasonString, finished ?
@"Yes" :
@"No");
283@interface CameraCallbackImpl : NSObject <NCCameraCallback>
286@implementation CameraCallbackImpl
288- (void)onMoveFinishedWithCompleted:(BOOL)completed {
289 NSLog(
@"Camera move animation %@", completed ?
@"completed" :
@"cancelled");
295int main(
int argc,
const char * argv[]) {