Skip to content
Draft
Show file tree
Hide file tree
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
17 changes: 17 additions & 0 deletions GeoBus.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
CFAF0E7628CE586300DDAD5B /* Globals.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFAF0E7528CE586300DDAD5B /* Globals.swift */; };
CFAF0E7828CE84C200DDAD5B /* Vehicles.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFAF0E7728CE84C200DDAD5B /* Vehicles.swift */; };
CFAF0E7A28CE84F400DDAD5B /* MapAnnotations.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFAF0E7928CE84F400DDAD5B /* MapAnnotations.swift */; };
CFB16ADA28EA6F730095D2ED /* Map in Frameworks */ = {isa = PBXBuildFile; productRef = CFB16AD928EA6F730095D2ED /* Map */; };
CFB5D45728EEFE21002368BC /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = CFB5D45528EEFE21002368BC /* InfoPlist.strings */; };
CFB5D45A28EEFE6B002368BC /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = CFB5D45828EEFE6B002368BC /* Localizable.strings */; };
CFC80FCC28D2C2FF003D059D /* DragAndDrop.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFC80FCB28D2C2FF003D059D /* DragAndDrop.swift */; };
Expand Down Expand Up @@ -179,6 +180,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
CFB16ADA28EA6F730095D2ED /* Map in Frameworks */,
CFF71E7028CCC47200C498FE /* Lottie in Frameworks */,
CFFF2D3D28D7C99C00E035E0 /* PostHog in Frameworks */,
);
Expand Down Expand Up @@ -425,6 +427,7 @@
packageProductDependencies = (
CFF71E6F28CCC47200C498FE /* Lottie */,
CFFF2D3C28D7C99C00E035E0 /* PostHog */,
CFB16AD928EA6F730095D2ED /* Map */,
);
productName = GeoBus;
productReference = CF181FE228CCB7D600248F72 /* GeoBus.app */;
Expand Down Expand Up @@ -462,6 +465,7 @@
packageReferences = (
CFF71E6E28CCC47200C498FE /* XCRemoteSwiftPackageReference "lottie-ios" */,
CFFF2D3B28D7C99C00E035E0 /* XCRemoteSwiftPackageReference "posthog-ios" */,
CFB16AD828EA6F730095D2ED /* XCRemoteSwiftPackageReference "Map" */,
);
productRefGroup = CF181FE328CCB7D600248F72 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -842,6 +846,14 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
CFB16AD828EA6F730095D2ED /* XCRemoteSwiftPackageReference "Map" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/pauljohanneskraft/Map";
requirement = {
branch = main;
kind = branch;
};
};
CFF71E6E28CCC47200C498FE /* XCRemoteSwiftPackageReference "lottie-ios" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/airbnb/lottie-ios.git";
Expand All @@ -861,6 +873,11 @@
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
CFB16AD928EA6F730095D2ED /* Map */ = {
isa = XCSwiftPackageProductDependency;
package = CFB16AD828EA6F730095D2ED /* XCRemoteSwiftPackageReference "Map" */;
productName = Map;
};
CFF71E6F28CCC47200C498FE /* Lottie */ = {
isa = XCSwiftPackageProductDependency;
package = CFF71E6E28CCC47200C498FE /* XCRemoteSwiftPackageReference "lottie-ios" */;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions GeoBus/App/Components/Map/MapAnnotations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ import MapKit
import SwiftUI


struct GenericMapAnnotation: Identifiable {
class GenericMapAnnotation: Identifiable, Equatable, ObservableObject {
static func == (lhs: GenericMapAnnotation, rhs: GenericMapAnnotation) -> Bool {
lhs.location.latitude == rhs.location.latitude && lhs.location.longitude == rhs.location.longitude
}


let id = UUID()
let location: CLLocationCoordinate2D
let id: String
@Published var location: CLLocationCoordinate2D
let format: Format

enum Format {
Expand All @@ -26,6 +30,7 @@ struct GenericMapAnnotation: Identifiable {
var stop: Stop?

init(lat: Double, lng: Double, format: Format, stop: Stop) {
self.id = UUID().uuidString //stop.publicId
self.location = CLLocationCoordinate2D(latitude: lat, longitude: lng)
self.format = format
self.stop = stop
Expand All @@ -36,6 +41,7 @@ struct GenericMapAnnotation: Identifiable {
var vehicle: VehicleSummary?

init(lat: Double, lng: Double, format: Format, vehicle: VehicleSummary) {
self.id = vehicle.busNumber
self.location = CLLocationCoordinate2D(latitude: lat, longitude: lng)
self.format = format
self.stop = nil
Expand Down
63 changes: 46 additions & 17 deletions GeoBus/App/Components/Map/MapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,38 @@
//

import SwiftUI
import Map
import MapKit
import Combine

struct MapView: View {

@EnvironmentObject var mapController: MapController
@EnvironmentObject var stopsController: StopsController
@EnvironmentObject var routesController: RoutesController
@EnvironmentObject var vehiclesController: VehiclesController


var body: some View {

Map(
coordinateRegion: $mapController.region,
interactionModes: [.all],
showsUserLocation: true,
annotationItems: mapController.visibleAnnotations
) { annotation in

MapAnnotation(coordinate: annotation.location) {
switch (annotation.format) {
case .stop:
StopAnnotationView(stop: annotation.stop!, isPresentedOnAppear: false)
case .vehicle:
VehicleAnnotationView(vehicle: annotation.vehicle!, isPresentedOnAppear: false)
case .singleStop:
StopAnnotationView(stop: annotation.stop!, isPresentedOnAppear: true)
interactionModes: [.pan, .zoom],
annotationItems: mapController.visibleAnnotations,
annotationContent: { item in
let annotation = UpdatingMapAnnotation(coordinate: item.location, publisher: item.$location)
ViewMapAnnotation(annotation: annotation) {
switch (item.format) {
case .stop:
StopAnnotationView(stop: item.stop!, isPresentedOnAppear: false)
case .vehicle:
VehicleAnnotationView(vehicle: item.vehicle!, isPresentedOnAppear: false)
case .singleStop:
StopAnnotationView(stop: item.stop!, isPresentedOnAppear: true)
}
}
}

}
)
.onChange(of: stopsController.selectedStop) { newStop in
if (newStop != nil) {
mapController.updateAnnotations(with: newStop!)
Expand All @@ -50,7 +52,34 @@ struct MapView: View {
.onChange(of: vehiclesController.vehicles) { newVehiclesList in
mapController.updateAnnotations(with: newVehiclesList)
}

}

}




@objc
class UpdatingMapAnnotation: NSObject, MKAnnotation {

dynamic var coordinate: CLLocationCoordinate2D

private var coordinateCancellable: Cancellable?

init<P: Publisher>(coordinate: CLLocationCoordinate2D, publisher: P) where P.Output == CLLocationCoordinate2D, P.Failure == Never {
self.coordinate = coordinate

super.init()

coordinateCancellable = publisher
.sink { [weak self] newValue in
// I changed unowned to weak, since we are now in another async context
// and the instance could (although highly unlikely) be gone until the animation is performed
UIView.animate(withDuration: 0.25) {
self?.coordinate = newValue
}
}
}

}
7 changes: 4 additions & 3 deletions GeoBus/App/Models/Routes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct APIRouteVariant: Decodable {
}

struct APIRouteVariantItinerary: Decodable {
let shape: String?
let id: Int?
let type: String?
let connections: [APIRouteVariantItineraryConnection]?
Expand Down Expand Up @@ -77,11 +78,11 @@ struct Route: Codable, Equatable, Identifiable {
let name: String
let kind: Kind
var variants: [Variant]

var id: String {
return self.number
}

}


Expand All @@ -90,7 +91,7 @@ struct Variant: Codable, Equatable, Identifiable {
var name: String = ""
let isCircular: Bool
var upItinerary, downItinerary, circItinerary: [Stop]?

var id: String {
return self.name
}
Expand Down
5 changes: 3 additions & 2 deletions GeoBus/App/Models/Stops.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct APIStop: Decodable {

/* MARK: - Stop */

// Data models adjusted for the app.
// Data model adjusted for the app.

struct Stop: Codable, Equatable, Identifiable {
let publicId: String
Expand All @@ -36,6 +36,7 @@ struct Stop: Codable, Equatable, Identifiable {
let direction: Direction?

var id: String {
return self.publicId //UUID().uuidString
return self.publicId
// return UUID().uuidString
}
}
Loading