-
Notifications
You must be signed in to change notification settings - Fork 1.3k
allow for user-provided symbol imagery (aka Sprites) #941
Changes from all commits
7f705da
9991f9d
55ef14f
a68b47b
a96a8fe
04d57b8
54aaa43
33a3388
d880507
086e72a
aa2dcf1
d2ee014
afaf74e
4f48874
bc41d3c
6271f8e
a0e391c
70d0a26
f9601ae
b2a3314
62ac43a
746e4d2
c5ed00a
a57f3dd
d08ec53
3269933
d37bd54
0d4cfd5
74b744a
493c72b
c66ec87
1f4b5e7
5ab58de
5f9e675
e3b823b
e0da13d
445d3af
e0384a9
a1c2529
c701134
fb230dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#ifndef MBGL_ANNOTATIONS_SPRITE_IMAGE | ||
#define MBGL_ANNOTATIONS_SPRITE_IMAGE | ||
|
||
#include <mbgl/util/noncopyable.hpp> | ||
#include <mbgl/util/geo.hpp> | ||
|
||
#include <string> | ||
#include <memory> | ||
#include <cstdint> | ||
|
||
namespace mbgl { | ||
|
||
class SpriteImage : private util::noncopyable { | ||
public: | ||
SpriteImage( | ||
uint16_t width, uint16_t height, float pixelRatio, std::string&& data, bool sdf = false); | ||
|
||
// Logical dimensions of the sprite image. | ||
const uint16_t width; | ||
const uint16_t height; | ||
|
||
// Pixel ratio of the sprite image. | ||
const float pixelRatio; | ||
|
||
// Physical dimensions of the sprite image. | ||
const uint16_t pixelWidth; | ||
const uint16_t pixelHeight; | ||
|
||
// A string of an RGBA8 representation of the sprite. It must have exactly | ||
// (width * ratio) * (height * ratio) * 4 (RGBA) bytes. The scan lines may | ||
// not have gaps between them (i.e. stride == 0). | ||
const std::string data; | ||
|
||
// Whether this image should be interpreted as a signed distance field icon. | ||
const bool sdf; | ||
}; | ||
|
||
} | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#import <UIKit/UIKit.h> | ||
|
||
#import "MGLTypes.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface MGLAnnotationImage : NSObject | ||
|
||
@property (nonatomic, readonly) UIImage *image; | ||
@property (nonatomic, readonly) NSString *reuseIdentifier; | ||
|
||
+ (instancetype)annotationImageWithImage:(UIImage *)image reuseIdentifier:(NSString *)reuseIdentifier; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@class MGLAnnotationImage; | ||
@class MGLUserLocation; | ||
@class MGLPolyline; | ||
@class MGLPolygon; | ||
|
@@ -258,6 +259,18 @@ IB_DESIGNABLE | |
* @param annotations The array of annotations to remove. Objects in the array must conform to the MGLAnnotation protocol. */ | ||
- (void)removeAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations; | ||
|
||
/** Returns a reusable annotation image object located by its identifier. | ||
* | ||
* For performance reasons, you should generally reuse MGLAnnotationImage objects for annotations in your map views. Dequeueing saves time and memory during performance-critical operations such as scrolling. | ||
* | ||
* @param identifier A string identifying the annotation image to be reused. This string is the same one you specify when initially returning the annotation image object using the mapView:imageForAnnotation: method. | ||
* @return An annotation image object with the specified identifier, or `nil` if no such object exists in the reuse queue. */ | ||
- (nullable MGLAnnotationImage *)dequeueReusableAnnotationImageWithIdentifier:(NSString *)identifier; | ||
|
||
#pragma mark - Managing Annotation Selections | ||
|
||
/** @name Managing Annotation Selections */ | ||
|
||
/** The annotations that are currently selected. | ||
* | ||
* Assigning a new array to this property selects only the first annotation in the array. */ | ||
|
@@ -336,7 +349,13 @@ IB_DESIGNABLE | |
* @param mapView The map view that requested the annotation symbol name. | ||
* @param annotation The object representing the annotation that is about to be displayed. | ||
* @return The marker symbol to display for the specified annotation or `nil` if you want to display the default symbol. */ | ||
- (nullable NSString *)mapView:(MGLMapView *)mapView symbolNameForAnnotation:(id <MGLAnnotation>)annotation; | ||
- (nullable NSString *)mapView:(MGLMapView *)mapView symbolNameForAnnotation:(id <MGLAnnotation>)annotation __attribute__((unavailable("Use -mapView:imageForAnnotation:."))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be worth leaving the existing symbol-based annotation API around? Seems like it’d continue to be the most convenient way to use Maki icons as annotation images (for instance). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, hadn't thought about Maki. You'd have to know which were in the style, though, as it's not all of them by default. I don't think there's much benefit, until such time that we maybe roll out an |
||
|
||
/** Returns an image object to use for the marker for the specified point annotation object. | ||
* @param mapView The map view that requested the annotation image. | ||
* @param annotation The object representing the annotation that is about to be displayed. | ||
* @return The image object to display for the specified annotation or `nil` if you want to display the default marker image. */ | ||
- (nullable MGLAnnotationImage *)mapView:(MGLMapView *)mapView imageForAnnotation:(id <MGLAnnotation>)annotation; | ||
|
||
/** Returns the alpha value to use when rendering a shape annotation. Defaults to `1.0`. | ||
* @param mapView The map view rendering the shape annotation. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#import "MGLAnnotationImage.h" | ||
|
||
@interface MGLAnnotationImage () | ||
|
||
@property (nonatomic) UIImage *image; | ||
@property (nonatomic) NSString *reuseIdentifier; | ||
|
||
@end | ||
|
||
@implementation MGLAnnotationImage | ||
|
||
+ (instancetype)annotationImageWithImage:(UIImage *)image reuseIdentifier:(NSString *)reuseIdentifier | ||
{ | ||
return [[self alloc] initWithImage:image reuseIdentifier:reuseIdentifier]; | ||
} | ||
|
||
- (instancetype)initWithImage:(UIImage *)image reuseIdentifier:(NSString *)reuseIdentifier | ||
{ | ||
self = [super init]; | ||
|
||
if (self) | ||
{ | ||
_image = image; | ||
_reuseIdentifier = [reuseIdentifier copy]; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
@end |
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.
This file should be audited for nullability. Since neither property should ever be
nil
, surround the header withNS_ASSUME_NONNULL_BEGIN
andNS_ASSUME_NONNULL_END
and import MGLTypes.h (to get the Xcode 6.1 compatibility shim).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.
Grabbed this last night already: 56fbebf
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.
Is this strictly required if it's pulled in with
MapboxGL.h
?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.
No, but then this header should pull in MGLTypes.h. Headers shouldn't have implicit dependencies.
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.
f8342da