This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Camera API #2193
Merged
Merged
Camera API #2193
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#import "Mapbox.h" | ||
|
||
#pragma once | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
/** An `MGLMapCamera` object represents a viewpoint from which the user observes some point on an `MGLMapView`. */ | ||
@interface MGLMapCamera : NSObject <NSSecureCoding, NSCopying> | ||
|
||
/** Coordinate at the center of the map view. */ | ||
@property (nonatomic) CLLocationCoordinate2D centerCoordinate; | ||
|
||
/** Heading measured in degrees clockwise from true north. */ | ||
@property (nonatomic) CLLocationDirection heading; | ||
|
||
/** Pitch toward the horizon measured in degrees, with 0 degrees resulting in a two-dimensional map. */ | ||
@property (nonatomic) CGFloat pitch; | ||
|
||
/** Meters above ground level. */ | ||
@property (nonatomic) CLLocationDistance altitude; | ||
|
||
/** Returns a new camera with all properties set to 0. */ | ||
+ (instancetype)camera; | ||
|
||
+ (instancetype)cameraLookingAtCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate | ||
fromEyeCoordinate:(CLLocationCoordinate2D)eyeCoordinate | ||
eyeAltitude:(CLLocationDistance)eyeAltitude; | ||
|
||
+ (instancetype)cameraLookingAtCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate | ||
fromDistance:(CLLocationDistance)distance | ||
pitch:(CGFloat)pitch | ||
heading:(CLLocationDirection)heading; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef MBGL_MAP_CAMERA | ||
#define MBGL_MAP_CAMERA | ||
|
||
#include <mbgl/util/geo.hpp> | ||
#include <mbgl/util/optional.hpp> | ||
#include <mbgl/util/chrono.hpp> | ||
#include <mbgl/util/unitbezier.hpp> | ||
|
||
namespace mbgl { | ||
|
||
struct CameraOptions { | ||
mapbox::util::optional<LatLng> center; | ||
mapbox::util::optional<double> zoom; | ||
mapbox::util::optional<double> angle; | ||
mapbox::util::optional<double> pitch; | ||
mapbox::util::optional<Duration> duration; | ||
mapbox::util::optional<mbgl::util::UnitBezier> easing; | ||
}; | ||
|
||
} | ||
|
||
#endif /* MBGL_MAP_CAMERA */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#import "MGLMapCamera.h" | ||
|
||
#include <mbgl/util/projection.hpp> | ||
|
||
@implementation MGLMapCamera | ||
|
||
+ (BOOL)supportsSecureCoding | ||
{ | ||
return YES; | ||
} | ||
|
||
+ (instancetype)camera | ||
{ | ||
return [[self alloc] init]; | ||
} | ||
|
||
+ (instancetype)cameraLookingAtCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate | ||
fromEyeCoordinate:(CLLocationCoordinate2D)eyeCoordinate | ||
eyeAltitude:(CLLocationDistance)eyeAltitude | ||
{ | ||
mbgl::LatLng centerLatLng = mbgl::LatLng(centerCoordinate.latitude, centerCoordinate.longitude); | ||
mbgl::LatLng eyeLatLng = mbgl::LatLng(eyeCoordinate.latitude, eyeCoordinate.longitude); | ||
|
||
mbgl::ProjectedMeters centerMeters = mbgl::Projection::projectedMetersForLatLng(centerLatLng); | ||
mbgl::ProjectedMeters eyeMeters = mbgl::Projection::projectedMetersForLatLng(eyeLatLng); | ||
CLLocationDirection heading = std::atan((centerMeters.northing - eyeMeters.northing) / | ||
(centerMeters.easting - eyeMeters.easting)); | ||
|
||
double groundDistance = std::hypot(centerMeters.northing - eyeMeters.northing, | ||
centerMeters.easting - eyeMeters.easting); | ||
CGFloat pitch = std::atan(eyeAltitude / groundDistance); | ||
|
||
return [[self alloc] initWithCenterCoordinate:centerCoordinate | ||
altitude:eyeAltitude | ||
pitch:pitch | ||
heading:heading]; | ||
} | ||
|
||
+ (instancetype)cameraLookingAtCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate | ||
fromDistance:(CLLocationDistance)distance | ||
pitch:(CGFloat)pitch | ||
heading:(CLLocationDirection)heading | ||
{ | ||
return [[self alloc] initWithCenterCoordinate:centerCoordinate | ||
altitude:distance | ||
pitch:(CGFloat)pitch | ||
heading:heading]; | ||
} | ||
|
||
- (instancetype)initWithCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate | ||
altitude:(CLLocationDistance)altitude | ||
pitch:(CGFloat)pitch | ||
heading:(CLLocationDirection)heading | ||
{ | ||
if (self = [super init]) | ||
{ | ||
_centerCoordinate = centerCoordinate; | ||
_altitude = altitude; | ||
_pitch = pitch; | ||
_heading = heading; | ||
} | ||
return self; | ||
} | ||
|
||
- (nullable instancetype)initWithCoder:(NSCoder *)coder | ||
{ | ||
if (self = [super init]) | ||
{ | ||
_centerCoordinate = CLLocationCoordinate2DMake([coder decodeDoubleForKey:@"centerLatitude"], | ||
[coder decodeDoubleForKey:@"centerLongitude"]); | ||
_altitude = [coder decodeDoubleForKey:@"altitude"]; | ||
_pitch = [coder decodeDoubleForKey:@"pitch"]; | ||
_heading = [coder decodeDoubleForKey:@"heading"]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)encodeWithCoder:(NSCoder *)coder | ||
{ | ||
[coder encodeDouble:_centerCoordinate.latitude forKey:@"centerLatitude"]; | ||
[coder encodeDouble:_centerCoordinate.longitude forKey:@"centerLongitude"]; | ||
[coder encodeDouble:_altitude forKey:@"altitude"]; | ||
[coder encodeDouble:_pitch forKey:@"pitch"]; | ||
[coder encodeDouble:_heading forKey:@"heading"]; | ||
} | ||
|
||
- (id)copyWithZone:(nullable NSZone *)zone | ||
{ | ||
return [[[self class] allocWithZone:zone] initWithCenterCoordinate:_centerCoordinate | ||
altitude:_altitude | ||
pitch:_pitch | ||
heading:_heading]; | ||
} | ||
|
||
- (NSString *)description | ||
{ | ||
return [NSString stringWithFormat:@"<MKMapCamera %p centerCoordinate:%f, %f altitude:%.0fm heading:%.0f° pitch:%.0f°>", | ||
self, _centerCoordinate.latitude, _centerCoordinate.longitude, _altitude, _heading, _pitch]; | ||
} | ||
|
||
@end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious @1ec5 why this is required, for an iOS header which should be brought in with the once-safe
#import
vs.#include
anyway.