Last active
February 7, 2017 13:28
-
-
Save fmo91/b792cefe1de8af0f0c70ff07981f0dfa to your computer and use it in GitHub Desktop.
An example on MapKitGoogleStyler library.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.swift | |
// MapKitGoogleStylerExample | |
// | |
// Created by Fernando Ortiz on 2/6/17. | |
// Copyright © 2017 Fernando Martín Ortiz. All rights reserved. | |
// | |
import UIKit | |
import MapKit | |
import MapKitGoogleStyler | |
class ViewController: UIViewController { | |
@IBOutlet weak var mapView: MKMapView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
mapView.delegate = self | |
configureTileOverlay() | |
} | |
private func configureTileOverlay() { | |
// We first need to have the path of the overlay configuration JSON | |
guard let overlayFileURLString = Bundle.main.path(forResource: "overlay", ofType: "json") else { | |
return | |
} | |
let overlayFileURL = URL(fileURLWithPath: overlayFileURLString) | |
// 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) | |
} | |
} | |
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) | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment