Skip to content

Commit

Permalink
Merge pull request #34 from edequartel/version-20
Browse files Browse the repository at this point in the history
Version 20
  • Loading branch information
edequartel authored Mar 27, 2024
2 parents 276d90f + fcdac1e commit 751f987
Show file tree
Hide file tree
Showing 11 changed files with 533 additions and 124 deletions.
14 changes: 5 additions & 9 deletions Ravens.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
470411132BB2B87300A498F5 /* LocationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 470411122BB2B87300A498F5 /* LocationManager.swift */; };
470F112F2BB18C5E003FE0C0 /* GeoJSONViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 470F112E2BB18C5E003FE0C0 /* GeoJSONViewModel.swift */; };
4717C0BF2B9CC41400B570D0 /* YearView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4717C0BE2B9CC41400B570D0 /* YearView.swift */; };
4725B9612BB14BD400F6F137 /* LocationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4725B9602BB14BD400F6F137 /* LocationViewModel.swift */; };
4725B9612BB14BD400F6F137 /* LocationIdViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4725B9602BB14BD400F6F137 /* LocationIdViewModel.swift */; };
4725B9632BB14C2C00F6F137 /* LocationJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4725B9622BB14C2C00F6F137 /* LocationJSON.swift */; };
4725B9652BB14E5500F6F137 /* LocationLatLongView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4725B9642BB14E5500F6F137 /* LocationLatLongView.swift */; };
474093822B558F82004F10C5 /* ObservationDetailsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 474093812B558F82004F10C5 /* ObservationDetailsView.swift */; };
474093842B55B5DE004F10C5 /* ManualView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 474093832B55B5DE004F10C5 /* ManualView.swift */; };
474093872B55B7AC004F10C5 /* MarkdownUI in Frameworks */ = {isa = PBXBuildFile; productRef = 474093862B55B7AC004F10C5 /* MarkdownUI */; };
Expand Down Expand Up @@ -99,9 +98,8 @@
470411122BB2B87300A498F5 /* LocationManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationManager.swift; sourceTree = "<group>"; };
470F112E2BB18C5E003FE0C0 /* GeoJSONViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeoJSONViewModel.swift; sourceTree = "<group>"; };
4717C0BE2B9CC41400B570D0 /* YearView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YearView.swift; sourceTree = "<group>"; };
4725B9602BB14BD400F6F137 /* LocationViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationViewModel.swift; sourceTree = "<group>"; };
4725B9602BB14BD400F6F137 /* LocationIdViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationIdViewModel.swift; sourceTree = "<group>"; };
4725B9622BB14C2C00F6F137 /* LocationJSON.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationJSON.swift; sourceTree = "<group>"; };
4725B9642BB14E5500F6F137 /* LocationLatLongView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationLatLongView.swift; sourceTree = "<group>"; };
474093812B558F82004F10C5 /* ObservationDetailsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObservationDetailsView.swift; sourceTree = "<group>"; };
474093832B55B5DE004F10C5 /* ManualView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ManualView.swift; sourceTree = "<group>"; };
474C40282B4BC4040038B3A5 /* Ravens.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Ravens.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -254,13 +252,13 @@
474C40542B4BFDC90038B3A5 /* RegionListViewModel.swift */,
474C40602B4C08FB0038B3A5 /* LanguageViewModel.swift */,
474C408B2B4DAC590038B3A5 /* RegionViewModel.swift */,
474C40992B50073C0038B3A5 /* ObservationsViewModel.swift */,
47568D2E2B59BA1300E69B1A /* ObservationsSpeciesViewModel.swift */,
47DB89B32B7A397F0093C1ED /* ObsViewModel.swift */,
474C40992B50073C0038B3A5 /* ObservationsViewModel.swift */,
4785CD1C2B964C0E002F52BE /* ObservationsUserViewModel.swift */,
4704110C2BB1C82000A498F5 /* ObservationsLocationViewModel.swift */,
4785CD182B95C856002F52BE /* UserViewModel.swift */,
4725B9602BB14BD400F6F137 /* LocationViewModel.swift */,
4725B9602BB14BD400F6F137 /* LocationIdViewModel.swift */,
470F112E2BB18C5E003FE0C0 /* GeoJSONViewModel.swift */,
470411122BB2B87300A498F5 /* LocationManager.swift */,
);
Expand Down Expand Up @@ -312,7 +310,6 @@
4785CD202B964FAC002F52BE /* MapObservationsUserView.swift */,
4785CD1A2B95C87E002F52BE /* UserView.swift */,
476FA8A52B9B031B00665613 /* SoundsView.swift */,
4725B9642BB14E5500F6F137 /* LocationLatLongView.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -467,9 +464,8 @@
474C408E2B4DB2850038B3A5 /* RegionsView.swift in Sources */,
474C40532B4BFD090038B3A5 /* RegionList.swift in Sources */,
474C408A2B4DAA110038B3A5 /* Region.swift in Sources */,
4725B9612BB14BD400F6F137 /* LocationViewModel.swift in Sources */,
4725B9612BB14BD400F6F137 /* LocationIdViewModel.swift in Sources */,
47568D2D2B59B54500E69B1A /* ObservationsSpecies.swift in Sources */,
4725B9652BB14E5500F6F137 /* LocationLatLongView.swift in Sources */,
47B7E3B62B5D9C5500B88043 /* FloatingButton.swift in Sources */,
474C404C2B4BCE340038B3A5 /* SpeciesDetailsView.swift in Sources */,
474C402E2B4BC4040038B3A5 /* ContentView.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Ravens/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct ContentView: View {
// Tab 2
ZStack {
MapObservationsLocationView(sharedLocationId: Binding<Int>(get: { self.locationId ?? 0 }, set: { self.locationId = $0 }))
ObservationCircle(toggle: $isSheetObservationsLocationsViewPresented, colorHex: "d7b731")
ObservationCircle(toggle: $isSheetObservationsLocationsViewPresented, colorHex: "a7b731")
}
.tabItem {
Text("Area")
Expand Down
6 changes: 0 additions & 6 deletions Ravens/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,6 @@
},
"Local map" : {

},
"Locations" : {

},
"Login" : {
"localizations" : {
Expand Down Expand Up @@ -980,9 +977,6 @@
}
}
}
},
"View on Website" : {

},
"Voelt als: %@" : {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import Foundation
import Alamofire

class LocationViewModel: ObservableObject {
// get the LocationId from latitude and longitude
class LocationIdViewModel: ObservableObject {
@Published var locations: [LocationJSON] = []
@Published var isLoading: Bool = false

Expand Down
41 changes: 40 additions & 1 deletion Ravens/Models/ObservationsLocationViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ class ObservationsLocationViewModel: ObservableObject {

private var keyChainViewModel = KeychainViewModel()

// var minLatitude: Double = 0
// var maxLatitude: Double = 0
// var minLongitude: Double = 0
// var maxLongitude: Double = 0

var locations = [Location]()
var span: Span = Span(latitudeDelta: 0.1, longitudeDelta: 0.1, latitude: 0, longitude: 0)

var settings: Settings
init(settings: Settings) {
Expand Down Expand Up @@ -46,8 +52,39 @@ class ObservationsLocationViewModel: ObservableObject {
}
}

func getSpan() {
var latitudes: [Double] = []
var longitudes: [Double] = []

let max = (observationsSpecies?.results.count ?? 0)
for i in 0 ..< max {
let longitude = observationsSpecies?.results[i].point.coordinates[0] ?? 52.024052
let latitude = observationsSpecies?.results[i].point.coordinates[1] ?? 5.245350
latitudes.append(latitude)
longitudes.append(longitude)
}

let minLatitude = latitudes.min() ?? 0
let maxLatitude = latitudes.max() ?? 0
let minLongitude = longitudes.min() ?? 0
let maxLongitude = longitudes.max() ?? 0
print("min \(minLatitude) \(minLongitude)")
print("max \(maxLatitude) \(maxLongitude)")

let centreLatitude = (minLatitude + maxLatitude) / 2
let centreLongitude = (minLongitude + maxLongitude) / 2

let latitudeDelta = (maxLatitude - minLatitude) * 1.5
let longitudeDelta = (maxLongitude - minLongitude) * 1.5

print("delta \(latitudeDelta) \(longitudeDelta)")
print("position \(centreLatitude) \(centreLongitude)")

span = Span(latitudeDelta: latitudeDelta, longitudeDelta: longitudeDelta, latitude: centreLatitude, longitude: centreLongitude)
}


func fetchData(locationId: Int, limit: Int, offset: Int) {
func fetchData(locationId: Int, limit: Int, offset: Int, completion: @escaping () -> Void) {
log.error("fetchData ObservationsLocationViewModel limit: \(locationId) \(limit) offset: \(offset)")

keyChainViewModel.retrieveCredentials()
Expand Down Expand Up @@ -75,6 +112,8 @@ class ObservationsLocationViewModel: ObservableObject {
DispatchQueue.main.async {
self.observationsSpecies = observationsSpecies
self.getLocations()
self.getSpan()
completion()
}
} catch {
self.log.error("Error ObservationsLocationViewModel decoding JSON: \(error)")
Expand Down
28 changes: 12 additions & 16 deletions Ravens/Models/ObservationsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,31 @@ struct Location: Identifiable {
var hasSound: Bool
}

struct Span {
var latitudeDelta: Double
var longitudeDelta: Double
var latitude: Double
var longitude: Double

}

class ObservationsViewModel: ObservableObject {
let log = SwiftyBeaver.self
@Published var observations: Observations?

var locations = [Location]()
var poiLocations = [Location]()
// var span: Span = Span(latitudeDelta: 0.1, longitudeDelta: 0.1, latitude: 52.024052, longitude: 5.245350)

var settings: Settings
init(settings: Settings) {
log.info("init ObservationsViewModel")
self.settings = settings

}

///
func getLocations() {
locations.removeAll()

let max = (observations?.results.count ?? 0)
for i in 0 ..< max {

Expand All @@ -47,12 +54,10 @@ class ObservationsViewModel: ObservableObject {
let hasPhoto = observations?.results[i].has_photo ?? false
let hasSound = observations?.results[i].has_sound ?? false
let newLocation = Location(name: name, coordinate: CLLocationCoordinate2D(latitude: latitude, longitude: longitude), rarity: rarity, hasPhoto: hasPhoto, hasSound: hasSound)

locations.append(newLocation)

}
}

func getPoiLocations() {
poiLocations.removeAll()
var newLocation = Location(name: "IJmuiden", coordinate: CLLocationCoordinate2D(latitude: 52.459402, longitude: 4.540332), rarity: 0, hasPhoto: false, hasSound: false)
Expand All @@ -70,7 +75,7 @@ class ObservationsViewModel: ObservableObject {
newLocation = Location(name: "De zouweboezem", coordinate: CLLocationCoordinate2D(latitude: 51.948497, longitude: 4.995383), rarity: 0, hasPhoto: false, hasSound: false)
poiLocations.append(newLocation)
// newLocation = Location(name: "Werkhoven", coordinate: CLLocationCoordinate2D(latitude: 52.024052, longitude: 5.245350), rarity: 0)
poiLocations.append(newLocation)
// poiLocations.append(newLocation)
newLocation = Location(name: "Blauwe kamer", coordinate: CLLocationCoordinate2D(latitude: 51.942360, longitude: 5.610475), rarity: 0, hasPhoto: false, hasSound: false)
poiLocations.append(newLocation)
newLocation = Location(name: "Steenwaard", coordinate: CLLocationCoordinate2D(latitude: 51.965423, longitude: 5.215302), rarity: 0, hasPhoto: false, hasSound: false)
Expand All @@ -92,13 +97,6 @@ class ObservationsViewModel: ObservableObject {

let url = settings.endPoint()+"observations/around-point/?days=\(settings.days)&end_date=\(formatCurrentDate(value: settings.selectedDate))&lat=\(lat)&lng=\(long)&radius=\(settings.radius)&species_group=\(settings.selectedGroupId)&min_rarity=\(settings.selectedRarity)"



// //deze verder uitwerken met location.id /api/v1/locations/17829/observations/
// let url = settings.endPoint()+"locations/17820/observations/"
//// "observations/around-point/?days=\(settings.days)&end_date=\(formatCurrentDate(value: settings.selectedDate))&lat=\(lat)&lng=\(long)&radius=\(settings.radius)&species_group=\(settings.selectedGroupId)&min_rarity=\(settings.selectedRarity)"
//

log.info("\(url)")

AF.request(url, headers: headers).responseDecodable(of: Observations.self) { response in
Expand All @@ -107,7 +105,7 @@ class ObservationsViewModel: ObservableObject {
DispatchQueue.main.async {
self.observations = observations
self.getLocations()
self.getPoiLocations()
// self.getPoiLocations()
self.log.error("observations locations count \(self.locations.count)")
}
case .failure(let error):
Expand All @@ -118,5 +116,3 @@ class ObservationsViewModel: ObservableObject {
}
}


// let url = "https://waarneming.nl/api/v1/user/observations/"
39 changes: 0 additions & 39 deletions Ravens/Views/LocationLatLongView.swift

This file was deleted.

33 changes: 5 additions & 28 deletions Ravens/Views/MapObservationView.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//
// MapObservationView.swift
// Ravens
//
Expand All @@ -12,10 +11,7 @@ import SwiftyBeaver
struct MapObservationView: View {
let log = SwiftyBeaver.self

@StateObject private var locationViewModel = LocationViewModel()

@StateObject private var geoJSONViewModel = GeoJSONViewModel()
@State private var polyOverlays = [MKPolygon]()
@StateObject private var locationIdViewModel = LocationIdViewModel()

@EnvironmentObject var observationsLocationViewModel: ObservationsLocationViewModel

Expand Down Expand Up @@ -80,7 +76,6 @@ struct MapObservationView: View {
.frame(width: 6, height: 6)
)
}

}

MapCircle(center: circlePos ?? CLLocationCoordinate2D(), radius: CLLocationDistance(settings.radius))
Expand All @@ -103,13 +98,7 @@ struct MapObservationView: View {
)
}
}

//JSONData
ForEach(polyOverlays, id: \.self) { polyOverlay in
MapPolygon(polyOverlay)
.stroke(.pink, lineWidth: 1)
.foregroundStyle(.blue.opacity(0.1))
}



}
Expand All @@ -118,19 +107,6 @@ struct MapObservationView: View {
.safeAreaInset(edge: .bottom) {
VStack {
SettingsDetailsView(count: observationsViewModel.locations.count, results: observationsViewModel.observations?.count ?? 0 )

if locationViewModel.locations.count > 0 {
HStack {
Text("\(locationViewModel.locations[0].name)")
Spacer()
Text("\(locationViewModel.locations[0].id)")

}
.foregroundColor(.white)
} else {
Text("Default Name")
}

}
}

Expand All @@ -148,7 +124,6 @@ struct MapObservationView: View {
}
}
.mapControls() {
// MapUserLocationButton()
MapCompass() //tapping this makes it north
}
}
Expand All @@ -171,7 +146,9 @@ struct MapObservationView: View {
.region(
MKCoordinateRegion(
center: CLLocationCoordinate2D(latitude: myLatitude, longitude: myLongitude),
span: MKCoordinateSpan(latitudeDelta: 0.1, longitudeDelta: 0.1)
span: MKCoordinateSpan(latitudeDelta: 0.5, longitudeDelta: 0.5)
// span: MKCoordinateSpan(latitudeDelta: observationsViewModel.span.latitudeDelta, longitudeDelta: observationsViewModel.span.longitudeDelta)

)
)
} else {
Expand Down
Loading

0 comments on commit 751f987

Please sign in to comment.