diff options
Diffstat (limited to 'platform')
-rw-r--r-- | platform/macos/app/Base.lproj/MainMenu.xib | 16 | ||||
-rw-r--r-- | platform/macos/app/Base.lproj/MapDocument.xib | 6 | ||||
-rw-r--r-- | platform/macos/app/MapDocument.m | 68 | ||||
-rw-r--r-- | platform/macos/config.cmake | 4 | ||||
-rw-r--r-- | platform/macos/macos.xcodeproj/project.pbxproj | 8 | ||||
-rw-r--r-- | platform/macos/src/Mapbox.h | 1 |
6 files changed, 95 insertions, 8 deletions
diff --git a/platform/macos/app/Base.lproj/MainMenu.xib b/platform/macos/app/Base.lproj/MainMenu.xib index 9a8cf05c16..9a53ba9d4b 100644 --- a/platform/macos/app/Base.lproj/MainMenu.xib +++ b/platform/macos/app/Base.lproj/MainMenu.xib @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> -<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="12120" systemVersion="16E195" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct"> +<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="12121" systemVersion="16E195" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct"> <dependencies> - <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="12120"/> + <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="12121"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> </dependencies> <objects> @@ -128,6 +128,12 @@ <action selector="revertDocumentToSaved:" target="-1" id="iJ3-Pv-kwq"/> </connections> </menuItem> + <menuItem title="Save snapshot" id="vjX-0E-kLO"> + <modifierMask key="keyEquivalentModifierMask"/> + <connections> + <action selector="takeSnapshot:" target="-1" id="H06-sU-n4U"/> + </connections> + </menuItem> <menuItem isSeparatorItem="YES" id="aJh-i4-bef"/> <menuItem title="Page Setup…" keyEquivalent="P" id="qIS-W8-SiK"> <connections> @@ -654,7 +660,7 @@ CA <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES"/> <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/> <rect key="contentRect" x="109" y="131" width="350" height="84"/> - <rect key="screenRect" x="0.0" y="0.0" width="1280" height="777"/> + <rect key="screenRect" x="0.0" y="0.0" width="1680" height="1027"/> <view key="contentView" id="eA4-n3-qPe"> <rect key="frame" x="0.0" y="0.0" width="350" height="84"/> <autoresizingMask key="autoresizingMask"/> @@ -730,7 +736,7 @@ CA <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES" utility="YES"/> <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/> <rect key="contentRect" x="830" y="430" width="400" height="300"/> - <rect key="screenRect" x="0.0" y="0.0" width="1280" height="777"/> + <rect key="screenRect" x="0.0" y="0.0" width="1680" height="1027"/> <view key="contentView" id="8ha-hw-zOD"> <rect key="frame" x="0.0" y="0.0" width="400" height="300"/> <autoresizingMask key="autoresizingMask"/> @@ -739,7 +745,7 @@ CA <rect key="frame" x="-1" y="20" width="402" height="281"/> <clipView key="contentView" id="J9U-Yx-o2S"> <rect key="frame" x="1" y="0.0" width="400" height="280"/> - <autoresizingMask key="autoresizingMask"/> + <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <subviews> <tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" autosaveColumns="NO" headerView="MAZ-Iq-hBi" id="Ato-Vu-HYT"> <rect key="frame" x="0.0" y="0.0" width="423" height="257"/> diff --git a/platform/macos/app/Base.lproj/MapDocument.xib b/platform/macos/app/Base.lproj/MapDocument.xib index d95f21b2e9..0394f38533 100644 --- a/platform/macos/app/Base.lproj/MapDocument.xib +++ b/platform/macos/app/Base.lproj/MapDocument.xib @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> -<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="12120" systemVersion="16E195" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES"> +<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="12121" systemVersion="16E195" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES"> <dependencies> - <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="12120"/> + <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="12121"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> </dependencies> <objects> @@ -48,7 +48,7 @@ <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES" fullSizeContentView="YES"/> <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/> <rect key="contentRect" x="388" y="211" width="642" height="480"/> - <rect key="screenRect" x="0.0" y="0.0" width="1280" height="777"/> + <rect key="screenRect" x="0.0" y="0.0" width="1680" height="1027"/> <view key="contentView" id="TuG-C5-zLS"> <rect key="frame" x="0.0" y="0.0" width="642" height="480"/> <autoresizingMask key="autoresizingMask"/> diff --git a/platform/macos/app/MapDocument.m b/platform/macos/app/MapDocument.m index d6855d3ff2..406ff0ca9d 100644 --- a/platform/macos/app/MapDocument.m +++ b/platform/macos/app/MapDocument.m @@ -3,6 +3,7 @@ #import "AppDelegate.h" #import "LimeGreenStyleLayer.h" #import "DroppedPinAnnotation.h" +#import "MGLMapsnapshotter.h" #import "MGLStyle+MBXAdditions.h" #import "MGLVectorSource+MGLAdditions.h" @@ -73,6 +74,9 @@ NS_ARRAY_OF(id <MGLAnnotation>) *MBXFlattenedShapes(NS_ARRAY_OF(id <MGLAnnotatio BOOL _isTouringWorld; BOOL _isShowingPolygonAndPolylineAnnotations; BOOL _isShowingAnimatedAnnotation; + + // Snapshotter + MGLMapSnapshotter* snapshotter; } #pragma mark Lifecycle @@ -153,6 +157,67 @@ NS_ARRAY_OF(id <MGLAnnotation>) *MBXFlattenedShapes(NS_ARRAY_OF(id <MGLAnnotatio camera.heading, camera.pitch]]; } +#pragma mark File methods + +- (IBAction)takeSnapshot:(id)sender { + MGLMapCamera *camera = self.mapView.camera; + + MGLMapSnapshotOptions* options = [[MGLMapSnapshotOptions alloc] initWithStyleURL:self.mapView.styleURL camera:camera size:self.mapView.bounds.size]; + options.zoom = self.mapView.zoomLevel; + + // Create and start the snapshotter + snapshotter = [[MGLMapSnapshotter alloc] initWithOptions:options]; + [snapshotter startWithCompletionHandler: ^(NSImage *image, NSError *error) { + if (error) { + NSLog(@"Could not load snapshot: %@", [error localizedDescription]); + } else { + NSWindow* window = [[[self windowControllers] objectAtIndex:0] window]; + + NSString* newName = [[@"snapshot" stringByDeletingPathExtension] stringByAppendingPathExtension:@"png"]; + + // Set the default name for the file and show the panel. + NSSavePanel* panel = [NSSavePanel savePanel]; + [panel setNameFieldStringValue:newName]; + [panel beginSheetModalForWindow:window completionHandler:^(NSInteger result){ + if (result == NSFileHandlingPanelOKButton) { + // Write the contents in the new format. + NSURL* fileURL = [panel URL]; + + NSBitmapImageRep *bitmapRep = nil; + for (NSImageRep *imageRep in [image representations]) { + if ([imageRep isKindOfClass:[NSBitmapImageRep class]]){ + bitmapRep = (NSBitmapImageRep *)imageRep; + break; // stop on first bitmap rep we find + } + } + + if (!bitmapRep) { + bitmapRep = [NSBitmapImageRep imageRepWithData:[image TIFFRepresentation]]; + + } + + NSString *extension = [[fileURL pathExtension] lowercaseString]; + NSBitmapImageFileType fileType; + if ([extension isEqualToString:@"png"]) { + fileType = NSPNGFileType; + } else if ([extension isEqualToString:@"gif"]) { + fileType = NSGIFFileType; + } else if ([extension isEqualToString:@"jpg"] || [extension isEqualToString:@"jpeg"]) { + fileType = NSJPEGFileType; + } else { + fileType = NSTIFFFileType; + } + + NSData *imageData = [bitmapRep representationUsingType:fileType properties:@{}]; + [imageData writeToURL:fileURL atomically:NO]; + } + }]; + + } + snapshotter = nil; + }]; +} + #pragma mark View methods - (IBAction)showStyle:(id)sender { @@ -963,6 +1028,9 @@ NS_ARRAY_OF(id <MGLAnnotation>) *MBXFlattenedShapes(NS_ARRAY_OF(id <MGLAnnotatio if (menuItem.action == @selector(giveFeedback:)) { return YES; } + if (menuItem.action == @selector(takeSnapshot:)) { + return !(snapshotter && [snapshotter isLoading]); + } return NO; } diff --git a/platform/macos/config.cmake b/platform/macos/config.cmake index 1d471e1a8b..bb2cc9ac1c 100644 --- a/platform/macos/config.cmake +++ b/platform/macos/config.cmake @@ -53,6 +53,10 @@ macro(mbgl_platform_core) PRIVATE platform/default/mbgl/gl/headless_display.hpp PRIVATE platform/darwin/src/headless_display_cgl.cpp + # Snapshotting + PRIVATE platform/default/mbgl/map/map_snapshotter.cpp + PRIVATE platform/default/mbgl/map/map_snapshotter.hpp + # Thread pool PRIVATE platform/default/mbgl/util/shared_thread_pool.cpp PRIVATE platform/default/mbgl/util/shared_thread_pool.hpp diff --git a/platform/macos/macos.xcodeproj/project.pbxproj b/platform/macos/macos.xcodeproj/project.pbxproj index 34b08c0035..40bbb07e8b 100644 --- a/platform/macos/macos.xcodeproj/project.pbxproj +++ b/platform/macos/macos.xcodeproj/project.pbxproj @@ -81,6 +81,8 @@ 558DE7A61E56161C00C7916D /* MGLFoundation_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 558DE7A41E56161C00C7916D /* MGLFoundation_Private.h */; }; 558DE7A71E56161C00C7916D /* MGLFoundation.mm in Sources */ = {isa = PBXBuildFile; fileRef = 558DE7A51E56161C00C7916D /* MGLFoundation.mm */; }; 55E2AD111E5B0A6900E8C587 /* MGLOfflineStorageTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 55E2AD101E5B0A6900E8C587 /* MGLOfflineStorageTests.mm */; }; + 92092EF01F5EB10E00AF5130 /* MGLMapSnapshotter.h in Headers */ = {isa = PBXBuildFile; fileRef = 92092EEE1F5EB10E00AF5130 /* MGLMapSnapshotter.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 92092EF11F5EB10E00AF5130 /* MGLMapSnapshotter.mm in Sources */ = {isa = PBXBuildFile; fileRef = 92092EEF1F5EB10E00AF5130 /* MGLMapSnapshotter.mm */; }; 920A3E591E6F859D00C16EFC /* MGLSourceQueryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 920A3E581E6F859D00C16EFC /* MGLSourceQueryTests.m */; }; 92F2C3EB1F0E3A1900268EC0 /* MGLRendererFrontend.h in Headers */ = {isa = PBXBuildFile; fileRef = 92F2C3EA1F0E3A1900268EC0 /* MGLRendererFrontend.h */; }; 96E027311E57C9A7004B8E66 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 96E027331E57C9A7004B8E66 /* Localizable.strings */; }; @@ -354,6 +356,8 @@ 55D9B4B01D005D3900C1CCE2 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; }; 55E2AD101E5B0A6900E8C587 /* MGLOfflineStorageTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLOfflineStorageTests.mm; path = ../../darwin/test/MGLOfflineStorageTests.mm; sourceTree = "<group>"; }; 55FE0E8D1D100A0900FD240B /* config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = config.xcconfig; path = ../../build/macos/config.xcconfig; sourceTree = "<group>"; }; + 92092EEE1F5EB10E00AF5130 /* MGLMapSnapshotter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLMapSnapshotter.h; sourceTree = "<group>"; }; + 92092EEF1F5EB10E00AF5130 /* MGLMapSnapshotter.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLMapSnapshotter.mm; sourceTree = "<group>"; }; 920A3E581E6F859D00C16EFC /* MGLSourceQueryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLSourceQueryTests.m; sourceTree = "<group>"; }; 92F2C3EA1F0E3A1900268EC0 /* MGLRendererFrontend.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLRendererFrontend.h; sourceTree = "<group>"; }; 966091701E5BBFF700A9A03B /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Localizable.strings; sourceTree = "<group>"; }; @@ -1048,6 +1052,8 @@ 558DE7A51E56161C00C7916D /* MGLFoundation.mm */, DAE6C34D1CC31E0400DB3429 /* MGLMapCamera.h */, DAE6C36E1CC31E2A00DB3429 /* MGLMapCamera.mm */, + 92092EEE1F5EB10E00AF5130 /* MGLMapSnapshotter.h */, + 92092EEF1F5EB10E00AF5130 /* MGLMapSnapshotter.mm */, DD0902B01DB1AC6400C5BDCE /* MGLNetworkConfiguration.h */, DD0902AF1DB1AC6400C5BDCE /* MGLNetworkConfiguration.m */, 92F2C3EA1F0E3A1900268EC0 /* MGLRendererFrontend.h */, @@ -1111,6 +1117,7 @@ DA8F259C1D51CB000010E6B5 /* MGLStyleValue_Private.h in Headers */, DAE6C35B1CC31E0400DB3429 /* MGLAnnotation.h in Headers */, DAE6C3B61CC31EF300DB3429 /* MGLMapView_Private.h in Headers */, + 92092EF01F5EB10E00AF5130 /* MGLMapSnapshotter.h in Headers */, 3527428D1D4C24AB00A1ECE6 /* MGLCircleStyleLayer.h in Headers */, DA00FC8A1D5EEAC3009AABC8 /* MGLAttributionInfo.h in Headers */, DAE6C3B21CC31EF300DB3429 /* MGLAttributionButton.h in Headers */, @@ -1403,6 +1410,7 @@ buildActionMask = 2147483647; files = ( 07A019EF1ED665CD00ACD43E /* MGLImageSource.mm in Sources */, + 92092EF11F5EB10E00AF5130 /* MGLMapSnapshotter.mm in Sources */, 40ABDB561DB0022100372083 /* NSImage+MGLAdditions.mm in Sources */, DAE6C3901CC31E2A00DB3429 /* MGLPointAnnotation.mm in Sources */, DAE6C3981CC31E2A00DB3429 /* NSBundle+MGLAdditions.m in Sources */, diff --git a/platform/macos/src/Mapbox.h b/platform/macos/src/Mapbox.h index e4ad258b6e..a082a4771e 100644 --- a/platform/macos/src/Mapbox.h +++ b/platform/macos/src/Mapbox.h @@ -56,3 +56,4 @@ FOUNDATION_EXPORT MGL_EXPORT const unsigned char MapboxVersionString[]; #import "NSValue+MGLAdditions.h" #import "MGLStyleValue.h" #import "MGLAttributionInfo.h" +#import "MGLMapSnapshotter.h" |