Git Product home page Git Product logo

windyswift's Introduction

WindySwift

Swift Version PackageManager Platforms License Twitter: @thepeaklab

WindySwift is a wrapper for windy.com written in Swift for the iOS and macOS platform.

Usage

  • Add WindySwift Swift Package to Xcode
  • Add a UIView to your Storyboard and change the class to WindyMapView.

  • Create an @IBOutlet in your ViewController
@IBOutlet var mapView: WindyMapView!
  • Initialize your WindyMapView in viewDidLoad()
override func viewDidLoad() {
    super.viewDidLoad()

    mapView.delegate = self
    mapView.initialize(options: WindyInitOptions(key: "<YOUR Windy Key>",
                                                 lat: 53.1392144,
                                                 lon: 8.2057949,
                                                 zoom: 6))

}

Region

Move center to coordinate

let randomLat = Double.random(in: 47...53)
let randomLng = Double.random(in: 7...12)
let coordinate = CLLocationCoordinate2D(latitude: randomLat, longitude: randomLng)
mapView.panTo(coordinate: coordinate, options: .animate(true))

Change zoom level

let zoomLevel = Int.random(in: 0...20)
mapView.setZoom(zoom: zoomLevel, options: .animate(true))

Fit Bounds

Fit the map, to that a list of coordinates are visible.

let coordinates = [
    CLLocationCoordinate2D(latitude: 53.528740, longitude: 8.452565),
    CLLocationCoordinate2D(latitude: 53.505438, longitude: 8.476923),
    CLLocationCoordinate2D(latitude: 53.488712, longitude: 8.410969),
    CLLocationCoordinate2D(latitude: 53.456613, longitude: 8.477863),
    CLLocationCoordinate2D(latitude: 53.449079, longitude: 8.425022),
    CLLocationCoordinate2D(latitude: 53.415919, longitude: 8.468630),
    CLLocationCoordinate2D(latitude: 53.406520, longitude: 8.394845)
]
mapView.fitBounds(coordinates: coordinates)

Get current map center coordinate

mapView.getCenter { coordinate in
    guard let coordinate = coordinate else {
        print("no center")
        return
    }
    print("center is at \(coordinate)")
}

Annotations

  • Subclass WindyMapAnnotation to create custom annotation.
class CustomAnnotation: WindyMapAnnotation {

    init(coordinate: CLLocationCoordinate2D) {
        let mapIconRoratePath = Bundle.main.path(forResource: "sample", ofType: "gif")!
        super.init(coordinate: coordinate, icon: WindyIcon(icon: .url(url: mapIconRoratePath)))
    }

}
  • Add Annotation
let coordinate = CLLocationCoordinate2D(latitude: 53.141063, longitude: 8.230920)
let annotation = RotateWindyAnnotation(coordinate: coordinate)
mapView.addAnnotation(annotation)
// or add multiple using addAnnotations(_ annotations: [WindyMapAnnotation])
  • Implement Delegate
extension ViewController: WindyMapViewDelegate {

    func windyMapView(_ windyMapView: WindyMapView, viewFor annotation: WindyMapAnnotation) -> WindyMapAnnotationView? {
        switch annotation {
        case let customAnnotation as CustomAnnotation:
            let annotationView = WindyMapAnnotationView(annotation: customAnnotation, icon: customAnnotation.icon)
            return annotationView
        default:
            return nil
        }
    }

}
  • Remove Annotation
// remove all annotations
mapView.removeAnnotations(mapView.annotations)

// or remove single annotation
removeAnnotation(_ annotation: WindyMapAnnotation)
  • Convert annotation to center point (point center, not coordinate center)
windyMapView.convert(annotation) { point in
    print("annotation is at \(point)")
}

WindyMapViewDelegate

func windyMapViewZoomDidInitialize(_ windyMapView: WindyMapView)

func windyMapViewZoomDidStart(_ windyMapView: WindyMapView)
func windyMapViewZoomDidEnd(_ windyMapView: WindyMapView)

func windyMapViewMoveDidStart(_ windyMapView: WindyMapView)
func windyMapViewMoveDidEnd(_ windyMapView: WindyMapView)

func windyMapViewDidZoom(_ windyMapView: WindyMapView)
func windyMapViewDidMove(_ windyMapView: WindyMapView)

func windyMapView(_ windyMapView: WindyMapView, viewFor: WindyMapAnnotation) -> WindyMapAnnotationView?

func windyMapView(_ windyMapView: WindyMapView, didSelect annotationView: WindyMapAnnotationView)

Need Help?

Please submit an issue on GitHub.

License

This project is licensed under the terms of the MIT license. See the LICENSE file.

windyswift's People

Contributors

cpageler93 avatar grumpyshoe avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.