Removed Added MGLObserver, MGLObservable (pr 358). The implementation is partially in the core library which so it could not be cherry-picked.

This commit is contained in:
Petr Pokorny
2021-02-22 19:28:26 +01:00
parent 409ef553fa
commit bede290e9b
13 changed files with 1 additions and 516 deletions

View File

@@ -1,41 +0,0 @@
#import "MGLFoundation.h"
NS_ASSUME_NONNULL_BEGIN
/**
Type of event used when subscribing to and unsubscribing from an `MGLObservable`.
*/
typedef NSString *MGLEventType NS_TYPED_EXTENSIBLE_ENUM;
// TODO: Doc
FOUNDATION_EXPORT MGL_EXPORT MGLEventType const MGLEventTypeResourceRequest;
/**
Generic Event used when notifying an `MGLObserver`. This is not intended nor
expected to be created by the application developer. It will be provided as
part of an `MGLObservable` notification.
*/
MGL_EXPORT
@interface MGLEvent: NSObject
/// Type of an event. Matches an original event type used for a subscription.
@property (nonatomic, readonly, copy) MGLEventType type;
/// Timestamp taken at the time of an event creation, relative to the Unix epoch.
@property (nonatomic, readonly) NSTimeInterval begin;
/// Timestamp taken at the time of an event completion. For a non-interval
/// (single-shot) events, migth be equal to an event's `begin` timestamp.
/// Relative to the Unix epoch.
@property (nonatomic, readonly) NSTimeInterval end;
/// Generic property for the event's data. Supported types are: `NSNumber` (int64,
/// uint64, bool, double), `NSString`, `NSArray`, `NSDictionary`.
@property (nonatomic, readonly, copy) id data;
/// Test for equality. Note this compares all properties except `data`.
- (BOOL)isEqualToEvent:(MGLEvent *)otherEvent;
@end
NS_ASSUME_NONNULL_END

View File

@@ -1,80 +0,0 @@
#import "MGLEvent_Private.h"
#import "MGLStyleValue_Private.h"
const MGLEventType MGLEventTypeResourceRequest = @"resource-request";
#pragma mark - Event
@implementation MGLEvent
- (instancetype)init {
[self doesNotRecognizeSelector:_cmd];
return nil;
}
- (instancetype)initWithEvent:(const mbgl::ObservableEvent&)event {
self = [super init];
if (!self)
return nil;
// mbgl::ObservableEvent timestamps do not use the system_clock, i.e. they
// are not relative to the Unix epoch, so we'll need to offset appropriately
auto systemClockNow = std::chrono::system_clock::now();
auto steadyClockNow = std::chrono::steady_clock::now();
auto begin = std::chrono::time_point_cast<std::chrono::system_clock::duration>(systemClockNow +
(event.begin - steadyClockNow));
auto end = std::chrono::time_point_cast<std::chrono::system_clock::duration>(systemClockNow +
(event.end - steadyClockNow));
auto beginTime = std::chrono::duration<double, std::ratio<1>>(begin.time_since_epoch()).count();
auto endTime = std::chrono::duration<double, std::ratio<1>>(end.time_since_epoch()).count();
_type = (MGLEventType)[NSString stringWithUTF8String:event.type.c_str()];
_begin = beginTime;
_end = endTime;
// From value.md
// Supported types are `int`, `uint`, `bool`, `double`, `array`, `object` and `string`.
_data = MGLJSONObjectFromMBGLValue(event.data);
return self;
}
- (NSString *)description {
return [NSString stringWithFormat:@"<%@: %p; type = %@, begin = %f, end = %f, data = %@>",
NSStringFromClass([self class]), (void *)self,
self.type,
self.begin,
self.end,
self.data];
}
#pragma mark - Equality
- (NSUInteger)hash {
return self.type.hash ^ @(self.begin).hash ^ @(self.end).hash;
}
- (BOOL)isEqualToEvent:(MGLEvent *)other {
if (self == other)
return YES;
// Ignore the value at this moment.
return ((self.type == other.type) &&
(self.begin == other.begin) &&
(self.end == other.end));
}
- (BOOL)isEqual:(id)other {
if (self == other)
return YES;
if (![other isKindOfClass:[MGLEvent class]]) {
return NO;
}
return [self isEqualToEvent:(MGLEvent*)other];
}
@end

