summaryrefslogtreecommitdiff
path: root/platform/darwin
diff options
context:
space:
mode:
authorFredrik Karlsson <bjorn.fredrik.karlsson@gmail.com>2016-08-16 11:01:32 +0200
committerFredrik Karlsson <bjorn.fredrik.karlsson@gmail.com>2016-08-18 14:26:05 +0200
commitf7069523b4b137eb6dfb965eca82d39b46841b15 (patch)
treee5cdc55ebef1091b4c9bd4f83d9cd1d003829379 /platform/darwin
parent02b908633eb3626b05f1c0abb04fe67054904609 (diff)
downloadqtlocation-mapboxgl-f7069523b4b137eb6dfb965eca82d39b46841b15.tar.gz
[ios, macos] fixes #5974 Move style classes API to MGLStyle
Diffstat (limited to 'platform/darwin')
-rw-r--r--platform/darwin/src/MGLStyle.h28
-rw-r--r--platform/darwin/src/MGLStyle.mm58
-rw-r--r--platform/darwin/src/MGLStyle_Private.h3
-rw-r--r--platform/darwin/src/MGLVectorSource.mm4
4 files changed, 91 insertions, 2 deletions
diff --git a/platform/darwin/src/MGLStyle.h b/platform/darwin/src/MGLStyle.h
index b1ccfe14e6..a8b36ab0ca 100644
--- a/platform/darwin/src/MGLStyle.h
+++ b/platform/darwin/src/MGLStyle.h
@@ -221,6 +221,34 @@ static const NSInteger MGLStyleDefaultVersion = 9;
*/
- (void)removeSource:(MGLSource *)source;
+/**
+ Currently active style classes, represented as an array of string identifiers.
+ */
+@property (nonatomic) NS_ARRAY_OF(NSString *) *styleClasses;
+
+/**
+ Returns a Boolean value indicating whether the style class with the given
+ identifier is currently active.
+
+ @param styleClass The style class to query for.
+ @return Whether the style class is currently active.
+ */
+- (BOOL)hasStyleClass:(NSString *)styleClass;
+
+/**
+ Activates the style class with the given identifier.
+
+ @param styleClass The style class to activate.
+ */
+- (void)addStyleClass:(NSString *)styleClass;
+
+/**
+ Deactivates the style class with the given identifier.
+
+ @param styleClass The style class to deactivate.
+ */
+- (void)removeStyleClass:(NSString *)styleClass;
+
@end
NS_ASSUME_NONNULL_END
diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm
index ae52dc3f2b..8bc4018e73 100644
--- a/platform/darwin/src/MGLStyle.mm
+++ b/platform/darwin/src/MGLStyle.mm
@@ -12,7 +12,11 @@
#import "MGLStyle_Private.h"
#import "MGLStyleLayer_Private.h"
#import "MGLSource_Private.h"
+
#import "MGLSource.h"
+#import "MGLVectorSource.h"
+#import "MGLRasterSource.h"
+#import "MGLGeoJSONSource.h"
#include <mbgl/util/default_styles.hpp>
#include <mbgl/style/layers/fill_layer.hpp>
@@ -179,4 +183,58 @@ static NSURL *MGLStyleURL_emerald;
self.mapView.mbglMap->removeSource(source.sourceIdentifier.UTF8String);
}
+- (NS_ARRAY_OF(NSString *) *)styleClasses
+{
+ NSMutableArray *returnArray = [NSMutableArray array];
+
+ const std::vector<std::string> &appliedClasses = self.mapView.mbglMap->getClasses();
+
+ for (auto class_it = appliedClasses.begin(); class_it != appliedClasses.end(); class_it++)
+ {
+ [returnArray addObject:@(class_it->c_str())];
+ }
+
+ return returnArray;
+}
+
+- (void)setStyleClasses:(NS_ARRAY_OF(NSString *) *)appliedClasses
+{
+ [self setStyleClasses:appliedClasses transitionDuration:0];
+}
+
+- (void)setStyleClasses:(NS_ARRAY_OF(NSString *) *)appliedClasses transitionDuration:(NSTimeInterval)transitionDuration
+{
+ std::vector<std::string> newAppliedClasses;
+
+ for (NSString *appliedClass in appliedClasses)
+ {
+ newAppliedClasses.insert(newAppliedClasses.end(), [appliedClass UTF8String]);
+ }
+
+ mbgl::style::TransitionOptions transition { { MGLDurationInSeconds(transitionDuration) } };
+ self.mapView.mbglMap->setClasses(newAppliedClasses, transition);
+}
+
+- (BOOL)hasStyleClass:(NSString *)styleClass
+{
+ return styleClass && self.mapView.mbglMap->hasClass([styleClass UTF8String]);
+}
+
+- (void)addStyleClass:(NSString *)styleClass
+{
+ if (styleClass)
+ {
+ self.mapView.mbglMap->addClass([styleClass UTF8String]);
+ }
+}
+
+- (void)removeStyleClass:(NSString *)styleClass
+{
+ if (styleClass)
+ {
+ self.mapView.mbglMap->removeClass([styleClass UTF8String]);
+ }
+}
+
+
@end
diff --git a/platform/darwin/src/MGLStyle_Private.h b/platform/darwin/src/MGLStyle_Private.h
index ed0122bf73..46291b37b9 100644
--- a/platform/darwin/src/MGLStyle_Private.h
+++ b/platform/darwin/src/MGLStyle_Private.h
@@ -7,4 +7,7 @@
@interface MGLStyle (Private)
@property (nonatomic, weak) MGLMapView *mapView;
+
+- (void)setStyleClasses:(NS_ARRAY_OF(NSString *) *)appliedClasses transitionDuration:(NSTimeInterval)transitionDuration;
+
@end
diff --git a/platform/darwin/src/MGLVectorSource.mm b/platform/darwin/src/MGLVectorSource.mm
index 2cf6f34f98..130144584b 100644
--- a/platform/darwin/src/MGLVectorSource.mm
+++ b/platform/darwin/src/MGLVectorSource.mm
@@ -1,6 +1,6 @@
#import "MGLVectorSource.h"
-#import "MGLSource_Private.hpp"
+#import "MGLSource_Private.h"
#include <mbgl/style/sources/vector_source.hpp>
@@ -9,7 +9,7 @@
static NSString *MGLVectorSourceType = @"vector";
- (instancetype)initWithSourceIdentifier:(NSString *)sourceIdentifier URL:(NSURL *)url {
- if (self = [super initWithSourceIdentifier:sourceIdentifier sourceType:MGLVectorSourceType]) {
+ if (self = [super initWithSourceIdentifier:sourceIdentifier]) {
_URL = url;
}
return self;