Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed example project #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions Example/MapKitGoogleStyler/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,42 @@ import MapKit
import MapKitGoogleStyler

class ViewController: UIViewController {

@IBOutlet weak var mapView: MKMapView!

override func viewDidLoad() {
super.viewDidLoad()

guard let jsonURL = Bundle.main.url(forResource: "MapStyle", withExtension: "json") else {
print("Invalid json url")
mapView.delegate = self
configureTileOverlay()
}

func configureTileOverlay() {
// We first need to have the path of the overlay configuration JSON
guard let overlayFileURLString = Bundle.main.path(forResource: "MapStyle", ofType: "json") else {
return
}
let overlayFileURL = URL(fileURLWithPath: overlayFileURLString)

do {
try mapView.customize(withJSONFileURL: jsonURL)
} catch let error {
print("Error! \(error)")
// After that, you can create the tile overlay using MapKitGoogleStyler
guard let tileOverlay = try? MapKitGoogleStyler.buildOverlay(with: overlayFileURL) else {
return
}

// And finally add it to your MKMapView
mapView.add(tileOverlay)
}
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
extension ViewController: MKMapViewDelegate {
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
// This is the final step. This code can be copied and pasted into your project
// without thinking on it so much. It simply instantiates a MKTileOverlayRenderer
// for displaying the tile overlay.
if let tileOverlay = overlay as? MKTileOverlay {
return MKTileOverlayRenderer(tileOverlay: tileOverlay)
} else {
return MKOverlayRenderer(overlay: overlay)
}
}

}