Skip to content

Commit

Permalink
Update Swift Playground to use import MapLibre (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
roblabs authored Jan 17, 2024
1 parent 3df876f commit 3587b03
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/.swiftpm
/.build
39 changes: 21 additions & 18 deletions MapLibreTest.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,28 @@

import UIKit
import PlaygroundSupport
import Mapbox
import MapLibre

// Create a map set its dimensions
let width: CGFloat = 640
let height: CGFloat = 480

let mapView = MGLMapView(frame: CGRect(x: 0, y: 0, width: width, height: height))
let mapView = MLNMapView(frame: CGRect(x: 0, y: 0, width: width, height: height))
mapView.frame = CGRect(x: 0, y: 0, width: width, height: height)

// shows the result of running the code this far
PlaygroundPage.current.liveView = mapView

// Hide logo & attribution button
mapView.logoView.isHidden = true
mapView.attributionButton.isHidden = true

// enable debugging tile features
mapView.debugMask = MGLMapDebugMaskOptions(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)
mapView.debugMask = MLNMapDebugMaskOptions(rawValue:
MLNMapDebugMaskOptions.collisionBoxesMask.rawValue + // Edges of glyphs and symbols
MLNMapDebugMaskOptions.timestampsMask.rawValue + // shows a timestamp indicating when it was loaded.
MLNMapDebugMaskOptions.tileBoundariesMask.rawValue + // Edges of tile boundaries
MLNMapDebugMaskOptions.tileInfoMask.rawValue // tile coordinate (x/y/z)
)

// Set Style
Expand All @@ -37,18 +40,18 @@ mapView.setCenter(CLLocationCoordinate2D(latitude: 0.0, longitude: 0.0), zoomLev

// MGLMapSnapshotter example code
var image: UIImage?
let camera = MGLMapCamera(lookingAtCenter: CLLocationCoordinate2D(latitude: 0, longitude: 0), altitude: 100, pitch: 75, heading: 45)
let camera = MLNMapCamera(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))
let options = MLNMapSnapshotOptions(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
}
let snapshotter = MLNMapSnapshotter(options: options)
// Awaiting https://github.com/maplibre/maplibre-native/issues/1979
//snapshotter.start { (snapshot, error) in
// if let error = error {
// fatalError(error.localizedDescription)
// }
//
// image = snapshot?.image
//}

PlaygroundPage.current.liveView = mapView
6 changes: 0 additions & 6 deletions MapLibreTest.playground/timeline.xctimeline

This file was deleted.

0 comments on commit 3587b03

Please sign in to comment.