-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
380 additions
and
78 deletions.
There are no files selected for viewing
200 changes: 200 additions & 0 deletions
200
app/Common/Components/MapAnnotation/BusAnnotation.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
|
||
import MapKit | ||
import SwiftUI | ||
|
||
struct StopAnnotation: View { | ||
let routes: [String] | ||
var stopIcon: String | ||
let isMetro: Bool | ||
|
||
init(routes: [String]) { | ||
isMetro = routes.allSatisfy { METRO_LINES.contains($0) } | ||
self.routes = routes | ||
|
||
guard !isMetro else { | ||
stopIcon = "tram.circle.fill" | ||
return | ||
} | ||
|
||
let transportTypes = Set(routes.map { | ||
getVehicleType($0) | ||
}) | ||
|
||
if transportTypes.contains(.bus) { | ||
stopIcon = "bus" | ||
} else { | ||
stopIcon = transportTypes.first!.rawValue | ||
} | ||
} | ||
|
||
var body: some View { | ||
if isMetro { | ||
MetroAnnotationStack(metroLines: routes) | ||
} else { | ||
Image( | ||
systemName: stopIcon | ||
) | ||
.imageScale(.small) | ||
.padding(3) | ||
.font(.system(size: 16)) | ||
.foregroundStyle(.white) | ||
.background( | ||
LinearGradient( | ||
gradient: Gradient(colors: getBgColors(routes) | ||
|
||
), | ||
startPoint: .topLeading, | ||
endPoint: .bottomTrailing | ||
) | ||
) | ||
.clipShape(.rect(cornerRadius: 4)) | ||
.overlay( | ||
RoundedRectangle(cornerRadius: 6) | ||
.stroke(.white, lineWidth: 2) | ||
) | ||
} | ||
} | ||
} | ||
|
||
#Preview("Metro") { | ||
Map { | ||
Annotation( | ||
"Random place on map", coordinate: CLLocationCoordinate2D( | ||
latitude: 50.113680, longitude: 14.449520) | ||
) { | ||
StopAnnotation( | ||
routes: ["A"] | ||
) | ||
} | ||
} | ||
} | ||
|
||
#Preview("Metro Stack") { | ||
Map { | ||
Annotation( | ||
"Random place on map", coordinate: CLLocationCoordinate2D( | ||
latitude: 50.113680, longitude: 14.449520) | ||
) { | ||
StopAnnotation( | ||
routes: ["A", "C"] | ||
) | ||
} | ||
} | ||
} | ||
|
||
#Preview("Tram") { | ||
Map { | ||
Annotation( | ||
"Random place on map", coordinate: CLLocationCoordinate2D( | ||
latitude: 50.113680, longitude: 14.449520) | ||
) { | ||
StopAnnotation( | ||
routes: ["78"] | ||
) | ||
} | ||
} | ||
} | ||
|
||
#Preview("Night Tram") { | ||
Map { | ||
Annotation( | ||
"Random place on map", coordinate: CLLocationCoordinate2D( | ||
latitude: 50.113680, longitude: 14.449520) | ||
) { | ||
StopAnnotation( | ||
routes: ["90"] | ||
) | ||
} | ||
} | ||
} | ||
|
||
#Preview("Bus") { | ||
Map { | ||
Annotation( | ||
"Random place on map", coordinate: CLLocationCoordinate2D( | ||
latitude: 50.113680, longitude: 14.449520) | ||
) { | ||
StopAnnotation( | ||
routes: ["700"] | ||
) | ||
} | ||
} | ||
} | ||
|
||
#Preview("Bus & Tram") { | ||
Map { | ||
Annotation( | ||
"Random place on map", coordinate: CLLocationCoordinate2D( | ||
latitude: 50.113680, longitude: 14.449520) | ||
) { | ||
StopAnnotation( | ||
routes: ["60", "700"] | ||
) | ||
} | ||
} | ||
} | ||
|
||
#Preview("Night Bus") { | ||
Map { | ||
Annotation( | ||
"Random place on map", coordinate: CLLocationCoordinate2D( | ||
latitude: 50.113680, longitude: 14.449520) | ||
) { | ||
StopAnnotation( | ||
routes: ["900"] | ||
) | ||
} | ||
} | ||
} | ||
|
||
#Preview("Detour") { | ||
Map { | ||
Annotation( | ||
"Random place on map", coordinate: CLLocationCoordinate2D( | ||
latitude: 50.113680, longitude: 14.449520) | ||
) { | ||
StopAnnotation( | ||
routes: ["X700"] | ||
) | ||
} | ||
} | ||
} | ||
|
||
#Preview("Ferry") { | ||
Map { | ||
Annotation( | ||
"Random place on map", coordinate: CLLocationCoordinate2D( | ||
latitude: 50.113680, longitude: 14.449520) | ||
) { | ||
StopAnnotation( | ||
routes: ["P4"] | ||
) | ||
} | ||
} | ||
} | ||
|
||
#Preview("Cable car") { | ||
Map { | ||
Annotation( | ||
"Random place on map", coordinate: CLLocationCoordinate2D( | ||
latitude: 50.113680, longitude: 14.449520) | ||
) { | ||
StopAnnotation( | ||
routes: ["LD"] | ||
) | ||
} | ||
} | ||
} | ||
|
||
#Preview("Train") { | ||
Map { | ||
Annotation( | ||
"Random place on map", coordinate: CLLocationCoordinate2D( | ||
latitude: 50.113680, longitude: 14.449520) | ||
) { | ||
StopAnnotation( | ||
routes: ["S42"] | ||
) | ||
} | ||
} | ||
} |
33 changes: 0 additions & 33 deletions
33
app/Common/Components/MapAnnotation/BusAnnotation/BusAnnotation.swift
This file was deleted.
Oops, something went wrong.
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
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
import SwiftUI | ||
|
||
func getBgColors(_ routes: [String]) -> [Color] { | ||
let vehicleTypes: [VehicleType] = routes.map { getVehicleType($0) } | ||
|
||
if vehicleTypes.count == 1, vehicleTypes[0] == .metro { | ||
return [getMetroLineColor(routes[0])] | ||
} | ||
|
||
if routes.allSatisfy({ isNightService($0) }) { | ||
return [.gray] | ||
} else if routes.allSatisfy({ $0.starts(with: "X") }) { | ||
return [.orange] | ||
} | ||
|
||
var res: [Color] = [] | ||
if vehicleTypes.contains(.bus) { | ||
res.append(.blue) | ||
} | ||
|
||
if vehicleTypes.contains(.tram) { | ||
res.append(.indigo) | ||
} else if vehicleTypes.contains(.lightrail) { | ||
res.append(.gray) | ||
} else if vehicleTypes.contains(.cablecar) { | ||
res.append(.brown) | ||
} else if vehicleTypes.contains(.ferry) { | ||
res.append(.mint) | ||
} | ||
|
||
return res | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
// https://pid.cz/jizdni-rady-podle-linek/metro/ | ||
func getVehicleType(_ nameAnyCased: String) -> VehicleType { | ||
let name = nameAnyCased.uppercased() | ||
|
||
if name.hasPrefix("LD") { | ||
return .cablecar | ||
} | ||
|
||
if name.hasPrefix("R") || | ||
name.hasPrefix("S") || | ||
name.hasPrefix("T") || | ||
name.hasPrefix("U") | ||
{ | ||
return .lightrail | ||
} | ||
|
||
if name.hasPrefix("P") { | ||
return .ferry | ||
} | ||
|
||
let number = Int(name) | ||
guard let number else { | ||
return .bus | ||
} | ||
|
||
// trolley bus | ||
if number == 58 || number == 59 { | ||
return .bus | ||
} else if number < 100 { | ||
return .tram | ||
} | ||
|
||
return .bus | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
|
||
func isNightService(_ name: String) -> Bool { | ||
let number = Int(name) | ||
guard let number else { | ||
return false | ||
} | ||
|
||
return number >= 900 || (number >= 90 && number < 100) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
enum VehicleType: String { | ||
case bus | ||
case tram | ||
case cablecar | ||
case ferry | ||
case metro | ||
case lightrail | ||
} |
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
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
Oops, something went wrong.