summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLRasterStyleLayer.mm
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-04-03 14:25:37 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-04-13 10:33:18 -0700
commitde6c9b35f35f6ec0950529261b207d716c046beb (patch)
treef022e3e09b4f8ffbe7646341f91aa76b8081ff62 /platform/darwin/src/MGLRasterStyleLayer.mm
parent98d005792b68d0b299f123c1d31e50c72ba91ba8 (diff)
downloadqtlocation-mapboxgl-de6c9b35f35f6ec0950529261b207d716c046beb.tar.gz
[darwin] Simplify MGLStyleLayer initialization and pointer management
Similarly to the previous commit, introduce `-[MGLStyleLayer initWithPendingLayer:]`, allowing the base class to track the owned `_pendingSource` pointer and implement `-addToMapView:` and `-removeFromMapView:` without any casts. Fixes an issue where `-[MGLStyle layerFromMBGLLayer:]` would wind up creating layers whose `_rawLayer` and `_pendingLayer` held different values.
Diffstat (limited to 'platform/darwin/src/MGLRasterStyleLayer.mm')
-rw-r--r--platform/darwin/src/MGLRasterStyleLayer.mm62
1 files changed, 5 insertions, 57 deletions
diff --git a/platform/darwin/src/MGLRasterStyleLayer.mm b/platform/darwin/src/MGLRasterStyleLayer.mm
index 80508e4e70..8f5415629a 100644
--- a/platform/darwin/src/MGLRasterStyleLayer.mm
+++ b/platform/darwin/src/MGLRasterStyleLayer.mm
@@ -2,35 +2,28 @@
// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`.
#import "MGLSource.h"
-#import "MGLMapView_Private.h"
#import "NSPredicate+MGLAdditions.h"
#import "NSDate+MGLAdditions.h"
#import "MGLStyleLayer_Private.h"
+#import "MGLForegroundStyleLayer_Private.h"
#import "MGLStyleValue_Private.h"
#import "MGLRasterStyleLayer.h"
-#include <mbgl/map/map.hpp>
+#include <mbgl/style/transition_options.hpp>
#include <mbgl/style/layers/raster_layer.hpp>
@interface MGLRasterStyleLayer ()
-@property (nonatomic) mbgl::style::RasterLayer *rawLayer;
+@property (nonatomic, readonly) mbgl::style::RasterLayer *rawLayer;
@end
@implementation MGLRasterStyleLayer
-{
- std::unique_ptr<mbgl::style::RasterLayer> _pendingLayer;
-}
- (instancetype)initWithIdentifier:(NSString *)identifier source:(MGLSource *)source
{
- if (self = [super initWithIdentifier:identifier source:source]) {
- auto layer = std::make_unique<mbgl::style::RasterLayer>(identifier.UTF8String, source.identifier.UTF8String);
- _pendingLayer = std::move(layer);
- self.rawLayer = _pendingLayer.get();
- }
- return self;
+ auto layer = std::make_unique<mbgl::style::RasterLayer>(identifier.UTF8String, source.identifier.UTF8String);
+ return self = [super initWithPendingLayer:std::move(layer) source:source];
}
- (mbgl::style::RasterLayer *)rawLayer
@@ -38,11 +31,6 @@
return (mbgl::style::RasterLayer *)super.rawLayer;
}
-- (void)setRawLayer:(mbgl::style::RasterLayer *)rawLayer
-{
- super.rawLayer = rawLayer;
-}
-
- (NSString *)sourceIdentifier
{
MGLAssertStyleLayerIsValid();
@@ -50,46 +38,6 @@
return @(self.rawLayer->getSourceID().c_str());
}
-#pragma mark - Adding to and removing from a map view
-
-- (void)addToMapView:(MGLMapView *)mapView belowLayer:(MGLStyleLayer *)otherLayer
-{
- if (_pendingLayer == nullptr) {
- [NSException raise:@"MGLRedundantLayerException"
- format:@"This instance %@ was already added to %@. Adding the same layer instance " \
- "to the style more than once is invalid.", self, mapView.style];
- }
-
- if (otherLayer) {
- const mbgl::optional<std::string> belowLayerId{otherLayer.identifier.UTF8String};
- mapView.mbglMap->addLayer(std::move(_pendingLayer), belowLayerId);
- } else {
- mapView.mbglMap->addLayer(std::move(_pendingLayer));
- }
-}
-
-- (void)removeFromMapView:(MGLMapView *)mapView
-{
- if (self.rawLayer != mapView.mbglMap->getLayer(self.identifier.UTF8String)) {
- return;
- }
-
- auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String);
- if (!removedLayer) {
- return;
- }
-
- mbgl::style::RasterLayer *layer = dynamic_cast<mbgl::style::RasterLayer *>(removedLayer.get());
- if (!layer) {
- return;
- }
-
- removedLayer.release();
-
- _pendingLayer = std::unique_ptr<mbgl::style::RasterLayer>(layer);
- self.rawLayer = _pendingLayer.get();
-}
-
#pragma mark - Accessing the Paint Attributes
- (void)setMaximumRasterBrightness:(MGLStyleValue<NSNumber *> *)maximumRasterBrightness {