View File

@@ -1,11 +0,0 @@
#import <Foundation/Foundation.h>
#import "MGLEvent.h"
#include <mbgl/util/observable.hpp>
NS_ASSUME_NONNULL_BEGIN
@interface MGLEvent ()
- (instancetype)initWithEvent:(const mbgl::ObservableEvent&)event;
@end
NS_ASSUME_NONNULL_END

View File

@@ -1,65 +0,0 @@
#import "MGLFoundation.h"
#import "MGLEvent.h"
NS_ASSUME_NONNULL_BEGIN
#pragma mark -
/**
Base class for observers used to receive notifications from an `MGLObservable`.
Subclasses should only override `-[MGLObserver notifyWithEvent:]`.
*/
MGL_EXPORT
@interface MGLObserver: NSObject
/// A unique identifier that can be used to identify an observer.
@property (nonatomic, readonly) NSUInteger identifier;
/// Primary notification method.
- (void)notifyWithEvent:(MGLEvent*)event;
// TODO: document
- (BOOL)isEqualToObserver:(MGLObserver *)other;
@end
#pragma mark -
/**
Protocol that yypes that wish to support subscriptions for events should conform
to.
*/
MGL_EXPORT
@protocol MGLObservable
/**
Subscribes an `MGLObserver` to a provided set of event types.
`MGLObservable` will hold a strong reference to an `MGLObserver` instance,
therefore, in order to stop receiving notifications (and to avoid memory leaks),
the caller must call unsubscribe with the `MGLObserver` instance used for
the initial subscription.
@param observer an MGLObserver
@param events a set of event types to subscribe to.
*/
- (void)subscribeForObserver:(nonnull MGLObserver *)observer
events:(nonnull NSSet<MGLEventType> *)events;
/**
Unsubscribes an `MGLObserver` from a provided set of event types.
@param observer an MGLObserver
@param events a set of event types to unsubscribe from.
*/
- (void)unsubscribeForObserver:(nonnull MGLObserver *)observer
events:(nonnull NSSet<MGLEventType> *)events;
/**
Unsubscribes an `MGLObserver` from all events (and release the strong reference).
@param observer an MGLObserver
*/
- (void)unsubscribeForObserver:(nonnull MGLObserver *)observer;
@end
NS_ASSUME_NONNULL_END

View File

@@ -1,101 +0,0 @@
#import "MGLObserver_Private.h"
#import "MGLLoggingConfiguration_Private.h"
#import "MGLEvent_Private.h"
#pragma mark - Native C++ peer object
namespace mbgl {
namespace darwin {
void Observer::notify(const ObservableEvent& event) {
if (!observer) {
MGLLogWarning(@"Platform observer has been deallocated");
return;
}
[observer notifyWithEvent:[[MGLEvent alloc] initWithEvent:event]];
}
std::size_t Observer::id() const {
if (!observer) {
MGLLogWarning(@"Platform observer has been deallocated");
return 0;
}
return static_cast<std::size_t>(observer.identifier);
}
}
}
#pragma mark - Cocoa observer
@implementation MGLObserver
+ (NSUInteger)nextIdentifier {
static NSUInteger identifier;
return ++identifier;
}
- (void)dealloc {
MGLAssert(!_observing, @"Ensure the observer is unsubscribed before deallocating");
}
- (instancetype)init {
self = [super init];
if (!self) return nil;
_identifier = [MGLObserver nextIdentifier];
_peer = std::make_shared<mbgl::darwin::Observer>(self);
return self;
}
- (void)notifyWithEvent:(MGLEvent*)event {
if (self.notificationHandler) {
self.notificationHandler(event);
}
}
- (BOOL)isEqualToObserver:(MGLObserver *)other {
if (self == other)
return YES;
if (self.identifier != other.identifier)
return NO;
return (self.peer == other.peer);
}
- (BOOL)isEqual:(id)other {
if (self == other)
return YES;
if (![other isKindOfClass:[MGLObserver class]]) {
return NO;
}
return [self isEqualToObserver:(MGLObserver*)other];
}
- (NSUInteger)hash {
// Rotate the address
NSUInteger peerHash = reinterpret_cast<NSUInteger>(self.peer.get());
NSUInteger width = (sizeof(NSUInteger) * __CHAR_BIT__);
NSUInteger shift = self.identifier % width;
NSUInteger newHash = (peerHash << shift) | (peerHash >> (width - shift));
return newHash;
}
- (NSString *)description {
return [NSString stringWithFormat:@"<%@: %p; identifier = %lu, peer = %p, hash = %lu>",
NSStringFromClass([self class]), (void *)self,
(unsigned long)self.identifier,
self.peer.get(),
(unsigned long)[self hash]];
}
@end

