Skip to main content

mln_map/transform/
animation.rs

1//! Animated camera commands: easing and flying to a camera.
2
3use std::f64::consts::PI;
4use std::time::Duration;
5
6use mln_map_types::{
7    AnimationOptions, CameraOptions, TransformState, TransitionOutcome, VerticalPerspectiveProjection,
8};
9use mln_util::geo::{EdgeInsets, LatLngBounds, WrapMode};
10use mln_util::interpolate::interpolate;
11use mln_util::projection::Projection;
12
13use super::transition::{AlongFn, FrameFn};
14use super::{
15    CameraCommandId, Transform, frame_edge_insets, frame_unproject, lat_lng, nanos_from_secs, normalize_angle,
16};
17
18/// An animation frame's padding, `t` of the way from `start` to `end`; `None`
19/// when it has none (see [`frame_edge_insets`]). Insets that don't change are
20/// kept as they are, so that infinite insets don't log on every frame.
21fn interpolate_edge_insets(start: &EdgeInsets, end: &EdgeInsets, t: f64) -> Option<EdgeInsets> {
22    if start == end {
23        return Some(*end);
24    }
25    frame_edge_insets(
26        interpolate(&start.top, &end.top, t),
27        interpolate(&start.left, &end.left, t),
28        interpolate(&start.bottom, &end.bottom, t),
29        interpolate(&start.right, &end.right, t),
30    )
31}
32
33impl Transform {
34    /// Change any combination of center, zoom, bearing, pitch and edgeInsets,
35    /// with a smooth animation between old and new values. Omitted options
36    /// keep their current animations and timing.
37    pub fn ease_to(&mut self, camera: &CameraOptions, animation: &AnimationOptions) -> CameraCommandId {
38        self.command(|transform| transform.ease(camera, animation))
39    }
40
41    pub(super) fn ease(&mut self, input_camera: &CameraOptions, animation: &AnimationOptions) {
42        let mut camera = *input_camera;
43        let globe = self.state.view().is_globe();
44
45        let duration = animation.duration.unwrap_or(Duration::ZERO);
46        if !globe
47            && self.state.limits().bounds == LatLngBounds::default()
48            && !self.is_gesture_in_progress()
49            && duration != Duration::ZERO
50            && animation.easing.is_none()
51        {
52            // A plain timed ease flies without the zoom-out. The flight's
53            // ground speed rises and falls along its path even at a constant
54            // zoom, so an ease given an easing interpolates instead, and
55            // moves as that easing says, as GL JS's easeTo does.
56            self.fly_to(&camera, animation, true);
57            return;
58        }
59
60        let mut zoom = camera.zoom.unwrap_or(self.view().zoom());
61        if camera.zoom.is_none()
62            && let Some(center) = camera.center
63            && globe
64        {
65            zoom += VerticalPerspectiveProjection::zoom_adjustment(
66                self.view().center(WrapMode::Wrapped).latitude(),
67                center.latitude(),
68            );
69        }
70        self.state.constrain_camera_and_zoom_to_bounds(&mut camera, &mut zoom);
71
72        let padding = camera.padding.unwrap_or(self.state.view().padding());
73        let mut start_lat_lng = self.view().center(WrapMode::Unwrapped);
74        let unwrapped_lat_lng = camera.center.unwrap_or(start_lat_lng);
75        // On the globe the ease heads for the center the zoom it was given
76        // allows, or else the zoom it starts from, as GL JS's does; its last
77        // frame is bounded by the zoom it ends on.
78        let lat_lng_end = self.state.constrained_center(
79            &if self.state.limits().bounds == LatLngBounds::default() {
80                unwrapped_lat_lng.wrapped()
81            } else {
82                unwrapped_lat_lng
83            },
84            if camera.zoom.is_some() { zoom } else { self.view().zoom() },
85        );
86
87        let mut bearing = match camera.bearing {
88            Some(b) => mln_math::deg2rad(-b),
89            None => self.view().angle(),
90        };
91        let mut pitch = match camera.pitch {
92            Some(p) => mln_math::deg2rad(p),
93            None => self.view().pitch(),
94        };
95        let mut fov = match camera.fov {
96            Some(f) => mln_math::deg2rad(f),
97            None => self.view().fov(),
98        };
99        let center_alt = camera.center_altitude.unwrap_or(self.state.view().center_altitude());
100        let roll = match camera.roll {
101            Some(r) => mln_math::deg2rad(r),
102            None => self.view().roll(),
103        };
104
105        if zoom.is_nan() || bearing.is_nan() || pitch.is_nan() || roll.is_nan() || fov.is_nan() {
106            self.end_unstarted(animation, TransitionOutcome::Cancelled);
107            return;
108        }
109
110        if self.state.limits().bounds == LatLngBounds::default() {
111            if self.is_gesture_in_progress() {
112                // If gesture in progress, we transfer the wrap rounds from the
113                // end longitude into start, so the "scroll effect" of rounding
114                // the world is the same while assuring the end longitude
115                // remains wrapped.
116                let wrap = unwrapped_lat_lng.longitude() - lat_lng_end.longitude();
117                start_lat_lng = lat_lng(start_lat_lng.latitude(), start_lat_lng.longitude() - wrap);
118            } else {
119                // Find the shortest path otherwise.
120                start_lat_lng.unwrap_for_shortest_path(&lat_lng_end);
121            }
122        }
123        let start_center_alt = self.state.view().center_altitude();
124
125        let start_scale = self.state.view().scale();
126        let start_point = Projection::project(&start_lat_lng, start_scale);
127        let end_point = Projection::project(&lat_lng_end, start_scale);
128
129        // Constrain camera options.
130        // The target is drawn in the projection the style gives at its zoom,
131        // which the animation may cross into.
132        let target_globe = match &self.projection_for_zoom {
133            Some(projection_for_zoom) => projection_for_zoom(zoom).transition_state() > 0.0,
134            None => globe,
135        };
136        zoom = mln_math::clamp_f64(
137            zoom,
138            self.state.min_zoom_at_latitude_with(lat_lng_end.latitude(), target_globe),
139            self.state.limits().max_zoom,
140        );
141        pitch = mln_math::clamp_f64(pitch, self.state.limits().min_pitch, self.state.limits().max_pitch);
142        fov = mln_math::clamp_f64(fov, mln_map_types::MIN_FIELD_OF_VIEW, mln_map_types::MAX_FIELD_OF_VIEW);
143
144        // Minimize rotation by taking the shorter path around the circle.
145        bearing = normalize_angle(bearing, self.state.view().angle());
146
147        let start_zoom = self.state.view().zoom();
148        let start_bearing = normalize_angle(self.state.view().angle(), bearing);
149        let start_pitch = self.state.view().pitch();
150        let start_roll = self.state.view().roll();
151        let start_fov = self.state.view().fov();
152        let start_edge_insets = self.state.view().padding();
153
154        // On the globe the zoom is eased in equator terms so the planet holds
155        // its size as the latitude changes, and the center moves the way GL
156        // JS moves it: longitude paced at 1 / cos(latitude), sped up ahead of
157        // a zoom in.
158        let normalized_start_zoom = if globe {
159            start_zoom + VerticalPerspectiveProjection::zoom_adjustment(start_lat_lng.latitude(), 0.0)
160        } else {
161            start_zoom
162        };
163        let normalized_zoom = if globe {
164            zoom + VerticalPerspectiveProjection::zoom_adjustment(lat_lng_end.latitude(), 0.0)
165        } else {
166            zoom
167        };
168        let final_scale = mln_map_types::zoom_scale(normalized_zoom - normalized_start_zoom);
169        let base = if normalized_zoom > normalized_start_zoom {
170            f64::min(2.0, final_scale)
171        } else {
172            f64::max(0.5, final_scale)
173        };
174        let delta_latitude = if globe {
175            VerticalPerspectiveProjection::difference_of_angles_degrees(
176                start_lat_lng.latitude(),
177                lat_lng_end.latitude(),
178            )
179        } else {
180            0.0
181        };
182        let delta_longitude = if globe {
183            VerticalPerspectiveProjection::difference_of_angles_degrees(
184                start_lat_lng.longitude(),
185                lat_lng_end.longitude(),
186            )
187        } else {
188            0.0
189        };
190        let moves_around_anchor = camera.anchor.is_some() && camera.center.is_none();
191
192        let frame: FrameFn = Box::new(move |state: &TransformState, t: f64| {
193            let (frame_lat_lng, frame_zoom) = if globe {
194                // An anchor moves the center a frame at a time (see
195                // apply_transitions), so it stays, and the zoom follows its
196                // latitude to keep the planet's size.
197                let mut frame_lat_lng =
198                    if moves_around_anchor { state.view().center(WrapMode::Unwrapped) } else { lat_lng_end };
199                let mut frame_zoom = zoom;
200                if moves_around_anchor {
201                    frame_zoom = interpolate(&normalized_start_zoom, &normalized_zoom, t)
202                        + VerticalPerspectiveProjection::zoom_adjustment(0.0, frame_lat_lng.latitude());
203                } else if t < 1.0 {
204                    let factor = t * base.powf(1.0 - t);
205                    frame_lat_lng = VerticalPerspectiveProjection::interpolate_lat_lng(
206                        &start_lat_lng,
207                        delta_latitude,
208                        delta_longitude,
209                        factor,
210                    )
211                    .wrapped();
212                    frame_zoom = if zoom == start_zoom {
213                        start_zoom
214                    } else {
215                        interpolate(&normalized_start_zoom, &normalized_zoom, t)
216                            + VerticalPerspectiveProjection::zoom_adjustment(0.0, frame_lat_lng.latitude())
217                    };
218                }
219                (Some(frame_lat_lng), frame_zoom)
220            } else if t == 1.0 {
221                (Some(lat_lng_end), zoom)
222            } else {
223                let frame_point = interpolate(&start_point, &end_point, t);
224                (frame_unproject(&frame_point, start_scale, WrapMode::Unwrapped), interpolate(&start_zoom, &zoom, t))
225            };
226            CameraOptions {
227                center: frame_lat_lng,
228                zoom: Some(frame_zoom),
229                center_altitude: Some(interpolate(&start_center_alt, &center_alt, t)),
230                bearing: Some(-mln_math::rad2deg(mln_math::wrap(interpolate(&start_bearing, &bearing, t), -PI, PI))),
231                padding: interpolate_edge_insets(&start_edge_insets, &padding, t),
232                pitch: Some(mln_math::rad2deg(interpolate(&start_pitch, &pitch, t))),
233                roll: Some(mln_math::rad2deg(interpolate(&start_roll, &roll, t))),
234                fov: Some(mln_math::rad2deg(interpolate(&start_fov, &fov, t))),
235                ..Default::default()
236            }
237        });
238
239        // On the globe the zoom keeps the planet's size as the center's
240        // latitude changes, and a zoom moves the center when it bounds it
241        // closer to the equator, so an ease that moves the center sets both
242        // (an anchored one gets its center from the anchor).
243        let moves_center = input_camera.center.is_some() || lat_lng_end.wrapped() != start_lat_lng.wrapped();
244        let fields = if globe && moves_around_anchor {
245            CameraOptions { zoom: Some(zoom), ..*input_camera }
246        } else if globe && moves_center {
247            CameraOptions { center: Some(lat_lng_end), zoom: Some(zoom), ..*input_camera }
248        } else {
249            *input_camera
250        };
251        self.start_transition(&fields, animation, frame, None, duration, false);
252    }
253
254    /// This method implements an “optimal path” animation, as detailed in:
255    ///
256    /// Van Wijk, Jarke J.; Nuij, Wim A. A. “Smooth and efficient zooming and
257    /// panning.” INFOVIS ’03. pp. 15–22.
258    /// <https://www.win.tue.nl/~vanwijk/zoompan.pdf#page=5>.
259    ///
260    /// Where applicable, local variable documentation begins with the
261    /// associated variable or function in van Wijk (2003).
262    pub(crate) fn fly_to(
263        &mut self,
264        camera: &CameraOptions,
265        animation: &AnimationOptions,
266        linear_zoom_interpolation: bool,
267    ) -> CameraCommandId {
268        self.command(|transform| transform.fly(camera, animation, linear_zoom_interpolation))
269    }
270
271    pub(super) fn fly(
272        &mut self,
273        input_camera: &CameraOptions,
274        animation: &AnimationOptions,
275        linear_zoom_interpolation: bool,
276    ) {
277        let mut camera = *input_camera;
278        let globe = self.state.view().is_globe();
279
280        let mut zoom = camera.zoom.unwrap_or(self.view().zoom());
281        if camera.zoom.is_none()
282            && let Some(center) = camera.center
283            && globe
284        {
285            zoom += VerticalPerspectiveProjection::zoom_adjustment(
286                self.view().center(WrapMode::Wrapped).latitude(),
287                center.latitude(),
288            );
289        }
290        self.state.constrain_camera_and_zoom_to_bounds(&mut camera, &mut zoom);
291
292        let padding = camera.padding.unwrap_or(self.state.view().padding());
293        // As in easeTo, the globe's flight heads for the center the zoom it
294        // was given, or else starts from, allows.
295        let lat_lng_end = self.state.constrained_center(
296            &camera.center.unwrap_or(self.view().center(WrapMode::Unwrapped)).wrapped(),
297            if camera.zoom.is_some() { zoom } else { self.view().zoom() },
298        );
299        let center_alt = camera.center_altitude.unwrap_or(self.state.view().center_altitude());
300        let mut bearing = match camera.bearing {
301            Some(b) => mln_math::deg2rad(-b),
302            None => self.view().angle(),
303        };
304        let mut pitch = match camera.pitch {
305            Some(p) => mln_math::deg2rad(p),
306            None => self.view().pitch(),
307        };
308        let roll = match camera.roll {
309            Some(r) => mln_math::deg2rad(r),
310            None => self.view().roll(),
311        };
312        let mut fov = match camera.fov {
313            Some(f) => mln_math::deg2rad(f),
314            None => self.view().fov(),
315        };
316
317        if zoom.is_nan()
318            || bearing.is_nan()
319            || pitch.is_nan()
320            || roll.is_nan()
321            || fov.is_nan()
322            || self.state.view().size().is_empty()
323        {
324            self.end_unstarted(animation, TransitionOutcome::Cancelled);
325            return;
326        }
327
328        // Determine endpoints.
329        let mut start_lat_lng = self.view().center(WrapMode::Unwrapped).wrapped();
330        start_lat_lng.unwrap_for_shortest_path(&lat_lng_end);
331        let start_center_alt = self.state.view().center_altitude();
332
333        let start_point = Projection::project(&start_lat_lng, self.state.view().scale());
334        let end_point = Projection::project(&lat_lng_end, self.state.view().scale());
335
336        // Constrain camera options.
337        // The target is drawn in the projection the style gives at its zoom,
338        // which the animation may cross into.
339        let target_globe = match &self.projection_for_zoom {
340            Some(projection_for_zoom) => projection_for_zoom(zoom).transition_state() > 0.0,
341            None => globe,
342        };
343        zoom = mln_math::clamp_f64(
344            zoom,
345            self.state.min_zoom_at_latitude_with(lat_lng_end.latitude(), target_globe),
346            self.state.limits().max_zoom,
347        );
348        pitch = mln_math::clamp_f64(pitch, self.state.limits().min_pitch, self.state.limits().max_pitch);
349        fov = mln_math::clamp_f64(fov, mln_map_types::MIN_FIELD_OF_VIEW, mln_map_types::MAX_FIELD_OF_VIEW);
350
351        // Minimize rotation by taking the shorter path around the circle.
352        bearing = normalize_angle(bearing, self.state.view().angle());
353        let start_zoom = mln_map_types::scale_zoom(self.state.view().scale());
354        let start_bearing = normalize_angle(self.state.view().angle(), bearing);
355        let start_pitch = self.state.view().pitch();
356        let start_roll = self.state.view().roll();
357        let start_fov = self.state.view().fov();
358
359        // w₀: Initial visible span, measured in pixels at the initial scale.
360        // Known henceforth as a <i>screenful</i>.
361        let size = self.state.view().size();
362        let w0 = f64::max(
363            f64::from(size.width) - padding.left - padding.right,
364            f64::from(size.height) - padding.top - padding.bottom,
365        );
366        // The globe counts zoom in equator terms and distance along the
367        // surface, so the arc is the same at any latitude.
368        let normalized_start_zoom = if globe {
369            start_zoom + VerticalPerspectiveProjection::zoom_adjustment(start_lat_lng.latitude(), 0.0)
370        } else {
371            start_zoom
372        };
373        let normalized_zoom = if globe {
374            zoom + VerticalPerspectiveProjection::zoom_adjustment(lat_lng_end.latitude(), 0.0)
375        } else {
376            zoom
377        };
378        // w₁: Final visible span, measured in pixels with respect to the
379        // initial scale.
380        let w1 = w0 / mln_map_types::zoom_scale(normalized_zoom - normalized_start_zoom);
381        // Length of the flight path as projected onto the ground plane,
382        // measured in pixels from the world image origin at the initial scale.
383        let u1 = if globe {
384            VerticalPerspectiveProjection::surface_distance_pixels(
385                Projection::world_size(self.state.view().scale()),
386                start_lat_lng.latitude(),
387                &start_lat_lng,
388                &lat_lng_end,
389            )
390        } else {
391            (end_point.x - start_point.x).hypot(end_point.y - start_point.y)
392        };
393
394        // ρ: The relative amount of zooming that takes place along the flight
395        // path. A high value maximizes zooming for an exaggerated animation,
396        // while a low value minimizes zooming for something closer to
397        // easeTo().
398        //
399        // 1.42 is the average value selected by participants in the user
400        // study in van Wijk (2003). A value of 6<sup>¼</sup> would be
401        // equivalent to the root mean squared average velocity,
402        // V<sub>RMS</sub>. A value of 1 produces a circular motion.
403        let mut rho = 1.42;
404        if globe {
405            // GL JS: the arc may not dip below the map's or the flight's
406            // minimum zoom, and that only ever lowers ρ.
407            let floor_zoom = f64::max(animation.min_zoom.unwrap_or(self.state.min_zoom()), self.state.min_zoom());
408            let normalized_floor_zoom = f64::min(
409                f64::min(
410                    floor_zoom + VerticalPerspectiveProjection::zoom_adjustment(lat_lng_end.latitude(), 0.0),
411                    normalized_start_zoom,
412                ),
413                normalized_zoom,
414            );
415            let min_zoom = mln_math::clamp_f64(
416                normalized_floor_zoom + VerticalPerspectiveProjection::zoom_adjustment(0.0, lat_lng_end.latitude()),
417                self.state.min_zoom_at_latitude(lat_lng_end.latitude()),
418                self.state.limits().max_zoom,
419            );
420            let w_max = w0
421                / mln_map_types::zoom_scale(
422                    min_zoom + VerticalPerspectiveProjection::zoom_adjustment(lat_lng_end.latitude(), 0.0)
423                        - normalized_start_zoom,
424                );
425            if u1 != 0.0 {
426                rho = f64::min(rho, (w_max / u1 * 2.0).sqrt());
427            }
428        } else if animation.min_zoom.is_some() || linear_zoom_interpolation {
429            // util::min(a, b, c) = min(a, min(b, c)), fmin on doubles
430            let mut min_zoom =
431                mln_math::fmin(animation.min_zoom.unwrap_or(start_zoom), mln_math::fmin(start_zoom, zoom));
432            min_zoom = mln_math::clamp_f64(
433                min_zoom,
434                self.state.min_zoom_at_latitude(lat_lng_end.latitude()),
435                self.state.limits().max_zoom,
436            );
437            // w<sub>m</sub>: Maximum visible span, measured in pixels with
438            // respect to the initial scale.
439            let w_max = w0 / mln_map_types::zoom_scale(min_zoom - start_zoom);
440            rho = if u1 == 0.0 { 1.0 } else { (w_max / u1 * 2.0).sqrt() };
441        }
442        // ρ²
443        let rho2 = rho * rho;
444
445        // rᵢ: Returns the zoom-out factor at one end of the animation.
446        //
447        // @param i 0 for the ascent or 1 for the descent.
448        let r = |i: f64| -> f64 {
449            // bᵢ
450            let b = (w1 * w1 - w0 * w0 + if i == 0.0 { 1.0 } else { -1.0 } * rho2 * rho2 * u1 * u1)
451                / (2.0 * if i == 0.0 { w0 } else { w1 } * rho2 * u1);
452            ((b * b + 1.0).sqrt() - b).ln()
453        };
454
455        // r₀: Zoom-out factor during ascent.
456        let r0 = if u1 == 0.0 { f64::INFINITY } else { r(0.0) }; // Silence division by 0 on sanitize bot.
457        let r1 = if u1 == 0.0 { f64::INFINITY } else { r(1.0) };
458
459        // When u₀ = u₁, the optimal path doesn’t require both ascent and
460        // descent.
461        let is_close = u1.abs() < 0.000_001 || !r0.is_finite() || !r1.is_finite();
462
463        // w(s): Returns the visible span on the ground, measured in pixels
464        // with respect to the initial scale.
465        //
466        // Assumes an angular field of view of 2 arctan ½ ≈ 53°.
467        let w = move |s: f64| -> f64 {
468            if is_close {
469                ((if w1 < w0 { -1.0 } else { 1.0 }) * rho * s).exp()
470            } else {
471                r0.cosh() / (r0 + rho * s).cosh()
472            }
473        };
474        // u(s): Returns the distance along the flight path as projected onto
475        // the ground plane, measured in pixels from the world image origin at
476        // the initial scale.
477        let u = move |s: f64| -> f64 {
478            if is_close { 0.0 } else { w0 * (r0.cosh() * (r0 + rho * s).tanh() - r0.sinh()) / rho2 / u1 }
479        };
480        // S: Total length of the flight path, measured in ρ-screenfuls.
481        let total_s = if is_close { (w1 / w0).ln().abs() / rho } else { (r1 - r0) / rho };
482        // Where the center stays, the share of the time stands in.
483        let along: Option<AlongFn> = if is_close { None } else { Some(Box::new(move |k| u(k * total_s))) };
484
485        let duration = if let Some(duration) = animation.duration {
486            duration
487        } else {
488            // V: Average velocity, measured in ρ-screenfuls per second.
489            let mut velocity = 1.2;
490            if let Some(v) = animation.velocity {
491                velocity = v / rho;
492            }
493            // A duration that a `Duration` can't hold jumps, as one past
494            // max_duration does, rather than saturating to a flight that
495            // never ends.
496            nanos_from_secs(total_s / velocity).unwrap_or_default()
497        };
498        let duration = match animation.max_duration {
499            Some(max) if !linear_zoom_interpolation && duration > max => Duration::ZERO,
500            _ => duration,
501        };
502        let start_scale = self.state.view().scale();
503        let start_edge_insets = self.state.view().padding();
504        let delta_latitude = if globe {
505            VerticalPerspectiveProjection::difference_of_angles_degrees(
506                start_lat_lng.latitude(),
507                lat_lng_end.latitude(),
508            )
509        } else {
510            0.0
511        };
512        let delta_longitude = if globe {
513            VerticalPerspectiveProjection::difference_of_angles_degrees(
514                start_lat_lng.longitude(),
515                lat_lng_end.longitude(),
516            )
517        } else {
518            0.0
519        };
520
521        let frame: FrameFn = Box::new(move |_: &TransformState, k: f64| {
522            // s: The distance traveled along the flight path, measured in
523            // ρ-screenfuls.
524            let s = k * total_s;
525            let us = if k == 1.0 { 1.0 } else { u(s) };
526
527            let (frame_lat_lng, frame_zoom) = if globe {
528                let mut frame_lat_lng = lat_lng_end;
529                let mut frame_zoom = zoom;
530                if k < 1.0 {
531                    frame_lat_lng = VerticalPerspectiveProjection::interpolate_lat_lng(
532                        &start_lat_lng,
533                        delta_latitude,
534                        delta_longitude,
535                        us,
536                    )
537                    .wrapped();
538                    let frame_normalized_zoom = if linear_zoom_interpolation {
539                        interpolate(&normalized_start_zoom, &normalized_zoom, k)
540                    } else {
541                        normalized_start_zoom + mln_map_types::scale_zoom(1.0 / w(s))
542                    };
543                    frame_zoom = frame_normalized_zoom
544                        + VerticalPerspectiveProjection::zoom_adjustment(0.0, frame_lat_lng.latitude());
545                    if frame_zoom.is_nan() {
546                        frame_zoom = zoom;
547                    }
548                }
549                (Some(frame_lat_lng), frame_zoom)
550            } else {
551                // Calculate the current point and zoom level along the flight
552                // path.
553                let frame_point = interpolate(&start_point, &end_point, us);
554                let mut frame_zoom = if linear_zoom_interpolation {
555                    interpolate(&start_zoom, &zoom, k)
556                } else {
557                    start_zoom + mln_map_types::scale_zoom(1.0 / w(s))
558                };
559
560                // Zoom can be NaN if size is empty.
561                if frame_zoom.is_nan() {
562                    frame_zoom = zoom;
563                }
564
565                // Convert to geographic coordinates and set the new viewpoint.
566                (frame_unproject(&frame_point, start_scale, WrapMode::Unwrapped), frame_zoom)
567            };
568            CameraOptions {
569                center: frame_lat_lng,
570                zoom: Some(frame_zoom),
571                center_altitude: Some(interpolate(&start_center_alt, &center_alt, us)),
572                bearing: Some(-mln_math::rad2deg(mln_math::wrap(interpolate(&start_bearing, &bearing, k), -PI, PI))),
573                padding: interpolate_edge_insets(&start_edge_insets, &padding, k),
574                pitch: Some(mln_math::rad2deg(interpolate(&start_pitch, &pitch, k))),
575                roll: Some(mln_math::rad2deg(interpolate(&start_roll, &roll, k))),
576                fov: Some(mln_math::rad2deg(interpolate(&start_fov, &fov, k))),
577                ..Default::default()
578            }
579        });
580
581        self.start_transition(input_camera, animation, frame, along, duration, !linear_zoom_interpolation);
582    }
583}