Skip to content

Commit

Permalink
Feat: Fetch marts by the center of mapCenter GeoPoint #71
Browse files Browse the repository at this point in the history
  • Loading branch information
jinios committed Jul 30, 2019
1 parent 2c090b9 commit 9f41e82
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 81 deletions.
56 changes: 0 additions & 56 deletions MartHoliday/MartHoliday/Utility/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,62 +122,6 @@ extension UILabel {
}
}

//extension NMapView {
//
// func setMapGesture(enable: Bool) {
// self.setPanEnabled(enable)
// self.setZoomEnabled(enable)
// self.isMultipleTouchEnabled = enable
// }
//
//
// func showMarker(at point: NGeoPoint) {
//
// if let mapOverlayManager = self.mapOverlayManager {
//
// if let poiDataOverlay = mapOverlayManager.newPOIdataOverlay() {
//
// poiDataOverlay.initPOIdata(1)
//
// poiDataOverlay.addPOIitem(atLocation: NGeoPoint(longitude: point.longitude, latitude: point.latitude), title: "", type: UserPOIflagTypeDefault, iconIndex: 0, with: nil)
//
// poiDataOverlay.endPOIdata()
// poiDataOverlay.showAllPOIdata()
// }
// }
// }
//
// func showMarkers(at poiData: POIData?) {
//
// if let mapOverlayManager = self.mapOverlayManager {
// guard let poiData = poiData else { return }
//
// // create POI data overlay
// if let poiDataOverlay = mapOverlayManager.newPOIdataOverlay() {
//
// poiDataOverlay.initPOIdata(Int32(poiData.count))
//
// for i in 0..<poiData.count {
// let poiDatum = poiData[i]
// poiDataOverlay.addPOIitem(
// atLocation: poiDatum.nGeoPoint,
// title: poiDatum.branch.displayName(),
// type: UserPOIflagTypeDefault,
// iconIndex: Int32(i),
// with: nil)
// }
//
// poiDataOverlay.endPOIdata()
//
// // show all POI data
// poiDataOverlay.showAllPOIdata()
//
// poiDataOverlay.selectPOIitem(at: 0, moveToCenter: false, focusedBySelectItem: true)
// }
// }
// }
//
//}

extension Collection where Index == Int {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,25 @@ class LocationSearchViewController: IndicatorViewController, NMFMapViewDelegate,

var markerInfoWindowDataSource = MarkerInfoWindowDataSource()

var isDistanceSearchViewShown = true
var previousDistance: Int?

var settingDistance: Int? {
didSet {
self.distanceLabel.text = "\(self.settingDistance ?? 2)km"
}
}

let nMapViewObserverKeypath = "positionMode"

override func viewDidLoad() {
super.viewDidLoad()
setSearchAgainButtonBorder()
self.searchAgainButton.alpha = 0
self.userLocation = self.locationOverlay?.location
naverMapView.delegate = self

naverMapView.addObserver(self, forKeyPath: "positionMode", options: [.new], context: nil)
naverMapView.addObserver(self, forKeyPath: nMapViewObserverKeypath, options: [.new], context: nil)
NotificationCenter.default.addObserver(self, selector: #selector(showErrorAlert), name: .apiErrorAlertPopup, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(changeTrackingStatus), name: .completeFetchNearMart, object: nil)

Expand All @@ -84,7 +95,7 @@ class LocationSearchViewController: IndicatorViewController, NMFMapViewDelegate,
self.finishIndicator()
}

distanceSlider = TickMarkSlider(tick: 8, maximumValue: 8, initialValue: 2.0, frame: self.sliderView.bounds)
distanceSlider = TickMarkSlider(tick: 8, minimumValue: 0, maximumValue: 8, initialValue: 2.0, frame: self.sliderView.bounds)
distanceSlider!.addTickMarks()
distanceSlider!.delegate = self
self.sliderView.addSubview(distanceSlider!)
Expand All @@ -94,25 +105,31 @@ class LocationSearchViewController: IndicatorViewController, NMFMapViewDelegate,

}

@objc private func showErrorAlert() {
DispatchQueue.main.async {
self.presentErrorAlert(type: .DisableNearbyMarts)
}
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.setNavigationBar()
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
}

@objc private func showErrorAlert() {
DispatchQueue.main.async {
self.presentErrorAlert(type: .DisableNearbyMarts)
}
}

@objc func changeTrackingStatus() {
naverMapView.positionMode = .disabled
}

@objc func changeSearchDistance() {
self.showAndHideDistanceView()
guard !self.isDistanceSearchViewShown else { return }
fetchNearMarts(from: self.getMapCenter())
}

private func setNavigationBar() {
navigationController?.navigationBar.prefersLargeTitles = false
self.navigationItem.title = "내 주변 마트 검색"
Expand All @@ -123,21 +140,10 @@ class LocationSearchViewController: IndicatorViewController, NMFMapViewDelegate,
self.searchAgainButton.clipsToBounds = true
}

var settingDistance: Int? {
didSet {
self.distanceLabel.text = "\(self.settingDistance ?? 2)km"
}
}

var isDistanceSearchViewShown = true
var previousDistance: Int?

@objc func changeSearchDistance() {
self.showAndHideDistanceView()
guard self.isDistanceSearchViewShown else { return }
guard let userLocation = self.userLocation else { return }

fetchNearMarts(from: userLocation)
private func getMapCenter() -> NMGLatLng {
let position = naverMapView.mapView.cameraPosition
let centerGeoPoint = position.target
return centerGeoPoint
}

private func showAndHideDistanceView() {
Expand Down Expand Up @@ -188,7 +194,7 @@ extension LocationSearchViewController {
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
self.locationOverlay = naverMapView.mapView.locationOverlay

if keyPath == "positionMode" {
if keyPath == nMapViewObserverKeypath {
self.userLocation = self.locationOverlay!.location
}
}
Expand Down

0 comments on commit 9f41e82

Please sign in to comment.