View File

@@ -1,40 +0,0 @@
#import <mbgl/util/observable.hpp>
#import "MGLObserver.h"
NS_ASSUME_NONNULL_BEGIN
#pragma mark - Native C++ peer object
namespace mbgl {
namespace darwin {
class Observer : public mbgl::Observer {
public:
Observer(MGLObserver *observer_): observer(observer_) {}
virtual ~Observer() = default;
virtual void notify(const ObservableEvent& event);
virtual std::size_t id() const;
protected:
/// Cocoa observer that this adapter bridges to.
__weak MGLObserver *observer = nullptr;
};
}
}
#pragma mark -
@interface MGLObserver ()
@property (nonatomic, assign) std::shared_ptr<mbgl::darwin::Observer> peer;
// TODO: Consider making public
@property (nonatomic, copy) void (^notificationHandler)(MGLEvent *);
// Debug property used for development.
@property (nonatomic, assign) BOOL observing;
@end
NS_ASSUME_NONNULL_END

View File

@@ -10,7 +10,6 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
* Added `[MGLLocationManager requestTemporaryFullAccuracyAuthorizationWithPurposeKeyproperty:]` to allow developers request just-in-time full-accuracy permissions. (cherry pick from [#361](https://github.com/mapbox/mapbox-gl-native-ios/pull/361))
* Added `[MGLLocationManagerDelegate locationManagerDidChangeAuthorization:]` to let `MGLMapView` know about privacy changes. (cherry pick from [#376](https://github.com/mapbox/mapbox-gl-native-ios/pull/376))
* Added `[MGLMapViewDelegate mapView:didChangeLocationManagerAuthorization:]` to allow developers adjust their apps to privacy settings changes. (cherry pick from [#376](https://github.com/mapbox/mapbox-gl-native-ios/pull/376))
* Added `MGLObserver`, `MGLObservable` and `MGLEvent` to monitor events from the map view. (cherry pick from [#358](https://github.com/mapbox/mapbox-gl-native-ios/pull/358))
* Added an approximate user location halo when `MGLLocationManager.accuracyAuthorization` is set to `CLAccuracyAuthorizationReducedAccuracy`. (cherry pick from [#381](https://github.com/mapbox/mapbox-gl-native-ios/pull/381))
* The `MGLAccuracyAuthorizationDescription` as element of `NSLocationTemporaryUsageDescriptionDictionary` Info.plist key can now be set to describe why you request accuracy authorization. (cherry pick from [#392](https://github.com/mapbox/mapbox-gl-native-ios/pull/392))
* Added `[MGLMapViewDelegate mapViewStyleForDefaultUserLocationAnnotationView:]` and `MGLUserLocationAnnotationViewStyle` class to allow developers customize the default user location annotation view UI style. (cherry pick from [#403](https://github.com/mapbox/mapbox-gl-native-ios/pull/403))

View File

@@ -192,15 +192,6 @@ CLLocationCoordinate2D randomWorldCoordinate() {
@implementation MBXSpriteBackedAnnotation
@end
@interface MBXTestObserver: MGLObserver
@end
@implementation MBXTestObserver
- (void)notifyWithEvent:(MGLEvent *)event {
NSLog(@"Received event: %@", event);
}
@end
@interface MBXViewController () <UITableViewDelegate,
UITableViewDataSource,
MGLMapViewDelegate,
@@ -221,7 +212,6 @@ CLLocationCoordinate2D randomWorldCoordinate() {
@property (nonatomic) BOOL zoomLevelOrnamentEnabled;
@property (nonatomic) NSMutableArray<UIWindow *> *helperWindows;
@property (nonatomic) NSMutableArray<UIView *> *contentInsetsOverlays;
@property (nonatomic) MBXTestObserver *testObserver;
@property (nonatomic, copy) void (^locationBlock)(void);
@end
@@ -309,15 +299,6 @@ CLLocationCoordinate2D randomWorldCoordinate() {
}
}
}];
// TODO: Replace with menu implementation
self.testObserver = [[MBXTestObserver alloc] init];
[self.mapView subscribeForObserver:self.testObserver event:MGLEventTypeResourceRequest];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.mapView unsubscribeForObserver:self.testObserver];
self.testObserver = nil;
});
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations

View File

@@ -224,18 +224,6 @@
40F887701D7A1E58008ECB67 /* MGLShapeSource_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 40F8876F1D7A1DB8008ECB67 /* MGLShapeSource_Private.h */; };
40F887711D7A1E59008ECB67 /* MGLShapeSource_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 40F8876F1D7A1DB8008ECB67 /* MGLShapeSource_Private.h */; };
40FDA76B1CCAAA6800442548 /* MBXAnnotationView.m in Sources */ = {isa = PBXBuildFile; fileRef = 40FDA76A1CCAAA6800442548 /* MBXAnnotationView.m */; };
4BC5767B25E3C8AB006E06EB /* MGLObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BC5767525E3C8AA006E06EB /* MGLObserver.h */; };
4BC5767C25E3C8AB006E06EB /* MGLObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BC5767525E3C8AA006E06EB /* MGLObserver.h */; };
4BC5767D25E3C8AB006E06EB /* MGLEvent_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BC5767625E3C8AB006E06EB /* MGLEvent_Private.h */; };
4BC5767E25E3C8AB006E06EB /* MGLEvent_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BC5767625E3C8AB006E06EB /* MGLEvent_Private.h */; };
4BC5767F25E3C8AB006E06EB /* MGLEvent.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4BC5767725E3C8AB006E06EB /* MGLEvent.mm */; };
4BC5768025E3C8AB006E06EB /* MGLEvent.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4BC5767725E3C8AB006E06EB /* MGLEvent.mm */; };
4BC5768125E3C8AB006E06EB /* MGLObserver.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4BC5767825E3C8AB006E06EB /* MGLObserver.mm */; };
4BC5768225E3C8AB006E06EB /* MGLObserver.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4BC5767825E3C8AB006E06EB /* MGLObserver.mm */; };
4BC5768325E3C8AB006E06EB /* MGLEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BC5767925E3C8AB006E06EB /* MGLEvent.h */; };
4BC5768425E3C8AB006E06EB /* MGLEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BC5767925E3C8AB006E06EB /* MGLEvent.h */; };
4BC5768525E3C8AB006E06EB /* MGLObserver_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BC5767A25E3C8AB006E06EB /* MGLObserver_Private.h */; };
4BC5768625E3C8AB006E06EB /* MGLObserver_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BC5767A25E3C8AB006E06EB /* MGLObserver_Private.h */; };
4BC5769325E3D3D6006E06EB /* MGLUserLocationAnnotationViewStyle.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BC5769125E3D3D6006E06EB /* MGLUserLocationAnnotationViewStyle.h */; };
4BC5769425E3D3D6006E06EB /* MGLUserLocationAnnotationViewStyle.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BC5769125E3D3D6006E06EB /* MGLUserLocationAnnotationViewStyle.h */; };
4BC5769525E3D3D6006E06EB /* MGLUserLocationAnnotationViewStyle.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BC5769225E3D3D6006E06EB /* MGLUserLocationAnnotationViewStyle.m */; };
@@ -923,12 +911,6 @@
40F8876F1D7A1DB8008ECB67 /* MGLShapeSource_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLShapeSource_Private.h; sourceTree = "<group>"; };
40FDA7691CCAAA6800442548 /* MBXAnnotationView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MBXAnnotationView.h; sourceTree = "<group>"; };
40FDA76A1CCAAA6800442548 /* MBXAnnotationView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MBXAnnotationView.m; sourceTree = "<group>"; };
4BC5767525E3C8AA006E06EB /* MGLObserver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLObserver.h; sourceTree = "<group>"; };
4BC5767625E3C8AB006E06EB /* MGLEvent_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLEvent_Private.h; sourceTree = "<group>"; };
4BC5767725E3C8AB006E06EB /* MGLEvent.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLEvent.mm; sourceTree = "<group>"; };
4BC5767825E3C8AB006E06EB /* MGLObserver.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLObserver.mm; sourceTree = "<group>"; };
4BC5767925E3C8AB006E06EB /* MGLEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLEvent.h; sourceTree = "<group>"; };
4BC5767A25E3C8AB006E06EB /* MGLObserver_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLObserver_Private.h; sourceTree = "<group>"; };
4BC5769125E3D3D6006E06EB /* MGLUserLocationAnnotationViewStyle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLUserLocationAnnotationViewStyle.h; sourceTree = "<group>"; };
4BC5769225E3D3D6006E06EB /* MGLUserLocationAnnotationViewStyle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLUserLocationAnnotationViewStyle.m; sourceTree = "<group>"; };
550570C422958FB300228ECF /* MGLMapView+Impl.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "MGLMapView+Impl.mm"; sourceTree = "<group>"; };
@@ -1918,12 +1900,6 @@
1F6A82A021360F9C00BA5B41 /* MGLLoggingConfiguration.h */,
CF75A91422D85E860058A5C4 /* MGLLoggingConfiguration.mm */,
1F6A82A62138871900BA5B41 /* MGLLoggingConfiguration_Private.h */,
4BC5767625E3C8AB006E06EB /* MGLEvent_Private.h */,
4BC5767925E3C8AB006E06EB /* MGLEvent.h */,
4BC5767725E3C8AB006E06EB /* MGLEvent.mm */,
4BC5767A25E3C8AB006E06EB /* MGLObserver_Private.h */,
4BC5767525E3C8AA006E06EB /* MGLObserver.h */,
4BC5767825E3C8AB006E06EB /* MGLObserver.mm */,
);
name = Foundation;
path = ../darwin/src;
@@ -2214,7 +2190,6 @@
357FE2DD1E02D2B20068B753 /* NSCoder+MGLAdditions.h in Headers */,
35D13AB71D3D15E300AFB4E0 /* MGLStyleLayer.h in Headers */,
07D947531F67488E00E37934 /* MGLComputedShapeSource_Private.h in Headers */,
4BC5768325E3C8AB006E06EB /* MGLEvent.h in Headers */,
9654C1261FFC1AB900DB6A19 /* MGLPolyline_Private.h in Headers */,
40F887701D7A1E58008ECB67 /* MGLShapeSource_Private.h in Headers */,
350098DC1D484E60004B2AF0 /* NSValue+MGLStyleAttributeAdditions.h in Headers */,
@@ -2228,7 +2203,6 @@
3510FFF01D6D9D8C00F413B2 /* NSExpression+MGLAdditions.h in Headers */,
74CB5EBF219B280400102936 /* MGLHeatmapStyleLayer_Private.h in Headers */,
1FC4817D2098CBC0000D09B4 /* NSPredicate+MGLPrivateAdditions.h in Headers */,
4BC5767B25E3C8AB006E06EB /* MGLObserver.h in Headers */,
1F2B94C0221636D900210640 /* MGLNetworkConfiguration_Private.h in Headers */,
353AFA141D65AB17005A69F4 /* NSDate+MGLAdditions.h in Headers */,
DA8848531CBAFB9800AB86E3 /* MGLCompactCalloutView.h in Headers */,
@@ -2335,7 +2309,6 @@
DA72620B1DEEE3480043BB89 /* MGLOpenGLStyleLayer.h in Headers */,
404C26E71D89C55D000AA13D /* MGLTileSource_Private.h in Headers */,
DA88485C1CBAFB9800AB86E3 /* MGLFaux3DUserLocationAnnotationView.h in Headers */,
4BC5767D25E3C8AB006E06EB /* MGLEvent_Private.h in Headers */,
359F57461D2FDDA6005217F1 /* MGLUserLocationAnnotationView_Private.h in Headers */,
404C26E21D89B877000AA13D /* MGLTileSource.h in Headers */,
DA8847FD1CBAFA5100AB86E3 /* MGLTilePyramidOfflineRegion.h in Headers */,
@@ -2344,7 +2317,6 @@
350098BB1D480108004B2AF0 /* MGLVectorTileSource.h in Headers */,
DA8847F61CBAFA5100AB86E3 /* MGLOfflineStorage.h in Headers */,
DAD1656E1CF41981001FF4B9 /* MGLFeature_Private.h in Headers */,
4BC5768525E3C8AB006E06EB /* MGLObserver_Private.h in Headers */,
DA88483C1CBAFB8500AB86E3 /* MGLMapView.h in Headers */,
3EA9363147E77DD29FA06063 /* MGLRendererConfiguration.h in Headers */,
550570C822958FB400228ECF /* MGLMapView+Impl.h in Headers */,
@@ -2377,7 +2349,6 @@
3566C7671D4A77BA008152BC /* MGLShapeSource.h in Headers */,
DA35A29F1CC9E94C00E826B2 /* MGLCoordinateFormatter.h in Headers */,
967C864C210A9D3C004DF794 /* UIDevice+MGLAdditions.h in Headers */,
4BC5768425E3C8AB006E06EB /* MGLEvent.h in Headers */,
404C26E31D89B877000AA13D /* MGLTileSource.h in Headers */,
96E516F6200059EC00A02306 /* MGLRendererFrontend.h in Headers */,
071BBB041EE76147001FB02A /* MGLImageSource.h in Headers */,
@@ -2391,7 +2362,6 @@
96E516EF2000594F00A02306 /* NSArray+MGLAdditions.h in Headers */,
96E516F12000596800A02306 /* NSString+MGLAdditions.h in Headers */,
35E0CFE71D3E501500188327 /* MGLStyle_Private.h in Headers */,
4BC5767C25E3C8AB006E06EB /* MGLObserver.h in Headers */,
CA55CD42202C16AA00CE7095 /* MGLCameraChangeReason.h in Headers */,
DABFB86D1CBE9A0F00D62B32 /* MGLAnnotationImage.h in Headers */,
DABFB8721CBE9A0F00D62B32 /* MGLUserLocation.h in Headers */,
@@ -2498,7 +2468,6 @@
96E516E82000560B00A02306 /* MGLAnnotationContainerView_Private.h in Headers */,
35D13AC41D3D19DD00AFB4E0 /* MGLFillStyleLayer.h in Headers */,
DABFB86E1CBE9A0F00D62B32 /* MGLCalloutView.h in Headers */,
4BC5767E25E3C8AB006E06EB /* MGLEvent_Private.h in Headers */,
96E516FC20005A4400A02306 /* MGLUserLocationHeadingIndicator.h in Headers */,
1F7454971ECD450D00021D39 /* MGLLight_Private.h in Headers */,
DABFB8601CBE99E500D62B32 /* MGLMapCamera.h in Headers */,
@@ -2507,7 +2476,6 @@
DABFB86A1CBE99E500D62B32 /* MGLStyle.h in Headers */,
DA00FC8F1D5EEB0D009AABC8 /* MGLAttributionInfo.h in Headers */,
96E516E12000551100A02306 /* MGLMultiPoint_Private.h in Headers */,
4BC5768625E3C8AB006E06EB /* MGLObserver_Private.h in Headers */,
3EA934623AD0000B7D99C3FB /* MGLRendererConfiguration.h in Headers */,
DACA86272019218600E9693A /* MGLRasterDEMSource.h in Headers */,
9621F2502091020E005B3800 /* NSExpression+MGLAdditions.h in Headers */,
@@ -3097,7 +3065,6 @@
DA8848261CBAFA6200AB86E3 /* MGLPolygon.mm in Sources */,
35B82BFA1D6C5F8400B1B721 /* NSPredicate+MGLAdditions.mm in Sources */,
966FCF4E1F3A5C9200F2B6DE /* MGLUserLocationHeadingBeamLayer.m in Sources */,
4BC5768125E3C8AB006E06EB /* MGLObserver.mm in Sources */,
8989B17E201A48EB0081CF59 /* MGLHeatmapStyleLayer.mm in Sources */,
353AFA161D65AB17005A69F4 /* NSDate+MGLAdditions.mm in Sources */,
1FCAE2A420B872A400C577DD /* MGLLocationManager.m in Sources */,
@@ -3114,7 +3081,6 @@
DA8848271CBAFA6200AB86E3 /* MGLPolyline.mm in Sources */,
35CE61841D4165D9004F2359 /* UIColor+MGLAdditions.mm in Sources */,
3EA93369F61CF70AFA50465D /* MGLRendererConfiguration.m in Sources */,
4BC5767F25E3C8AB006E06EB /* MGLEvent.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -3196,7 +3162,6 @@
966FCF4F1F3A5C9200F2B6DE /* MGLUserLocationHeadingBeamLayer.m in Sources */,
DAA4E4231CBB730400178DFB /* MGLPolygon.mm in Sources */,
8989B17F201A48EB0081CF59 /* MGLHeatmapStyleLayer.mm in Sources */,
4BC5768225E3C8AB006E06EB /* MGLObserver.mm in Sources */,
353AFA171D65AB17005A69F4 /* NSDate+MGLAdditions.mm in Sources */,
35D13AC61D3D19DD00AFB4E0 /* MGLFillStyleLayer.mm in Sources */,
1FCAE2A520B872A400C577DD /* MGLLocationManager.m in Sources */,
@@ -3213,7 +3178,6 @@
35CE61851D4165D9004F2359 /* UIColor+MGLAdditions.mm in Sources */,
DAA4E4241CBB730400178DFB /* MGLPolyline.mm in Sources */,
3EA9366247780E4F252652A8 /* MGLRendererConfiguration.m in Sources */,
4BC5768025E3C8AB006E06EB /* MGLEvent.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@@ -6,7 +6,6 @@
#import "MGLMapCamera.h"
#import "MGLTypes.h"
#import "MGLStyle.h"
#import "MGLObserver.h"
NS_ASSUME_NONNULL_BEGIN
@@ -189,7 +188,7 @@ FOUNDATION_EXTERN MGL_EXPORT MGLExceptionName const MGLUserLocationAnnotationTyp
Simple map view</a> example to learn how to initialize a basic `MGLMapView`.
*/
MGL_EXPORT
@interface MGLMapView : UIView <MGLStylable, MGLObservable>
@interface MGLMapView : UIView <MGLStylable>
#pragma mark Creating Instances
@@ -2003,14 +2002,4 @@ MGL_EXPORT
*/
@property (nonatomic) MGLMapDebugMaskOptions debugMask;
/**
:nodoc:
Convenience method for subscribing to a single event. See `-[MGLObservable
subscribeForObserver:events:]`.
*/
- (void)subscribeForObserver:(nonnull MGLObserver *)observer
event:(nonnull MGLEventType)event;
@end
NS_ASSUME_NONNULL_END

