diff options
author | Fabian Guerra Soto <fabian.guerra@mapbox.com> | 2017-10-04 10:03:03 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-04 10:03:03 -0400 |
commit | f01588cac78b5e5411385faa451080a74320500b (patch) | |
tree | 1f0540cf5c71475f0ae6714d70b909338fed9b5f /platform/macos/app/MapDocument.m | |
parent | 6a846ce5a8ff1d62f4eafa3ef5bd0427096ca9e6 (diff) | |
download | qtlocation-mapboxgl-f01588cac78b5e5411385faa451080a74320500b.tar.gz |
[ios, macos] Improve snap shotter documentation. (#10020)
* [ios, macos] Improve snap shotter documentation.
* [macos] Save snapshots in correct format
* [macos] Renamed snapshot item to Export Image
* [ios, macos] Clarify Snapshotter documentation.
* [ios] Fix snapshot scale
* [macOS] Fix snapshotter 4x scaling.
* [ios] Fix snapshotter final image scale.
* [ios, macos] Update snapshotter size documentation.
* [ios, macos] Throw an exception when the snapshotter has already started.
* [ios, macos] Add snapshotter header example.
* [ios, macos] Use one of the predefined Foundation's exception names.
Diffstat (limited to 'platform/macos/app/MapDocument.m')
-rw-r--r-- | platform/macos/app/MapDocument.m | 51 |
1 files changed, 25 insertions, 26 deletions
diff --git a/platform/macos/app/MapDocument.m b/platform/macos/app/MapDocument.m index 36ca4ad228..feef53062b 100644 --- a/platform/macos/app/MapDocument.m +++ b/platform/macos/app/MapDocument.m @@ -162,50 +162,49 @@ NS_ARRAY_OF(id <MGLAnnotation>) *MBXFlattenedShapes(NS_ARRAY_OF(id <MGLAnnotatio - (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; + MGLMapSnapshotOptions *options = [[MGLMapSnapshotOptions alloc] initWithStyleURL:self.mapView.styleURL camera:camera size:self.mapView.bounds.size]; + options.zoomLevel = self.mapView.zoomLevel; // Create and start the snapshotter snapshotter = [[MGLMapSnapshotter alloc] initWithOptions:options]; - [snapshotter startWithCompletionHandler: ^(NSImage *image, NSError *error) { + [snapshotter startWithCompletionHandler:^(NSImage *image, NSError *error) { if (error) { - NSLog(@"Could not load snapshot: %@", [error localizedDescription]); + 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){ + NSSavePanel *panel = [NSSavePanel savePanel]; + panel.nameFieldStringValue = [self.mapView.styleURL.lastPathComponent.stringByDeletingPathExtension stringByAppendingPathExtension:@"png"]; + panel.allowedFileTypes = [@[(NSString *)kUTTypePNG] arrayByAddingObjectsFromArray:[NSBitmapImageRep imageUnfilteredTypes]]; + + [panel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result) { if (result == NSFileHandlingPanelOKButton) { // Write the contents in the new format. - NSURL* fileURL = [panel URL]; + NSURL *fileURL = panel.URL; - NSBitmapImageRep *bitmapRep = nil; - for (NSImageRep *imageRep in [image representations]) { - if ([imageRep isKindOfClass:[NSBitmapImageRep class]]){ + NSBitmapImageRep *bitmapRep; + 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]]; - + bitmapRep = [NSBitmapImageRep imageRepWithData:image.TIFFRepresentation]; } - NSString *extension = [[fileURL pathExtension] lowercaseString]; - NSBitmapImageFileType fileType; - if ([extension isEqualToString:@"png"]) { + CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileURL.pathExtension, NULL /* inConformingToUTI */); + NSBitmapImageFileType fileType = NSTIFFFileType; + if (UTTypeConformsTo(uti, kUTTypePNG)) { fileType = NSPNGFileType; - } else if ([extension isEqualToString:@"gif"]) { - fileType = NSGIFFileType; - } else if ([extension isEqualToString:@"jpg"] || [extension isEqualToString:@"jpeg"]) { - fileType = NSJPEGFileType; - } else { - fileType = NSTIFFFileType; + } else if (UTTypeConformsTo(uti, kUTTypeGIF)) { + fileType = NSGIFFileType; + } else if (UTTypeConformsTo(uti, kUTTypeJPEG2000)) { + fileType = NSJPEG2000FileType; + } else if (UTTypeConformsTo(uti, kUTTypeJPEG)) { + fileType = NSJPEGFileType; + } else if (UTTypeConformsTo(uti, kUTTypeBMP)) { + fileType = NSBitmapImageFileTypeBMP; } NSData *imageData = [bitmapRep representationUsingType:fileType properties:@{}]; |