summaryrefslogtreecommitdiff
path: root/platform/ios/MGLMapView.mm
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2015-12-16 14:14:44 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2015-12-16 15:48:55 -0800
commit350cafb9036e4639e3417b15b17a54582017302f (patch)
tree649a77504985ad3806e6e7bb849b5e579539837f /platform/ios/MGLMapView.mm
parent13d5b18ebaeb330f05c4abfc04e0247222e038ba (diff)
downloadqtlocation-mapboxgl-350cafb9036e4639e3417b15b17a54582017302f.tar.gz
Revert "Revert "[ios] Custom style layer""
This reverts commit 081e4e44516937a6139fad5823dd5ec3200cc343.
Diffstat (limited to 'platform/ios/MGLMapView.mm')
-rw-r--r--platform/ios/MGLMapView.mm66
1 files changed, 66 insertions, 0 deletions
diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm
index 5d944e81fe..e9657f5616 100644
--- a/platform/ios/MGLMapView.mm
+++ b/platform/ios/MGLMapView.mm
@@ -1,5 +1,6 @@
#import "MGLMapView.h"
#import "MGLMapView+IBAdditions.h"
+#import "MGLMapView+MGLCustomStyleLayerAdditions.h"
#import <mbgl/platform/log.hpp>
#import <mbgl/platform/gl.hpp>
@@ -3472,6 +3473,8 @@ class MBGLView : public mbgl::View
@end
+#pragma mark - IBAdditions methods
+
@implementation MGLMapView (IBAdditions)
+ (NS_SET_OF(NSString *) *)keyPathsForValuesAffectingStyleURL__
@@ -3610,3 +3613,66 @@ class MBGLView : public mbgl::View
}
@end
+
+#pragma mark - MGLCustomStyleLayerAdditions methods
+
+class MGLCustomStyleLayerHandlers
+{
+public:
+ MGLCustomStyleLayerHandlers(MGLCustomStyleLayerPreparationHandler p,
+ MGLCustomStyleLayerDrawingHandler d,
+ MGLCustomStyleLayerCompletionHandler f)
+ : prepare(p), draw(d), finish(f) {}
+
+ MGLCustomStyleLayerPreparationHandler prepare;
+ MGLCustomStyleLayerDrawingHandler draw;
+ MGLCustomStyleLayerCompletionHandler finish;
+};
+
+void MGLPrepareCustomStyleLayer(void *context)
+{
+ MGLCustomStyleLayerPreparationHandler prepare = reinterpret_cast<MGLCustomStyleLayerHandlers *>(context)->prepare;
+ if (prepare)
+ {
+ prepare();
+ }
+}
+
+void MGLDrawCustomStyleLayer(void *context, const mbgl::CustomLayerRenderParameters &params)
+{
+ CGSize size = CGSizeMake(params.width, params.height);
+ CLLocationCoordinate2D centerCoordinate = CLLocationCoordinate2DMake(params.latitude, params.longitude);
+ double zoomLevel = params.zoom;
+ CLLocationDirection direction = mbgl::util::wrap(params.bearing, 0., 360.);
+ CGFloat pitch = params.pitch;
+ CGFloat perspectiveSkew = params.altitude;
+ MGLCustomStyleLayerDrawingHandler draw = reinterpret_cast<MGLCustomStyleLayerHandlers *>(context)->draw;
+ if (draw)
+ {
+ draw(size, centerCoordinate, zoomLevel, direction, pitch, perspectiveSkew);
+ }
+}
+
+void MGLFinishCustomStyleLayer(void *context)
+{
+ MGLCustomStyleLayerHandlers *handlers = reinterpret_cast<MGLCustomStyleLayerHandlers *>(context);
+ MGLCustomStyleLayerCompletionHandler finish = handlers->finish;
+ if (finish)
+ {
+ finish();
+ }
+ delete handlers;
+}
+
+@implementation MGLMapView (MGLCustomStyleLayerAdditions)
+
+- (void)insertCustomStyleLayerWithIdentifier:(NSString *)identifier preparationHandler:(void (^)())preparation drawingHandler:(MGLCustomStyleLayerDrawingHandler)drawing completionHandler:(void (^)())completion belowStyleLayerWithIdentifier:(nullable NSString *)otherIdentifier
+{
+ NSAssert(identifier, @"Style layer needs an identifier");
+ MGLCustomStyleLayerHandlers *context = new MGLCustomStyleLayerHandlers(preparation, drawing, completion);
+ _mbglMap->addCustomLayer(identifier.UTF8String, MGLPrepareCustomStyleLayer,
+ MGLDrawCustomStyleLayer, MGLFinishCustomStyleLayer,
+ context, otherIdentifier.UTF8String);
+}
+
+@end