diff --git a/MapLibreTest.playground/Contents.swift b/MapLibreTest.playground/Contents.swift index f92c056..cac87aa 100644 --- a/MapLibreTest.playground/Contents.swift +++ b/MapLibreTest.playground/Contents.swift @@ -2,7 +2,8 @@ * The MapLibre Test Playground demonstrates basic rendering of a Mapbox style using the current MapLibre binary. * Useful for testing the data in the`binaryTarget[]` in this Swift Package repo. * Downloads the MapLibre `.xcframework` and creates a simple map, thereby testing the Swift Package Manager workflow. - * Add your style for basic rendering tests + * Add your style for basic rendering tests. + * Using the same style, demonstrate how to use `MGLMapSnapshotter`. */ import UIKit @@ -10,8 +11,8 @@ import PlaygroundSupport import Mapbox // Create a map set its dimensions -let width: CGFloat = 600 -let height: CGFloat = 400 +let width: CGFloat = 640 +let height: CGFloat = 480 let mapView = MGLMapView(frame: CGRect(x: 0, y: 0, width: width, height: height)) mapView.frame = CGRect(x: 0, y: 0, width: width, height: height) @@ -22,16 +23,32 @@ mapView.attributionButton.isHidden = true // enable debugging tile features mapView.debugMask = MGLMapDebugMaskOptions(rawValue: - // Edges of tile boundaries - MGLMapDebugMaskOptions.tileBoundariesMask.rawValue + - // tile coordinate (x/y/z) - MGLMapDebugMaskOptions.tileInfoMask.rawValue + MGLMapDebugMaskOptions.collisionBoxesMask.rawValue + // Edges of glyphs and symbols + MGLMapDebugMaskOptions.timestampsMask.rawValue + // shows a timestamp indicating when it was loaded. + MGLMapDebugMaskOptions.tileBoundariesMask.rawValue + // Edges of tile boundaries + MGLMapDebugMaskOptions.tileInfoMask.rawValue // tile coordinate (x/y/z) ) // Set Style -let styleJSON = "https://raw.githubusercontent.com/roblabs/openmaptiles-ios-demo/master/OSM2VectorTiles/styles/geography-class.GitHub.json" +var styleJSON = "https://demotiles.maplibre.org/style.json" mapView.styleURL = URL(string: styleJSON) -mapView.setCenter(CLLocationCoordinate2D(latitude: 0.0, longitude: 0.0), zoomLevel: 2, animated: false) +mapView.setCenter(CLLocationCoordinate2D(latitude: 0.0, longitude: 0.0), zoomLevel: 3, animated: false) + +// MGLMapSnapshotter example code +var image: UIImage? +let camera = MGLMapCamera(lookingAtCenter: CLLocationCoordinate2D(latitude: 0, longitude: 0), altitude: 100, pitch: 75, heading: 45) + +let options = MGLMapSnapshotOptions(styleURL: URL(string: styleJSON), camera: camera, size: CGSize(width: width, height: height)) +options.zoomLevel = mapView.zoomLevel + +let snapshotter = MGLMapSnapshotter(options: options) +snapshotter.start { (snapshot, error) in + if let error = error { + fatalError(error.localizedDescription) + } + + image = snapshot?.image +} PlaygroundPage.current.liveView = mapView diff --git a/README.md b/README.md index 85598e4..ed07d86 100644 --- a/README.md +++ b/README.md @@ -43,4 +43,5 @@ When you download this repo there is a Swift Playground that allows you to chang * Download this repo * Navigate to the folder where you `clone`d, and open `Package.swift` in at least Xcode 12. -* Run Playground by choosing `Editor` > `Run Playground` or `⇧⌘⏎` +* Run Playground by choosing `Editor` > `Run Playground` or `⇧-⌘-⏎` +* See issue [maplibre-gl-native-distribution#8](https://github.com/maplibre/maplibre-gl-native-distribution/issues/8) for screenshots of the MapLibre for Swift Playgrounds in action.