View File

@@ -67,8 +67,6 @@
#import "MGLLoggingConfiguration_Private.h"
#import "MGLNetworkConfiguration_Private.h"
#import "MGLReachability.h"
#import "MGLObserver_Private.h"
#import "MGLEvent_Private.h"
#include <algorithm>
#include <cstdlib>
@@ -279,8 +277,6 @@ public:
@property (nonatomic, assign) UIEdgeInsets safeMapViewContentInsets;
@property (nonatomic, strong) NSNumber *automaticallyAdjustContentInsetHolder;
@property (nonatomic) NSMutableSet<MGLObserver *> *observerCache;
@end
@implementation MGLMapView
@@ -522,8 +518,6 @@ public:
_selectedAnnotationTag = MGLAnnotationTagNotFound;
_annotationsNearbyLastTap = {};
_observerCache = [NSMutableSet set];
// TODO: This warning should be removed when automaticallyAdjustsScrollViewInsets is removed from
// the UIViewController api.
static dispatch_once_t onceToken;
@@ -6892,41 +6886,6 @@ public:
return _annotationViewReuseQueueByIdentifier[identifier];
}
#pragma mark - MGLObservable methods -
static std::vector<std::string> vectorOfStringsFromSet(NSSet<NSString *> *setOfStrings) {
__block std::vector<std::string> strings;
strings.reserve(setOfStrings.count);
[setOfStrings enumerateObjectsUsingBlock:^(NSString * _Nonnull text, BOOL * _Nonnull stop) {
strings.push_back(text.UTF8String);
}];
return strings;
}
// Convenience method
- (void)subscribeForObserver:(nonnull MGLObserver *)observer event:(nonnull MGLEventType)event {
[self subscribeForObserver:observer events:[NSSet setWithObject:event]];
}
- (void)subscribeForObserver:(MGLObserver *)observer events:(nonnull NSSet<MGLEventType> *)events {
observer.observing = YES;
[self.observerCache addObject:observer];
auto eventTypes = vectorOfStringsFromSet(events);
self.mbglMap.subscribe(observer.peer, eventTypes);
}
- (void)unsubscribeForObserver:(MGLObserver *)observer events:(nonnull NSSet<MGLEventType> *)events {
auto eventTypes = vectorOfStringsFromSet(events);
self.mbglMap.unsubscribe(observer.peer, eventTypes);
}
- (void)unsubscribeForObserver:(MGLObserver *)observer {
self.mbglMap.unsubscribe(observer.peer);
[self.observerCache removeObject:observer];
observer.observing = NO;
}
@end
#pragma mark - IBAdditions methods

