Skip to content

Commit

Permalink
feat: constructed rough RoutePoint, Route and RoutMapView structs
Browse files Browse the repository at this point in the history
added basic route stuct that holds coordinates represented as routePoints as well as built helper functions for bounding box calculations
  • Loading branch information
daiigr committed Mar 1, 2024
1 parent 66020b0 commit 4b1001b
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 9 deletions.
8 changes: 8 additions & 0 deletions windrider-ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
652D84312B9200B100AE8CCD /* RouteMapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 652D84302B9200B100AE8CCD /* RouteMapView.swift */; };
652D84332B92019B00AE8CCD /* Route.swift in Sources */ = {isa = PBXBuildFile; fileRef = 652D84322B92019B00AE8CCD /* Route.swift */; };
653CDEE62B909823000D4E8B /* windrider_iosApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 653CDEE52B909823000D4E8B /* windrider_iosApp.swift */; };
653CDEEC2B909825000D4E8B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 653CDEEB2B909825000D4E8B /* Assets.xcassets */; };
653CDEEF2B909825000D4E8B /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 653CDEEE2B909825000D4E8B /* Preview Assets.xcassets */; };
Expand Down Expand Up @@ -37,6 +39,8 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
652D84302B9200B100AE8CCD /* RouteMapView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RouteMapView.swift; sourceTree = "<group>"; };
652D84322B92019B00AE8CCD /* Route.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Route.swift; sourceTree = "<group>"; };
653CDEE22B909823000D4E8B /* windrider-ios.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "windrider-ios.app"; sourceTree = BUILT_PRODUCTS_DIR; };
653CDEE52B909823000D4E8B /* windrider_iosApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = windrider_iosApp.swift; sourceTree = "<group>"; };
653CDEEB2B909825000D4E8B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand Down Expand Up @@ -107,6 +111,8 @@
655D4EAE2B90C072008B6B2B /* ConditionPreviewView.swift */,
655D4EB02B90C250008B6B2B /* WindCondition.swift */,
655D4EB22B90C4BD008B6B2B /* ContentView.swift */,
652D84302B9200B100AE8CCD /* RouteMapView.swift */,
652D84322B92019B00AE8CCD /* Route.swift */,
);
path = "windrider-ios";
sourceTree = "<group>";
Expand Down Expand Up @@ -269,6 +275,8 @@
655D4EAD2B90BAC5008B6B2B /* MapView.swift in Sources */,
655D4EB32B90C4BD008B6B2B /* ContentView.swift in Sources */,
653CDEE62B909823000D4E8B /* windrider_iosApp.swift in Sources */,
652D84332B92019B00AE8CCD /* Route.swift in Sources */,
652D84312B9200B100AE8CCD /* RouteMapView.swift in Sources */,
655D4EAF2B90C072008B6B2B /* ConditionPreviewView.swift in Sources */,
655D4EB12B90C250008B6B2B /* WindCondition.swift in Sources */,
);
Expand Down
11 changes: 2 additions & 9 deletions windrider-ios/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,10 @@ import SwiftUI

struct ContentView: View {
var condition: WindCondition

let randomRoute = Route(points: [RoutePoint(latitude: 53.22240, longitude: 6.53929, direction: 0, timestamp: Date()), RoutePoint(latitude: 53.22240, longitude: 6.53929, direction: 0, timestamp: Date())])
var body: some View {
ZStack{
MapView()
VStack{
Spacer()
ConditionPreviewView(condition: condition)
.background()
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))

}
RouteMapView(route: randomRoute)
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions windrider-ios/MapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,12 @@ struct MapView: View {
}
}
}

// PreviewProvider to see the design in Xcode's Canvas
struct MapView_Previews: PreviewProvider {
static var previews: some View {
MapView()
}


}
61 changes: 61 additions & 0 deletions windrider-ios/Route.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// Route.swift
// windrider-ios
//
// Created by Daniel Grbac Bravo on 01/03/2024.
//

import Foundation

struct Route: Codable {
let routeId: String?
let points: [RoutePoint]

init(points: [RoutePoint]) {
self.routeId = nil
self.points = points
}

// finds the bounding box of the route
// returns the two points that define the bounding box
public func caluateBoundingBox(route: Route) -> [RoutePoint]{
var minLat: Double = 90
var maxLat: Double = -90
var minLon: Double = 180
var maxLon: Double = -180
for point in route.points {
if point.latitude < minLat {
minLat = point.latitude
}
if point.latitude > maxLat {
maxLat = point.latitude
}
if point.longitude < minLon {
minLon = point.longitude
}
if point.longitude > maxLon {
maxLon = point.longitude
}
}
return [RoutePoint(latitude: minLat, longitude: minLon, direction: 0, timestamp: Date()), RoutePoint(latitude: maxLat, longitude: maxLon, direction: 0, timestamp: Date())]
}


}



struct RoutePoint: Codable {
let latitude: Double
let longitude: Double
let direction: Double
let timestamp: Date

init(latitude: Double, longitude: Double, direction: Double, timestamp: Date) {
self.latitude = latitude
self.longitude = longitude
self.direction = direction
self.timestamp = timestamp
}
}

63 changes: 63 additions & 0 deletions windrider-ios/RouteMapView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// RouteMapView.swift
// windrider-ios
//
// Created by Daniel Grbac Bravo on 01/03/2024.
//

import SwiftUI
import MapKit

func calculateRegion(boundingBox: [RoutePoint]) -> MKCoordinateRegion {
let minLat = boundingBox[0].latitude
let maxLat = boundingBox[1].latitude
let minLon = boundingBox[0].longitude
let maxLon = boundingBox[1].longitude

let center = CLLocationCoordinate2D(latitude: (minLat + maxLat) / 2, longitude: (minLon + maxLon) / 2)
let span = MKCoordinateSpan(latitudeDelta: (maxLat - minLat) * 1.1, longitudeDelta: (maxLon - minLon) * 1.1)

return MKCoordinateRegion(center: center, span: span)
}




struct RouteMapView: View {
var route: Route
@State private var region: MKCoordinateRegion

init(route: Route) {
self.route = route
let boundingBox = route.caluateBoundingBox(route: route) // Assuming this is a correct method call
self._region = State(initialValue: calculateRegion(boundingBox: boundingBox))
}

var body: some View {
ZStack{
Map(){

}
.ignoresSafeArea()

}
}
}


struct RouteMapView_Previews: PreviewProvider {
static func createRandomRoute() -> Route {
var points = [RoutePoint]()
for _ in 0...100 {
points.append(RoutePoint(latitude: Double.random(in: 53.0...54.0), longitude: Double.random(in: 6.0...7.0), direction: Double.random(in: 0...360), timestamp: Date()))
}
return Route(points: points)
}

static var previews: some View {
// Now this call is valid because createRandomRoute is a static method
let randomRoute = createRandomRoute()

RouteMapView(route: randomRoute)
}
}

0 comments on commit 4b1001b

Please sign in to comment.