summaryrefslogtreecommitdiff
path: root/platform/ios/src/MGLMapView.mm
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2017-06-23 12:17:31 -0700
committerMinh Nguyễn <mxn@1ec5.org>2017-07-05 18:32:59 -0700
commit3d255176c549f96a17d05c8e5240067f7c2ad0f4 (patch)
tree1bc2f94c195749fddd0497a82614c5ed7727f8d5 /platform/ios/src/MGLMapView.mm
parentf35b8703268cb09d5a48fa56a94b87564e8064db (diff)
downloadqtlocation-mapboxgl-3d255176c549f96a17d05c8e5240067f7c2ad0f4.tar.gz
[ios] Lots of experiments
The transform matrix is correct, but applying it to the annotation container view incorrectly translates each annotation view, and applying it to each annotation view individually causes an incorrect anchor point to be used.
Diffstat (limited to 'platform/ios/src/MGLMapView.mm')
-rw-r--r--platform/ios/src/MGLMapView.mm62
1 files changed, 61 insertions, 1 deletions
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 1444fc3cb0..72e471ac80 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -165,6 +165,32 @@ mbgl::util::UnitBezier MGLUnitBezierForMediaTimingFunction(CAMediaTimingFunction
return { p1[0], p1[1], p2[0], p2[1] };
}
+static CATransform3D MGLTransform3DFromMat4(mbgl::mat4 &matrix) {
+ CATransform3D transform;
+
+ transform.m11 = matrix[0];
+ transform.m12 = matrix[1];
+ transform.m13 = matrix[2];
+ transform.m14 = matrix[3];
+
+ transform.m21 = matrix[4];
+ transform.m22 = matrix[5];
+ transform.m23 = matrix[6];
+ transform.m24 = matrix[7];
+
+ transform.m31 = matrix[8];
+ transform.m32 = matrix[9];
+ transform.m33 = matrix[10];
+ transform.m34 = matrix[11];
+
+ transform.m41 = matrix[12];
+ transform.m42 = matrix[13];
+ transform.m43 = matrix[14];
+ transform.m44 = matrix[15];
+
+ return transform;
+}
+
@interface MGLAnnotationAccessibilityElement : UIAccessibilityElement
@property (nonatomic) MGLAnnotationTag tag;
@@ -3285,9 +3311,12 @@ public:
}
else
{
+// CGFloat side = mbgl::util::tileSize * powf(2.0, self.zoomLevel);
+// CGRect frame = CGRectMake(0, 0, side, side);
+// newAnnotationContainerView = [[MGLAnnotationContainerView alloc] initWithFrame:frame];
newAnnotationContainerView = [[MGLAnnotationContainerView alloc] initWithFrame:self.bounds];
}
- newAnnotationContainerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
+// newAnnotationContainerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
newAnnotationContainerView.contentMode = UIViewContentModeCenter;
[newAnnotationContainerView addSubviews:annotationViews];
[_glView insertSubview:newAnnotationContainerView atIndex:0];
@@ -5001,6 +5030,31 @@ public:
NSArray *visibleAnnotations = [self visibleAnnotationsInRect:viewPort];
NSMutableArray *offscreenAnnotations = [self.annotations mutableCopy];
[offscreenAnnotations removeObjectsInArray:visibleAnnotations];
+
+ MGLMapCamera *camera = self.camera;
+
+ // Build a projection matrix, paralleling the code found in mbgl.
+ // mbgl::TransformState::fov
+ double fov = 0.6435011087932844;
+ double halfFov = fov / 2.0;
+ double cameraToCenterDistance = 0.5 * CGRectGetHeight(self.bounds) / tanf(halfFov);
+
+ double groundAngle = M_PI_2 + MGLRadiansFromDegrees(camera.pitch);
+ double topHalfSurfaceDistance = sinf(halfFov) * cameraToCenterDistance / sinf(M_PI - groundAngle - halfFov);
+
+ // Calculate z distance of the farthest fragment that should be rendered.
+ double furthestDistance = cosf(M_PI_2 - MGLRadiansFromDegrees(camera.pitch)) * topHalfSurfaceDistance + cameraToCenterDistance;
+
+ // Add a bit extra to avoid precision problems when a fragment's distance is exactly `furthestDistance`.
+ double farZ = furthestDistance * 1.01;
+
+ GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(fov, CGRectGetWidth(self.bounds) / CGRectGetHeight(self.bounds), 1, farZ);
+// CATransform3D projectionTransform = MGLTransform3DFromMatrix4(projectionMatrix);
+
+ CATransform3D projectionTransform = CATransform3DIdentity;
+ projectionTransform.m34 = -1.0 / (1.0 - furthestDistance * 0.5);
+ projectionTransform = CATransform3DRotate(projectionTransform, MGLRadiansFromDegrees(camera.pitch), -1, 0, 0);
+// self.annotationContainerView.layer.sublayerTransform = projectionTransform;
// Update the center of visible annotation views
for (id<MGLAnnotation> annotation in visibleAnnotations)
@@ -5086,6 +5140,12 @@ public:
[CATransaction commit];
}
+- (CATransform3D)projectionTransform {
+ mbgl::mat4 matrix;
+ _mbglMap->getProjMatrix(matrix);
+ return MGLTransform3DFromMat4(matrix);
+}
+
- (void)updateCalloutView
{
UIView <MGLCalloutView> *calloutView = self.calloutViewForSelectedAnnotation;