View File

@@ -23,7 +23,6 @@ FOUNDATION_EXPORT MGL_EXPORT const unsigned char MapboxVersionString[];
#import "MGLComputedShapeSource.h"
#import "MGLCoordinateFormatter.h"
#import "MGLDistanceFormatter.h"
#import "MGLEvent.h"
#import "MGLFeature.h"
#import "MGLFillExtrusionStyleLayer.h"
#import "MGLFillStyleLayer.h"
@@ -43,7 +42,6 @@ FOUNDATION_EXPORT MGL_EXPORT const unsigned char MapboxVersionString[];
#import "MGLMapView+IBAdditions.h"
#import "MGLMultiPoint.h"
#import "MGLNetworkConfiguration.h"
#import "MGLObserver.h"
#import "MGLOfflinePack.h"
#import "MGLOfflineRegion.h"
#import "MGLOfflineStorage.h"

View File

@@ -1,67 +0,0 @@
#pragma once
#include <map>
#include <mapbox/compatibility/value.hpp>
#include <mbgl/actor/scheduler.hpp>
#include <mbgl/util/chrono.hpp>
#include <memory>
#include <mutex>
#include <string>
#include <vector>
namespace mbgl {
class Observer;
struct ObservableEvent {
explicit ObservableEvent(std::string type);
std::string type;
TimePoint begin;
TimePoint end;
mapbox::base::Value data;
};
class Observer {
public:
virtual ~Observer() = default;
// Notifies Observer about an event
virtual void notify(const ObservableEvent&) = 0;
// Id of an observer, must be unique.
// Default implementation uses `this` address of an instance.
virtual std::size_t id() const;
};
// Observable class implements basic Publish&Subscribe functionality
class Observable {
public:
Observable();
virtual ~Observable();
// Subscribes `Observer` to recieve notifications of the event types provided in `eventTypes`
// `Observer::id()` would be used as an `id` for subscription.
virtual void subscribe(const std::shared_ptr<Observer>&, const std::vector<std::string>& eventTypes);
// Unsubscribes perviosly subscribed `Observer` with an `id`, that is provided by `Observer::id()`
// Whenever an empty list of events is provided, observer would be unsubscribed from all events.
virtual void unsubscribeWithId(std::size_t id, const std::vector<std::string>& eventTypes);
// Must return true if `Observable` supports an `eventType`.
virtual bool supportsEventType(const std::string& eventType) const;
// Shorthand for virtual method accepting `Observer` id.
void unsubscribe(const std::shared_ptr<Observer>&, const std::vector<std::string>& eventTypes);
void unsubscribe(const std::shared_ptr<Observer>&);
protected:
void dispatchEvent(const ObservableEvent&);
bool hasSubscribers() const;
private:
struct Subscriber;
std::map<std::size_t, std::unique_ptr<Subscriber>> subscribers;
mutable std::mutex mutex;
};
} // namespace mbgl