Skip to content

Commit

Permalink
work in progress user place creation
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbarela committed Mar 6, 2024
1 parent 80506ef commit 866031c
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 33 deletions.
16 changes: 16 additions & 0 deletions Marlin/Marlin.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@
F7303DFA2B965BA600CAC2BB /* UserPlacesList.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7303DF92B965BA600CAC2BB /* UserPlacesList.swift */; };
F7303DFE2B9688AE00CAC2BB /* DGPSStationListTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7303DFD2B9688AE00CAC2BB /* DGPSStationListTests.swift */; };
F7303E002B98B78000CAC2BB /* DataSourceFilterAndSort.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7303DFF2B98B78000CAC2BB /* DataSourceFilterAndSort.swift */; };
F7303E022B98EA7400CAC2BB /* DrawingMixin.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7303E012B98EA7400CAC2BB /* DrawingMixin.swift */; };
F7303E052B98EDEC00CAC2BB /* SearchRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7303E042B98EDEC00CAC2BB /* SearchRepository.swift */; };
F730DFC42A99000D0051775C /* GeoJSON in Frameworks */ = {isa = PBXBuildFile; productRef = F730DFC32A99000D0051775C /* GeoJSON */; };
F730DFC72A9950B20051775C /* GeoJSONExportable.swift in Sources */ = {isa = PBXBuildFile; fileRef = F730DFC62A9950B20051775C /* GeoJSONExportable.swift */; };
F73356FD2B308E4B00BEE26F /* AsamFilterable.swift in Sources */ = {isa = PBXBuildFile; fileRef = F73356FC2B308E4B00BEE26F /* AsamFilterable.swift */; };
Expand Down Expand Up @@ -933,6 +935,8 @@
F7303DF92B965BA600CAC2BB /* UserPlacesList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserPlacesList.swift; sourceTree = "<group>"; };
F7303DFD2B9688AE00CAC2BB /* DGPSStationListTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DGPSStationListTests.swift; sourceTree = "<group>"; };
F7303DFF2B98B78000CAC2BB /* DataSourceFilterAndSort.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataSourceFilterAndSort.swift; sourceTree = "<group>"; };
F7303E012B98EA7400CAC2BB /* DrawingMixin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DrawingMixin.swift; sourceTree = "<group>"; };
F7303E042B98EDEC00CAC2BB /* SearchRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchRepository.swift; sourceTree = "<group>"; };
F730DFC62A9950B20051775C /* GeoJSONExportable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeoJSONExportable.swift; sourceTree = "<group>"; };
F73356FC2B308E4B00BEE26F /* AsamFilterable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AsamFilterable.swift; sourceTree = "<group>"; };
F73356FE2B308EF100BEE26F /* ModuFilterable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModuFilterable.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1640,6 +1644,7 @@
F70BCE9829C4F1AE00AEF73D /* UserLayersMap.swift */,
F7667CEC2A0025B0005B36A0 /* NavigationalWarningMap.swift */,
F7AFF9402AD46A2300555960 /* AllRoutesMixin.swift */,
F7303E012B98EA7400CAC2BB /* DrawingMixin.swift */,
);
path = Mixins;
sourceTree = "<group>";
Expand Down Expand Up @@ -1668,6 +1673,7 @@
F71F2B1E2ACF3CAB00DFB5BA /* Repository */ = {
isa = PBXGroup;
children = (
F7303E032B98EDE000CAC2BB /* Search */,
F767DB3D2B8D0FA7002C12C7 /* UserPlace */,
F7C5F1E92AEC4AC70091BC01 /* ASAM */,
F7C5F1EA2AEC4AF40091BC01 /* Bookmark */,
Expand Down Expand Up @@ -1883,6 +1889,14 @@
path = DifferentialGPSStation;
sourceTree = "<group>";
};
F7303E032B98EDE000CAC2BB /* Search */ = {
isa = PBXGroup;
children = (
F7303E042B98EDEC00CAC2BB /* SearchRepository.swift */,
);
path = Search;
sourceTree = "<group>";
};
F730DFC52A9950930051775C /* Conversions */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -3924,6 +3938,7 @@
F767DB772B8FD793002C12C7 /* LightDefinition.swift in Sources */,
F7D8FA162922BA3B00E7D0A1 /* NoticeToMariners+DataSourceViewBuilder.swift in Sources */,
F76EE1572B928A69001128EB /* ModuDataLoadOperation.swift in Sources */,
F7303E052B98EDEC00CAC2BB /* SearchRepository.swift in Sources */,
F7FDF2B22AB4D5EA009A5E8F /* ModuModel.swift in Sources */,
F7FDF2AC2AB49C95009A5E8F /* AsamLocalDataSource.swift in Sources */,
F7A54CD52848149700E5F565 /* MarlinApp.swift in Sources */,
Expand Down Expand Up @@ -3965,6 +3980,7 @@
F767DB752B8FD777002C12C7 /* NavigationalWarningDefinition.swift in Sources */,
F71DF4862857954A00686951 /* Modu.swift in Sources */,
F7CB01132B61591600034B9C /* TileRepository.swift in Sources */,
F7303E022B98EA7400CAC2BB /* DrawingMixin.swift in Sources */,
F74B9B0D28B7DA210097D448 /* RadioBeaconSummaryView.swift in Sources */,
F767DB4C2B8E276D002C12C7 /* PublicationsTypeIdListViewModel.swift in Sources */,
F7D671E72871D46000758F1C /* SideMenuContent.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Marlin/Marlin/Filter/Fields/LocationBoundsMixin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class LocationBoundsMixin: NSObject, MapMixin, ObservableObject {
_coordinateTwo = coordinateTwo
}

func regionDidChange(mapView: MKMapView, animated: Bool) {
func regionDidChange(mapView: MKMapView, animated: Bool, centerCoordinate: CLLocationCoordinate2D) {
self.triggerUpdate()
region = mapView.region
}
Expand Down
13 changes: 9 additions & 4 deletions Marlin/Marlin/Map/MarlinMainMap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ struct MarlinMainMap: View {
var showExport: Bool = true

let focusMapAtLocation = NotificationCenter.default.publisher(for: .FocusMapAtLocation)

let longPressPub = NotificationCenter.default.publisher(for: .MapLongPress)

var body: some View {
VStack {
MarlinMap(name: "Marlin Map", mixins: mixins, mapState: mapState)
Expand All @@ -37,8 +38,12 @@ struct MarlinMainMap: View {
.onReceive(focusMapAtLocation) { notification in
mapState.forceCenter = notification.object as? MKCoordinateRegion
}
.overlay(bottomButtons(), alignment: .bottom)
.overlay(topButtons(), alignment: .top)
.overlay(alignment: .bottom) {
bottomButtons()
}
.overlay(alignment: .top) {
topButtons()
}
.onAppear {
mixins.addRouteMixin(routeRepository: routeRepository)
mixins.addAsamTileRepository(tileRepository: asamsTileRepository)
Expand Down Expand Up @@ -137,7 +142,7 @@ struct MarlinMainMap: View {
.fixedSize()
.accessibilityElement(children: .contain)
.accessibilityLabel("User Tracking")
CreateUserPlaceButton()
// CreateUserPlaceButton()
}
.padding(.trailing, 8)
.padding(.bottom, 30)
Expand Down
8 changes: 6 additions & 2 deletions Marlin/Marlin/Map/MarlinMap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,10 @@ class MarlinMapCoordinator: NSObject, MapCoordinator {
if mapGesture.state == .began {
let coordinate = mapView.convert(mapGesture.location(in: mapView), toCoordinateFrom: mapView)
NotificationCenter.default.post(name: marlinMap.notificationOnLongPress, object: coordinate)

for mixin in mixins {
mixin.mapLongPress(mapView: mapView, coordinate: coordinate)
}
}
}

Expand Down Expand Up @@ -709,10 +713,10 @@ class MarlinMapCoordinator: NSObject, MapCoordinator {

func mapView(_ mapView: MKMapView, regionDidChangeAnimated animated: Bool) {
for mixin in marlinMap.mixins.mixins {
mixin.regionDidChange(mapView: mapView, animated: animated)
mixin.regionDidChange(mapView: mapView, animated: animated, centerCoordinate: mapView.centerCoordinate)
}
}

func mapView(_ mapView: MKMapView, regionWillChangeAnimated animated: Bool) {
}

Expand Down
29 changes: 29 additions & 0 deletions Marlin/Marlin/Map/Mixins/DrawingMixin.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// DrawingMixin.swift
// Marlin
//
// Created by Daniel Barela on 3/6/24.
//

import Foundation
import MapKit

class DrawingMixin: NSObject, MapMixin {
var uuid: UUID = UUID()

func setupMixin(mapState: MapState, mapView: MKMapView) {

}

func removeMixin(mapView: MKMapView, mapState: MapState) {

}

func mapLongPress(mapView: MKMapView, coordinate: CLLocationCoordinate2D) {
// put a marker on the map and then do a query for where they long pressed
// this should show a bottom sheet which will provide actions:
// save as user point, measure, create route, draw more points
// if while drawing, the center of the map is close to a marlin feature
// it will snap to that feature
}
}
9 changes: 7 additions & 2 deletions Marlin/Marlin/Map/Mixins/MapMixin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protocol MapMixin: AnyObject {
func updateMixin(mapView: MKMapView, mapState: MapState)
func renderer(overlay: MKOverlay) -> MKOverlayRenderer?
func traitCollectionUpdated(previous: UITraitCollection?)
func regionDidChange(mapView: MKMapView, animated: Bool)
func regionDidChange(mapView: MKMapView, animated: Bool, centerCoordinate: CLLocationCoordinate2D)
func viewForAnnotation(annotation: MKAnnotation, mapView: MKMapView) -> MKAnnotationView?
func items(at location: CLLocationCoordinate2D, mapView: MKMapView, touchPoint: CGPoint) -> [any DataSource]?
func itemKeys(
Expand All @@ -25,9 +25,14 @@ protocol MapMixin: AnyObject {
touchPoint: CGPoint
) async -> [String: [String]]
func removeMixin(mapView: MKMapView, mapState: MapState)
func mapLongPress(mapView: MKMapView, coordinate: CLLocationCoordinate2D)
}

extension MapMixin {
func mapLongPress(mapView: MKMapView, coordinate: CLLocationCoordinate2D) {

}

func polygonHitTest(polygon: MKPolygon, location: CLLocationCoordinate2D) -> Bool {
guard let renderer = (renderer(overlay: polygon) as? MKPolygonRenderer
?? standardRenderer(overlay: polygon) as? MKPolygonRenderer) else {
Expand Down Expand Up @@ -141,6 +146,6 @@ extension MapMixin {
[:]
}

func regionDidChange(mapView: MKMapView, animated: Bool) {
func regionDidChange(mapView: MKMapView, animated: Bool, centerCoordinate: CLLocationCoordinate2D) {
}
}
2 changes: 1 addition & 1 deletion Marlin/Marlin/Map/Mixins/PersistedMapState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class PersistedMapState: NSObject, MapMixin {
}
}

func regionDidChange(mapView: MKMapView, animated: Bool) {
func regionDidChange(mapView: MKMapView, animated: Bool, centerCoordinate: CLLocationCoordinate2D) {
UserDefaults.standard.mapRegion = mapView.region
}

Expand Down
23 changes: 1 addition & 22 deletions Marlin/Marlin/Map/Mixins/SearchResultsMap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SearchResultAnnotation: NSObject, MKAnnotation {
var mapItem: MKMapItem

var title: String? {
"\(mapItem.name ?? "")\n\(mapItem.placemark.country ?? "")\n\(mapItem.placemark.ocean ?? "")"
"\(mapItem.name ?? "")\n\(mapItem.placemark.country ?? "")\n\(mapItem.placemark.ocean ?? "")"
}

var subtitle: String? {
Expand Down Expand Up @@ -53,33 +53,12 @@ class SearchResultsMap: NSObject, MapMixin {
mapView.addAnnotations(self.annotations)
}
.store(in: &cancellable)
// TODO: this seems like the wrong place for this
let region = UserDefaults.standard.mapRegion
if CLLocationCoordinate2DIsValid(region.center) {
if MKUserTrackingMode(rawValue: mapState.userTrackingMode) ?? MKUserTrackingMode.none == .none {
DispatchQueue.main.async {
mapState.center = region
}
}
} else {
DispatchQueue.main.async {
mapState.center = MKCoordinateRegion(
center: mapView.centerCoordinate,
zoom: 4,
bounds: UIScreen.main.bounds
)
}
}
}

func removeMixin(mapView: MKMapView, mapState: MapState) {

}

func regionDidChange(mapView: MKMapView, animated: Bool) {
UserDefaults.standard.mapRegion = mapView.region
}

func viewForAnnotation(annotation: MKAnnotation, mapView: MKMapView) -> MKAnnotationView? {
if let annotation = annotation as? SearchResultAnnotation {
let mapItem = annotation.mapItem
Expand Down
9 changes: 9 additions & 0 deletions Marlin/Marlin/Preferences/MarlinUserDefaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,13 @@ extension UserDefaults {
setValue(newValue, forKey: #function)
}
}

var searchType: SearchType {
get {
return SearchType.init(rawValue: integer(forKey: #function)) ?? .native
}
set {
setValue(newValue.rawValue, forKey: #function)
}
}
}
4 changes: 3 additions & 1 deletion Marlin/Marlin/Preferences/SortPreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ extension UserDefaults {

// Write/Set Data
UserDefaults.standard.set(data, forKey: "\(key)Sort")
NotificationCenter.default.post(name: .DataSourceUpdated, object: DataSourceUpdatedNotification(key: key))
DispatchQueue.main.async {
NotificationCenter.default.post(name: .DataSourceUpdated, object: DataSourceUpdatedNotification(key: key))

Check warning on line 99 in Marlin/Marlin/Preferences/SortPreferences.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Line Length Violation: Line should be 120 characters or less; currently it has 122 characters (line_length)

Check warning on line 99 in Marlin/Marlin/Preferences/SortPreferences.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Line Length Violation: Line should be 120 characters or less; currently it has 122 characters (line_length)
}
} catch {
print("Unable to Encode Array of Notes (\(error))")
}
Expand Down
29 changes: 29 additions & 0 deletions Marlin/Marlin/Repository/Search/SearchRepository.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// SearchRepository.swift
// Marlin
//
// Created by Daniel Barela on 3/6/24.
//

import Foundation
import MapKit

class SearchRepository {
func performSearch(
searchText: String,
region: MKCoordinateRegion?
) async -> [MKMapItem]? {
await withCheckedContinuation { continuation in
switch UserDefaults.standard.searchType {
case .native:
NativeSearchProvider.performSearch(searchText: searchText, region: region) { result in
continuation.resume(returning: result)
}
case .nominatim:
NominatimSearchProvider.performSearch(searchText: searchText, region: region) { result in
continuation.resume(returning: result)
}
}
}
}
}

0 comments on commit 866031c

Please sign in to comment.