summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Rex <julian.rex@mapbox.com>2019-10-03 17:23:27 -0400
committerJulian Rex <julian.rex@mapbox.com>2019-10-03 17:23:27 -0400
commitb48dc0c56867458a3fad798901f5e88d34a4cb14 (patch)
tree0e0d1c3332cc6d96a54ce7e8b608cb816b87ac28
parent2105fd14a88b66acbe35ebb787d68af5f0e0f259 (diff)
downloadqtlocation-mapboxgl-upstream/jrex/15695-coordinates.tar.gz
[macos] Fix for image scale in overlay.upstream/jrex/15695-coordinates
-rw-r--r--platform/darwin/src/MGLMapSnapshotter.mm13
1 files changed, 8 insertions, 5 deletions
diff --git a/platform/darwin/src/MGLMapSnapshotter.mm b/platform/darwin/src/MGLMapSnapshotter.mm
index b535178404..0dde94292c 100644
--- a/platform/darwin/src/MGLMapSnapshotter.mm
+++ b/platform/darwin/src/MGLMapSnapshotter.mm
@@ -36,8 +36,8 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64;
@interface MGLMapSnapshotOverlay() <MGLMapSnapshotProtocol>
-
-- (instancetype)initWithContext:(CGContextRef)context pointForFn:(mbgl::MapSnapshotter::PointForFn)pointForFn latLngForFn:(mbgl::MapSnapshotter::LatLngForFn)latLngForFn;
+@property (nonatomic, assign) CGFloat scale;
+- (instancetype)initWithContext:(CGContextRef)context scale:(CGFloat)scale pointForFn:(mbgl::MapSnapshotter::PointForFn)pointForFn latLngForFn:(mbgl::MapSnapshotter::LatLngForFn)latLngForFn;
@end
@@ -46,10 +46,11 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64;
mbgl::MapSnapshotter::LatLngForFn _latLngForFn;
}
-- (instancetype) initWithContext:(CGContextRef)context pointForFn:(mbgl::MapSnapshotter::PointForFn)pointForFn latLngForFn:(mbgl::MapSnapshotter::LatLngForFn)latLngForFn {
+- (instancetype) initWithContext:(CGContextRef)context scale:(CGFloat)scale pointForFn:(mbgl::MapSnapshotter::PointForFn)pointForFn latLngForFn:(mbgl::MapSnapshotter::LatLngForFn)latLngForFn {
self = [super init];
if (self) {
_context = context;
+ _scale = scale;
_pointForFn = pointForFn;
_latLngForFn = latLngForFn;
}
@@ -76,13 +77,13 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64;
- (NSPoint)pointForCoordinate:(CLLocationCoordinate2D)coordinate
{
mbgl::ScreenCoordinate sc = _pointForFn(MGLLatLngFromLocationCoordinate2D(coordinate));
- CGFloat height = (CGFloat)CGBitmapContextGetHeight(self.context);
+ CGFloat height = ((CGFloat)CGBitmapContextGetHeight(self.context))/self.scale;
return NSMakePoint(sc.x, height - sc.y);
}
- (CLLocationCoordinate2D)coordinateForPoint:(NSPoint)point
{
- CGFloat height = (CGFloat)CGBitmapContextGetHeight(self.context);
+ CGFloat height = ((CGFloat)CGBitmapContextGetHeight(self.context))/self.scale;
auto screenCoord = mbgl::ScreenCoordinate(point.x, height - point.y);
mbgl::LatLng latLng = _latLngForFn(screenCoord);
return MGLLocationCoordinate2DFromLatLng(latLng);
@@ -368,6 +369,7 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64;
if (currentContext && overlayHandler) {
MGLMapSnapshotOverlay *snapshotOverlay = [[MGLMapSnapshotOverlay alloc] initWithContext:currentContext
+ scale:scale
pointForFn:pointForFn
latLngForFn:latLngForFn];
CGContextSaveGState(snapshotOverlay.context);
@@ -451,6 +453,7 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64;
NSGraphicsContext *currentContext = [NSGraphicsContext currentContext];
if (currentContext && overlayHandler) {
MGLMapSnapshotOverlay *snapshotOverlay = [[MGLMapSnapshotOverlay alloc] initWithContext:currentContext.CGContext
+ scale:scale
pointForFn:pointForFn
latLngForFn:latLngForFn];
[currentContext saveGraphicsState];