Latest 1.2.0
Homepage https://github.com/inkyfox/RxMapKit
License MIT
Platforms ios 8.0, requires ARC
Dependencies RxSwift, RxCocoa
Authors

Swift
Carthage compatible
Version
License
Platform

RxMapKit is a RxSwift wrapper for MapKit

Example Usages

Setup MKMapView

// Setup MKMapview from Interface Builder
@IBOutlet weak var mapView: MKMapView!

or

// Setup MKMapview
let mapView = MKMapView(frame: self.view.bounds)
self.view.addSubview(mapView)

Observing properties

// Camera position

mapView.rx.regionDidChange.asDriver()
    .drive(onNext: { print("Did region change: ($0.region) isAnimated ($0.isAnimated)") })
    .addDisposableTo(disposeBag)

// Marker tapped

mapView.rx.didTapMarker.asDriver()
    .drive(onNext: { print("Did tap marker: ($0)") })
    .addDisposableTo(disposeBag)

// Update marker icon 

mapView.rx.didSelectAnnotationView.asDriver()
    .drive(onNext: { $0.image = #imageLiteral(resourceName: "marker_selected") })
    .addDisposableTo(disposeBag)

mapView.rx.didDeselectAnnotationView.asDriver()
    .drive(onNext: { $0.image = #imageLiteral(resourceName: "marker_normal") })
    .addDisposableTo(disposeBag)

Binding properties

// Camera animations

button.rx.tap
    .map { MKMapCamera(lookingAtCenter: center, fromDistance: 50000, pitch: 30, heading: 45) }
    .bindTo(mapView.rx.cameraToAnimate)
    .addDisposableTo(disposeBag)

button.rx.tap
    .map { CLLocationCoordinate2D(latitude: 33.3659424, longitude: 126.3476852) }
    .bindTo(mapView.rx.centerToAnimate)
    .addDisposableTo(disposeBag)

button.rx.tap
    .map { [annotation0, annotaion1] }
    .bindTo(mapView.rx.annotationsToShowToAnimate)
    .addDisposableTo(disposeBag)

// Properties

button.rx.tap
    .map { .satellite }
    .bindTo(mapView.rx.mapType)
    .addDisposableTo(disposeBag)

button.rx.tap
    .map { false }
    .bindTo(mapView.rx.showsTraffic)
    .addDisposableTo(disposeBag)

Delegates which have a return value

//  func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView?

mapView.rx.handleViewForAnnotation { (mapView, annotation) in
    if let _ = annotation as? MKUserLocation {
        return nil
    } else {
        let view = mapView.dequeueReusableAnnotationView(withIdentifier: "reusableIdentifier") ??
            MKAnnotationView(annotation: annotation, reuseIdentifier: "reusableIdentifier")
        view.image = #imageLiteral(resourceName: "marker_normal")
        view.canShowCallout = true
        return view
    }
}

// func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer

mapView.rx.handleRendererForOverlay { (mapView, overlay) in
    if overlay is MKCircle {
        let renderer = MKCircleRenderer(overlay: overlay)
        renderer.strokeColor = UIColor.green.withAlphaComponent(0.8)
        renderer.lineWidth = 4
        renderer.fillColor = UIColor.green.withAlphaComponent(0.3)
        return renderer
    } else {
        return MKOverlayRenderer(overlay: overlay)
    }
}

Installation

CocoaPods

pod 'RxMapKit'

Carthage

github "inkyfox/RxMapKit"

Requirements

Author

Yongha Yoo

License

MIT

Latest podspec

{
    "name": "RxMapKit",
    "version": "1.2.0",
    "summary": "RxSwift reactive wrapper for MapKit.",
    "homepage": "https://github.com/inkyfox/RxMapKit",
    "license": "MIT",
    "authors": {
        "Yongha Yoo": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/inkyfox/RxMapKit.git",
        "tag": "1.2.0"
    },
    "requires_arc": true,
    "source_files": "Sources/*.swift",
    "dependencies": {
        "RxSwift": [
            "~> 4.2"
        ],
        "RxCocoa": [
            "~> 4.2"
        ]
    },
    "swift_version": "4.1"
}

Pin It on Pinterest

Share This