Skip to content

Commit

Permalink
[ios] MapLibre logo with MLNMapSnapshotter (maplibre#2541)
Browse files Browse the repository at this point in the history
  • Loading branch information
louwers authored Jun 22, 2024
1 parent 7f1b76c commit ab25157
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 59 deletions.
35 changes: 18 additions & 17 deletions platform/darwin/src/MLNMapCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ NS_ASSUME_NONNULL_BEGIN

/**
An `MLNMapCamera` object represents a viewpoint from which the user observes
some point on an `MLNMapView`.
some point on an ``MLNMapView``.
#### Related examples
TODO: Camera animation, learn how to create a camera that rotates
- <doc:BlockingGesturesExample>: learn how to use the
``MLNMapViewDelegate/mapView:shouldChangeFromCamera:toCamera:`` method of ``MLNMapViewDelegate`` to
restrict panning.
- *TODO:* Camera animation, learn how to create a camera that rotates
around a central point.
TODO: Restrict map panning to an area, learn how to restrict map
panning using `MLNMapViewDelegate`'s `-mapView:shouldChangeFromCamera:toCamera:` method.
*/
MLN_EXPORT
@interface MLNMapCamera : NSObject <NSSecureCoding, NSCopying>
Expand All @@ -38,17 +39,17 @@ MLN_EXPORT
The altitude is the distance from the viewpoint to the map, perpendicular to
the map plane. This property does not account for physical elevation.
This property’s value may be less than that of the `viewingDistance` property.
Setting this property automatically updates the `viewingDistance` property
based on the `pitch` property’s current value.
This property’s value may be less than that of the ``viewingDistance`` property.
Setting this property automatically updates the ``viewingDistance`` property
based on the ``pitch`` property’s current value.
*/
@property (nonatomic) CLLocationDistance altitude;

/**
The straight-line distance from the viewpoint to the `centerCoordinate`.
The straight-line distance from the viewpoint to the ``centerCoordinate``.
Setting this property automatically updates the `altitude` property based on
the `pitch` property’s current value.
Setting this property automatically updates the ``altitude`` property based on
the ``pitch`` property’s current value.
*/
@property (nonatomic) CLLocationDistance viewingDistance;

Expand Down Expand Up @@ -76,12 +77,12 @@ MLN_EXPORT
This method interprets the distance as a straight-line distance from the
viewpoint to the center coordinate. To specify the altitude of the viewpoint,
use the `-cameraLookingAtCenterCoordinate:altitude:pitch:heading:` method.
use the ``cameraLookingAtCenterCoordinate:altitude:pitch:heading:`` method.
@param centerCoordinate The geographic coordinate on which the map should be
centered.
@param distance The straight-line distance from the viewpoint to the
`centerCoordinate`.
``centerCoordinate``.
@param pitch The viewing angle of the camera, measured in degrees. A value of
`0` results in a camera pointed straight down at the map. Angles greater
than `0` result in a camera angled toward the horizon.
Expand Down Expand Up @@ -117,11 +118,11 @@ MLN_EXPORT
heading:(CLLocationDirection)heading;

/**
@note This initializer incorrectly interprets the `distance` parameter. To
specify the straight-line distance from the viewpoint to `centerCoordinate`,
use the `-cameraLookingAtCenterCoordinate:acrossDistance:pitch:heading:`
> This initializer incorrectly interprets the `distance` parameter. To
specify the straight-line distance from the viewpoint to ``centerCoordinate``,
use the ``cameraLookingAtCenterCoordinate:acrossDistance:pitch:heading:``
method. To specify the altitude of the viewpoint, use the
`-cameraLookingAtCenterCoordinate:altitude:pitch:heading:` method, which has
``cameraLookingAtCenterCoordinate:altitude:pitch:heading:`` method, which has
the same behavior as this initializer.
*/
+ (instancetype)cameraLookingAtCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate
Expand All @@ -135,7 +136,7 @@ MLN_EXPORT
Returns a Boolean value indicating whether the given camera is functionally
equivalent to the receiver.
Unlike `-isEqual:`, this method returns `YES` if the difference between the
Unlike `isEqual:`, this method returns `YES` if the difference between the
coordinates, altitudes, pitches, or headings of the two camera objects is
negligible.
Expand Down
47 changes: 20 additions & 27 deletions platform/darwin/src/MLNMapSnapshotter.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ NS_ASSUME_NONNULL_BEGIN
@protocol MLNMapSnapshotterDelegate;

/**
An overlay that is placed within a `MLNMapSnapshot`.
To access this object, use `-[MLNMapSnapshotter startWithOverlayHandler:completionHandler:]`.
An overlay that is placed within a ``MLNMapSnapshot``.
To access this object, use ``MLNMapSnapshotter/startWithOverlayHandler:completionHandler:``.
*/

MLN_EXPORT
Expand Down Expand Up @@ -53,12 +53,12 @@ MLN_EXPORT
A block provided during the snapshot drawing process, enabling the ability to
draw custom overlays rendered with Core Graphics.
@param snapshotOverlay The `MLNMapSnapshotOverlay` provided during snapshot drawing.
@param snapshotOverlay The ``MLNMapSnapshotOverlay`` provided during snapshot drawing.
*/
typedef void (^MLNMapSnapshotOverlayHandler)(MLNMapSnapshotOverlay *snapshotOverlay);

/**
The options to use when creating images with the `MLNMapSnapshotter`.
The options to use when creating images with the ``MLNMapSnapshotter``.
*/
MLN_EXPORT
@interface MLNMapSnapshotOptions : NSObject <NSCopying>
Expand Down Expand Up @@ -94,9 +94,9 @@ MLN_EXPORT
/**
A camera representing the viewport visible in the snapshot.
If this property is non-nil and the `coordinateBounds` property is set to a
If this property is non-nil and the ``coordinateBounds`` property is set to a
non-empty coordinate bounds, the camera’s center coordinate and altitude are
ignored in favor of the `coordinateBounds` property.
ignored in favor of the ``coordinateBounds`` property.
*/
@property (nonatomic) MLNMapCamera *camera;

Expand Down Expand Up @@ -170,18 +170,18 @@ MLN_EXPORT
/**
A block to processes the result or error of a snapshot request.
@param snapshot The `MLNMapSnapshot` that was generated or `nil` if an error
@param snapshot The ``MLNMapSnapshot`` that was generated or `nil` if an error
occurred.
@param error The error that occured or `nil` when successful.
*/
typedef void (^MLNMapSnapshotCompletionHandler)(MLNMapSnapshot *_Nullable snapshot,
NSError *_Nullable error);

/**
An `MLNMapSnapshotter` generates static raster images of the map. Each snapshot
image depicts a portion of a map defined by an `MLNMapSnapshotOptions` object
you provide. The snapshotter generates an `MLNMapSnapshot` object
asynchronously, calling `MLNMapSnapshotterDelegate` methods if defined, then
An ``MLNMapSnapshotter`` generates static raster images of the map. Each snapshot
image depicts a portion of a map defined by an ``MLNMapSnapshotOptions`` object
you provide. The snapshotter generates an ``MLNMapSnapshot`` object
asynchronously, calling ``MLNMapSnapshotterDelegate`` methods if defined, then
passing it into a completion handler once tiles and other resources needed for
the snapshot are finished loading.
Expand All @@ -190,9 +190,9 @@ typedef void (^MLNMapSnapshotCompletionHandler)(MLNMapSnapshot *_Nullable snapsh
snapshot at a time. If you need to generate multiple snapshots concurrently,
create multiple snapshotter objects.
For an interactive map, use the `MLNMapView` class. Both `MLNMapSnapshotter`
and `MLNMapView` are compatible with offline packs managed by the
`MLNOfflineStorage` class.
For an interactive map, use the ``MLNMapView`` class. Both ``MLNMapSnapshotter``
and ``MLNMapView`` are compatible with offline packs managed by the
``MLNOfflineStorage`` class.
From a snapshot, you can obtain an image and convert geographic coordinates to
the image’s coordinate space in order to superimpose markers and overlays. If
Expand Down Expand Up @@ -277,7 +277,7 @@ MLN_EXPORT
Cancels the snapshot creation request, if any.
Once you call this method, you cannot resume the snapshot. In order to obtain
the snapshot, create a new `MLNMapSnapshotter` object.
the snapshot, create a new ``MLNMapSnapshotter`` object.
*/
- (void)cancel;

Expand Down Expand Up @@ -308,29 +308,22 @@ MLN_EXPORT
/**
The style displayed in the resulting snapshot.
Unlike the `MLNMapSnapshotOptions.styleURL` property, this property is set to
Unlike the ``MLNMapSnapshotOptions/styleURL`` property, this property is set to
an object that allows you to manipulate every aspect of the style locally.
This property is set to `nil` until the style finishes loading. If the style
has failed to load, this property is set to `nil`. Because the style loads
asynchronously, you should manipulate it in the
`-[MLNMapSnapshotterDelegate mapSnapshotter:didFinishLoadingStyle:]` method. It
``MLNMapSnapshotterDelegate/mapSnapshotter:didFinishLoadingStyle:`` method. It
is not possible to manipulate the style before it has finished loading.
@note The default styles provided by Mapbox contain sources and layers with
identifiers that will change over time. Applications that use APIs that
manipulate a style’s sources and layers must first set the style URL to an
explicitly versioned style using a convenience method like
`+[MLNStyle outdoorsStyleURLWithVersion:]` or a manually constructed
`NSURL`.
*/
@property (nonatomic, readonly, nullable) MLNStyle *style;

@end

/**
Optional methods about significant events when creating a snapshot using an
`MLNMapSnapshotter` object.
``MLNMapSnapshotter`` object.
*/
@protocol MLNMapSnapshotterDelegate <NSObject>
@optional
Expand All @@ -352,8 +345,8 @@ MLN_EXPORT
Tells the delegate that the snapshotter has just finished loading a style.
This method is called in response to
`-[MLNMapSnapshotter startWithQueue:completionHandler:]` as long as the
`MLNMapSnapshotter.delegate` property is set. Changes to sources or layers of
``MLNMapSnapshotter/startWithQueue:completionHandler:`` as long as the
``MLNMapSnapshotter/delegate`` property is set. Changes to sources or layers of
the style being snapshotted do not cause this method to be called.
@param snapshotter The snapshotter that has just loaded a style.
Expand Down
20 changes: 7 additions & 13 deletions platform/darwin/src/MLNMapSnapshotter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,7 @@ @interface MLNMapSnapshotOptions ()

/**
:nodoc:
Whether the Mapbox wordmark is displayed.
@note The Mapbox terms of service, which governs the use of Mapbox-hosted
vector tiles and styles,
<a href="https://docs.mapbox.com/help/how-mapbox-works/attribution/">requires</a> most Mapbox
customers to display the Mapbox wordmark. If this applies to you, do not
hide the wordmark or change its contents.
Whether to include the MapLibre logo. Note this is not required.
*/
@property (nonatomic, readwrite) BOOL showsLogo;
@end
Expand Down Expand Up @@ -388,7 +382,7 @@ - (void)startWithQueue:(dispatch_queue_t)queue overlayHandler:(MLNMapSnapshotOve
CGPoint attributionOrigin = CGPointMake(mglImage.size.width - 10 - attributionBackgroundSize.width,
logoImageRect.origin.y + (logoImageRect.size.height / 2) - (attributionBackgroundSize.height / 2) + 1);
if (!logoImage) {
CGSize defaultLogoSize = [MLNMapSnapshotter mapboxLongStyleLogo].size;
CGSize defaultLogoSize = [MLNMapSnapshotter maplibreLongStyleLogo].size;
logoImageRect = CGRectMake(0, mglImage.size.height - (MLNLogoImagePosition.y + defaultLogoSize.height), 0, defaultLogoSize.height);
attributionOrigin = CGPointMake(10, logoImageRect.origin.y + (logoImageRect.size.height / 2) - (attributionBackgroundSize.height / 2) + 1);
}
Expand Down Expand Up @@ -461,7 +455,7 @@ - (void)startWithQueue:(dispatch_queue_t)queue overlayHandler:(MLNMapSnapshotOve
CGPoint attributionOrigin = CGPointMake(targetFrame.size.width - 10 - attributionBackgroundSize.width,
MLNLogoImagePosition.y + 1);
if (!logoImage) {
CGSize defaultLogoSize = [MLNMapSnapshotter mapboxLongStyleLogo].size;
CGSize defaultLogoSize = [MLNMapSnapshotter maplibreLongStyleLogo].size;
logoImageRect = CGRectMake(0, MLNLogoImagePosition.y, 0, defaultLogoSize.height);
attributionOrigin = CGPointMake(10, attributionOrigin.y);
}
Expand Down Expand Up @@ -630,11 +624,11 @@ + (MLNImage *)logoImageWithStyle:(MLNAttributionInfoStyle)style
MLNImage *logoImage;
switch (style) {
case MLNAttributionInfoStyleLong:
logoImage = [MLNMapSnapshotter mapboxLongStyleLogo];
logoImage = [MLNMapSnapshotter maplibreLongStyleLogo];
break;
case MLNAttributionInfoStyleMedium:
#if TARGET_OS_IPHONE
logoImage = [UIImage imageNamed:@"mapbox_helmet" inBundle:[NSBundle mgl_frameworkBundle] compatibleWithTraitCollection:nil];
logoImage = [UIImage imageNamed:@"maplibre-logo-icon" inBundle:[NSBundle mgl_frameworkBundle] compatibleWithTraitCollection:nil];
#else
logoImage = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mgl_frameworkBundle] pathForResource:@"mapbox_helmet" ofType:@"pdf"]];
#endif
Expand All @@ -646,11 +640,11 @@ + (MLNImage *)logoImageWithStyle:(MLNAttributionInfoStyle)style
return logoImage;
}

+ (MLNImage *)mapboxLongStyleLogo
+ (MLNImage *)maplibreLongStyleLogo
{
MLNImage *logoImage;
#if TARGET_OS_IPHONE
logoImage =[UIImage imageNamed:@"mapbox" inBundle:[NSBundle mgl_frameworkBundle] compatibleWithTraitCollection:nil];
logoImage =[UIImage imageNamed:@"maplibre-logo-stroke-gray" inBundle:[NSBundle mgl_frameworkBundle] compatibleWithTraitCollection:nil];
#else
logoImage = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mgl_frameworkBundle] pathForResource:@"mapbox" ofType:@"pdf"]];
#endif
Expand Down
4 changes: 2 additions & 2 deletions platform/darwin/src/MLNSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ MLN_EXPORT
// MARK: Authorizing Access

/**
The API Key used by all instances of `MLNMapView` in the current application.
The API Key used by all instances of ``MLNMapView`` in the current application.
Setting this property to a value of `nil` has no effect.
@note You must set the API key before attempting to load any style which
requires the token. Therefore, you should generally set it before creating an instance of
`MLNMapView`. The recommended way to set an api key is to add an entry
``MLNMapView``. The recommended way to set an api key is to add an entry
to your application’s Info.plist file with the key `MLNApiKey`
and the type `String`. Alternatively, you may call this method from your
application delegate’s `-applicationDidFinishLaunching:` method.
Expand Down
1 change: 1 addition & 0 deletions platform/ios/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ filegroup(
name = "extra_files",
srcs = [
"BAZEL.md",
"CHANGELOG.md",
"MapLibre.podspec",
"PrivacyInfo.xcprivacy",
"README.md",
Expand Down
1 change: 1 addition & 0 deletions platform/ios/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ MapLibre welcomes participation and contributions from everyone. Please read [`C
## main

- Add [Privacy Manifest](https://developer.apple.com/documentation/bundleresources/privacy_manifest_files). MapLibre Native iOS has no built-in tracking, but it does use some system APIs for functional purposes that are marked by Apple as privacy sensitive. ([#1866](https://github.com/maplibre/maplibre-native/issues/1866)).
- Change default `MLNMapSnapshotter` logo to the MapLibre logo ([#2541](https://github.com/maplibre/maplibre-native/pull/2541)). Note that showing the MapLibre logo is never required. Check with your tile provider if you need to show a logo.

## 6.5.0

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "maplibre-logo-icon.svg",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading

0 comments on commit ab25157

Please sign in to comment.