Skip to content

Commit

Permalink
[Feat] Runnect#13 - 지도 사용을 위한 로직 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
lsj8706 committed Jan 2, 2023
1 parent cf2ea48 commit daaa336
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 21 deletions.
24 changes: 24 additions & 0 deletions Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
CE665615295D989A00C64E12 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = CE665614295D989A00C64E12 /* .swiftlint.yml */; };
CEC2A6852961F92C00160BF7 /* CustomButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC2A6842961F92C00160BF7 /* CustomButton.swift */; };
CEC2A68729629B9B00160BF7 /* SignInVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC2A68629629B9B00160BF7 /* SignInVC.swift */; };
CEC2A68A2962ADCD00160BF7 /* RNMapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC2A6892962ADCD00160BF7 /* RNMapView.swift */; };
CEC2A68C2962AE1B00160BF7 /* RNStartMarker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC2A68B2962AE1B00160BF7 /* RNStartMarker.swift */; };
CEC2A68E2962AF2C00160BF7 /* RNMarker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC2A68D2962AF2C00160BF7 /* RNMarker.swift */; };
CEC2A6902962B06C00160BF7 /* convertLocationObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC2A68F2962B06C00160BF7 /* convertLocationObject.swift */; };
CEEC6B3A2961C4F300D00E1E /* CourseDrawingHomeVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEEC6B392961C4F300D00E1E /* CourseDrawingHomeVC.swift */; };
CEEC6B3C2961C51A00D00E1E /* CourseStorageVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEEC6B3B2961C51A00D00E1E /* CourseStorageVC.swift */; };
CEEC6B3E2961C53700D00E1E /* CourseDiscoveryVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEEC6B3D2961C53700D00E1E /* CourseDiscoveryVC.swift */; };
Expand Down Expand Up @@ -138,6 +142,10 @@
CE665614295D989A00C64E12 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text.yaml; path = .swiftlint.yml; sourceTree = "<group>"; };
CEC2A6842961F92C00160BF7 /* CustomButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomButton.swift; sourceTree = "<group>"; };
CEC2A68629629B9B00160BF7 /* SignInVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignInVC.swift; sourceTree = "<group>"; };
CEC2A6892962ADCD00160BF7 /* RNMapView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RNMapView.swift; sourceTree = "<group>"; };
CEC2A68B2962AE1B00160BF7 /* RNStartMarker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RNStartMarker.swift; sourceTree = "<group>"; };
CEC2A68D2962AF2C00160BF7 /* RNMarker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RNMarker.swift; sourceTree = "<group>"; };
CEC2A68F2962B06C00160BF7 /* convertLocationObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = convertLocationObject.swift; sourceTree = "<group>"; };
CEEC6B392961C4F300D00E1E /* CourseDrawingHomeVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseDrawingHomeVC.swift; sourceTree = "<group>"; };
CEEC6B3B2961C51A00D00E1E /* CourseStorageVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseStorageVC.swift; sourceTree = "<group>"; };
CEEC6B3D2961C53700D00E1E /* CourseDiscoveryVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseDiscoveryVC.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -466,6 +474,7 @@
CE58759D29601476005D967E /* LoadingIndicator.swift */,
CE58759F29601500005D967E /* Toast.swift */,
CE6655C9295D84DD00C64E12 /* UserDefaultKeyList.swift */,
CEC2A68F2962B06C00160BF7 /* convertLocationObject.swift */,
);
path = Utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -513,6 +522,7 @@
CE6655B6295D803C00C64E12 /* UIComponents */ = {
isa = PBXGroup;
children = (
CEC2A6882962ADB900160BF7 /* MapView */,
CEEC6B4A2961D89700D00E1E /* CustomNavigationBar.swift */,
CEC2A6842961F92C00160BF7 /* CustomButton.swift */,
);
Expand Down Expand Up @@ -593,6 +603,16 @@
path = "UIKit+";
sourceTree = "<group>";
};
CEC2A6882962ADB900160BF7 /* MapView */ = {
isa = PBXGroup;
children = (
CEC2A6892962ADCD00160BF7 /* RNMapView.swift */,
CEC2A68B2962AE1B00160BF7 /* RNStartMarker.swift */,
CEC2A68D2962AF2C00160BF7 /* RNMarker.swift */,
);
path = MapView;
sourceTree = "<group>";
};
CEEC6B472961C5CA00D00E1E /* VC */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -765,6 +785,7 @@
CE6655E8295D889600C64E12 /* UISwitch+.swift in Sources */,
CE5875A029601500005D967E /* Toast.swift in Sources */,
CE6655F6295D90B600C64E12 /* addToolBar.swift in Sources */,
CEC2A68A2962ADCD00160BF7 /* RNMapView.swift in Sources */,
CE6655F0295D891B00C64E12 /* UITextView+.swift in Sources */,
CE6655EE295D88E600C64E12 /* UITextField+.swift in Sources */,
CE6655F8295D90CF00C64E12 /* adjusted+.swift in Sources */,
Expand All @@ -776,6 +797,7 @@
CE6655D4295D865B00C64E12 /* Publisher+UIControl.swift in Sources */,
CE6655EC295D88D000C64E12 /* UITableView+.swift in Sources */,
CEEC6B3A2961C4F300D00E1E /* CourseDrawingHomeVC.swift in Sources */,
CEC2A6902962B06C00160BF7 /* convertLocationObject.swift in Sources */,
CEC2A6852961F92C00160BF7 /* CustomButton.swift in Sources */,
CE66560C295D928300C64E12 /* setRootViewController.swift in Sources */,
CE6655D9295D871B00C64E12 /* URL+.swift in Sources */,
Expand All @@ -785,9 +807,11 @@
CE665612295D92E400C64E12 /* UserDefaultWrapper.swift in Sources */,
CE665610295D92C200C64E12 /* setTextLineHeight.swift in Sources */,
CE6655E2295D87EB00C64E12 /* UIImage+.swift in Sources */,
CEC2A68C2962AE1B00160BF7 /* RNStartMarker.swift in Sources */,
CE5875A4296015D2005D967E /* Encodable+.swift in Sources */,
CEEC6B4B2961D89700D00E1E /* CustomNavigationBar.swift in Sources */,
CE17F02D2961BBA100E1DED0 /* ColorLiterals.swift in Sources */,
CEC2A68E2962AF2C00160BF7 /* RNMarker.swift in Sources */,
CE6655D2295D862A00C64E12 /* Publisher+Driver.swift in Sources */,
CE6655E6295D887F00C64E12 /* UIStackView+.swift in Sources */,
CE6655CA295D84DD00C64E12 /* UserDefaultKeyList.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,13 @@ extension UIImage {
}
return renderImage
}

/// UIView를 image로 변환
convenience init(view: UIView) {
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.isOpaque, 0.0)
view.drawHierarchy(in: view.bounds, afterScreenUpdates: false)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
self.init(cgImage: (image?.cgImage)!)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
guard let windowScene = (scene as? UIWindowScene) else { return }

let window = UIWindow(windowScene: windowScene)
window.rootViewController = UINavigationController(rootViewController: SplashVC())
window.rootViewController = TabBarController()
self.window = window
window.makeKeyAndVisible()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// RNMapView.swift
// Runnect-iOS
//
// Created by sejin on 2023/01/02.
//

import Foundation
38 changes: 38 additions & 0 deletions Runnect-iOS/Runnect-iOS/Global/UIComponents/MapView/RNMarker.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// RNMarker.swift
// Runnect-iOS
//
// Created by sejin on 2023/01/02.
//

import UIKit

import NMapsMap
import SnapKit
import Then

final class RNMarker: NMFMarker {

// MARK: - initialization

override init() {
super.init()
setUI()
}
}

// MARK: - UI & Layout

extension RNMarker {
private func setUI() {
let image = NMFOverlayImage(image: ImageLiterals.icMapPoint)
self.iconImage = image

self.width = CGFloat(NMF_MARKER_SIZE_AUTO)
self.height = CGFloat(NMF_MARKER_SIZE_AUTO)

self.anchor = CGPoint(x: 0.5, y: 0.5)

self.iconPerspectiveEnabled = true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// RNStartMarker.swift
// Runnect-iOS
//
// Created by sejin on 2023/01/02.
//

import UIKit

import NMapsMap
import SnapKit
import Then

final class RNStartMarker: NMFMarker {

// MARK: - UI & Layout

let startInfoWindow = NMFInfoWindow()

// MARK: - initialization

override init() {
super.init()
setUI()
setInfoWindow()
}
}

// MARK: - UI & Layout

extension RNStartMarker {
private func setUI() {
let image = NMFOverlayImage(image: ImageLiterals.icMapDeparture)
self.iconImage = image

self.width = CGFloat(NMF_MARKER_SIZE_AUTO)
self.height = CGFloat(NMF_MARKER_SIZE_AUTO)

self.anchor = CGPoint(x: 0.5, y: 0.5)

self.iconPerspectiveEnabled = true
}

private func setInfoWindow() {
startInfoWindow.dataSource = self
}

func showInfoWindow() {
startInfoWindow.open(with: self)
}

func hideInfoWindow() {
startInfoWindow.close()
}
}

// MARK: - NMFOverlayImageDataSource

extension RNStartMarker: NMFOverlayImageDataSource {
func view(with overlay: NMFOverlay) -> UIView {
// 마커 위에 보여줄 InfoView 이미지 리턴
let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 58, height: 34))
imageView.image = ImageLiterals.icMapDeparture
return imageView
}
}
29 changes: 29 additions & 0 deletions Runnect-iOS/Runnect-iOS/Global/Utils/convertLocationObject.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// convertLocationObject.swift
// Runnect-iOS
//
// Created by sejin on 2023/01/02.
//

import Foundation
import CoreLocation

import NMapsMap

extension CLLocationCoordinate2D? {
func toNMGLatLng() -> NMGLatLng {
return NMGLatLng(lat: self?.latitude ?? 37.52901832956373, lng: self?.longitude ?? 126.9136196847032)
}
}

extension CLLocationCoordinate2D {
func toNMGLatLng() -> NMGLatLng {
return NMGLatLng(lat: self.latitude, lng: self.longitude)
}
}

extension NMGLatLng {
func toCLLocation() -> CLLocation {
return CLLocation(latitude: lat, longitude: lng)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,50 @@

import UIKit

final class CourseDrawingHomeVC: UIViewController, CustomNavigationBarDelegate {
lazy var naviBar = CustomNavigationBar(self, type: .title).setTitle("보관함")
// lazy var naviBar = CustomNavigationBar(self, type: .titleWithLeftButton)
// lazy var naviBar = CustomNavigationBar(self, type: .titleWithLeftButton).setTitle("목표 보상")
// lazy var naviBar = CustomNavigationBar(self, type: .search).showKeyboard().setTextFieldPlaceholder(placeholder: "출발지 검색")
final class CourseDrawingHomeVC: UIViewController {

let button = CustomButton(title: "코스 그리기")
// MARK: - Properties

private lazy var tabBarHeight = self.tabBarController?.tabBar.frame.size.height ?? 49

// MARK: - UI Components

private lazy var mapView = RNMapView()
.setPositionMode(mode: .normal)
.makeContentPadding(padding: UIEdgeInsets(top: -calculateTopInset(), left: 0, bottom: tabBarHeight, right: 0))
.moveToUserLocation()
.showLocationButton(toShow: true)

private let drawCourseButton = CustomButton(title: "코스 그리기")

// MARK: - View Life Cycle

override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white

naviBar.delegate = self

view.addSubviews(naviBar, button)
self.setUI()
self.setLayout()
}
}

// MARK: - UI & Layout

extension CourseDrawingHomeVC {
private func setUI() {
view.backgroundColor = .w1
}

private func setLayout() {
view.addSubviews(mapView, drawCourseButton)

naviBar.snp.makeConstraints { make in
make.leading.top.trailing.equalTo(view.safeAreaLayoutGuide)
make.height.equalTo(48)
mapView.snp.makeConstraints { make in
make.top.bottom.equalToSuperview()
make.leading.trailing.equalTo(view.safeAreaLayoutGuide)
}

button.snp.makeConstraints { make in
make.leading.bottom.trailing.equalTo(view.safeAreaLayoutGuide).inset(20)
drawCourseButton.snp.makeConstraints { make in
make.leading.trailing.equalTo(view.safeAreaLayoutGuide).inset(75)
make.bottom.equalTo(view.safeAreaLayoutGuide).inset(24)
make.height.equalTo(44)
}
}

func searchButtonDidTap(text: String) {
print(text)
}
}

0 comments on commit daaa336

Please sign in to comment.