From 8550f042938273e96299e5d1ae845652ad09db58 Mon Sep 17 00:00:00 2001 From: Mijin Jeon Date: Sun, 30 Jun 2019 01:38:57 +0900 Subject: [PATCH] Feat: Show markers and info windows #71 - Search nearby marts from user's location - Set markers on map - Show info windows above each markers - Push to Mart detail info screen when tap info windows --- .../MartHoliday.xcodeproj/project.pbxproj | 8 +++ .../View/MarkerInfoWindowView.swift | 57 +++++++++++++++ .../MartHoliday/View/MarkerInfoWindowView.xib | 71 +++++++++++++++++++ .../LocationSearchViewController.swift | 14 ++-- 4 files changed, 145 insertions(+), 5 deletions(-) create mode 100644 MartHoliday/MartHoliday/View/MarkerInfoWindowView.swift create mode 100644 MartHoliday/MartHoliday/View/MarkerInfoWindowView.xib diff --git a/MartHoliday/MartHoliday.xcodeproj/project.pbxproj b/MartHoliday/MartHoliday.xcodeproj/project.pbxproj index bafb1c7..ae64de7 100644 --- a/MartHoliday/MartHoliday.xcodeproj/project.pbxproj +++ b/MartHoliday/MartHoliday.xcodeproj/project.pbxproj @@ -106,6 +106,8 @@ FDEECC32214D002700F6FF09 /* NanumSquareRoundOTFR.otf in Resources */ = {isa = PBXBuildFile; fileRef = FDAF601D21273E880006B68A /* NanumSquareRoundOTFR.otf */; }; FDEECC33214D0C6500F6FF09 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FDB4BE28211D6BAE00D3B264 /* Assets.xcassets */; }; FDEEE8E82163B5BD00E63733 /* NoMapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDEEE8E72163B5BD00E63733 /* NoMapView.swift */; }; + FDF492C722B4E59100827025 /* MarkerInfoWindowView.xib in Resources */ = {isa = PBXBuildFile; fileRef = FDF492C622B4E59100827025 /* MarkerInfoWindowView.xib */; }; + FDF492C922B4E59C00827025 /* MarkerInfoWindowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDF492C822B4E59C00827025 /* MarkerInfoWindowView.swift */; }; FDF8ABC2215B722800DA74C9 /* FavoriteBranch.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDF8ABC1215B722800DA74C9 /* FavoriteBranch.swift */; }; FDF8ABC4215B76B400DA74C9 /* MainTableViewHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDF8ABC3215B76B400DA74C9 /* MainTableViewHeader.swift */; }; FDF8ABC6215B76FC00DA74C9 /* MainTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDF8ABC5215B76FC00DA74C9 /* MainTableViewCell.swift */; }; @@ -246,6 +248,8 @@ FDE2542D21627303008B25C8 /* NoMapView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NoMapView.xib; sourceTree = ""; }; FDEECC2C214CD3BD00F6FF09 /* MartHolidayTodayExtension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = MartHolidayTodayExtension.entitlements; sourceTree = ""; }; FDEEE8E72163B5BD00E63733 /* NoMapView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoMapView.swift; sourceTree = ""; }; + FDF492C622B4E59100827025 /* MarkerInfoWindowView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MarkerInfoWindowView.xib; sourceTree = ""; }; + FDF492C822B4E59C00827025 /* MarkerInfoWindowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarkerInfoWindowView.swift; sourceTree = ""; }; FDF8ABC1215B722800DA74C9 /* FavoriteBranch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoriteBranch.swift; sourceTree = ""; }; FDF8ABC3215B76B400DA74C9 /* MainTableViewHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTableViewHeader.swift; sourceTree = ""; }; FDF8ABC5215B76FC00DA74C9 /* MainTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTableViewCell.swift; sourceTree = ""; }; @@ -325,6 +329,8 @@ FDC19BA9215D2D54007D9A95 /* NoDataView.swift */, FDEEE8E72163B5BD00E63733 /* NoMapView.swift */, FD5359FD225F8BDB00AB48BE /* MartMapView.swift */, + FDF492C822B4E59C00827025 /* MarkerInfoWindowView.swift */, + FDF492C622B4E59100827025 /* MarkerInfoWindowView.xib */, ); path = View; sourceTree = ""; @@ -626,6 +632,7 @@ FD086D7F22A3B54600030929 /* DistanceSlider.xib in Resources */, FDAF602221273E880006B68A /* NanumSquareRoundOTFEB.otf in Resources */, FDAF602021273E880006B68A /* NanumSquareRoundOTFB.otf in Resources */, + FDF492C722B4E59100827025 /* MarkerInfoWindowView.xib in Resources */, FD2B746E218A395F00A2BC9E /* SlideMenuView.xib in Resources */, FDAF602121273E880006B68A /* NanumSquareRoundOTFR.otf in Resources */, FDB26C5B2170711400313A02 /* InfoPlist.strings in Resources */, @@ -816,6 +823,7 @@ FD1CC4E1211DF76300B21E09 /* DetailViewController.swift in Sources */, FD0371D82208121800B2055F /* DistanceSearch.swift in Sources */, FD93878E225A39420082CC71 /* APIResponse.swift in Sources */, + FDF492C922B4E59C00827025 /* MarkerInfoWindowView.swift in Sources */, FD15A11021F38DBB00B7276A /* LocationSearchViewController.swift in Sources */, FDB3AD69216FBA7F002209A2 /* NetworkManager.swift in Sources */, FD11EAE321203A4C003EB3E9 /* BranchTableViewCell.swift in Sources */, diff --git a/MartHoliday/MartHoliday/View/MarkerInfoWindowView.swift b/MartHoliday/MartHoliday/View/MarkerInfoWindowView.swift new file mode 100644 index 0000000..8f7f37e --- /dev/null +++ b/MartHoliday/MartHoliday/View/MarkerInfoWindowView.swift @@ -0,0 +1,57 @@ +// +// MarkerInfoWindowView.swift +// MartHoliday +// +// Created by YOUTH2 on 15/06/2019. +// Copyright © 2019 JINiOS. All rights reserved. +// + +import UIKit +import NMapsMap + +class MarkerInfoWindowDataSource: NSObject, NMFOverlayImageDataSource { + + var branch: Branch? + + func view(with overlay: NMFOverlay) -> UIView { + let markerInfoView = MarkerInfoWindowView(branch: self.branch) + return markerInfoView.make() + } + +} + +class MarkerInfoWindowView: UIView { + + @IBOutlet weak var contentView: UIView! + @IBOutlet weak var branchTitle: UILabel! + var branch: Branch? + + override init(frame: CGRect) { + super.init(frame: frame) + self.commonInit() + } + + required init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + self.commonInit() + } + + convenience init(branch: Branch?) { + self.init(frame: CGRect(x: 100, y: 100, width: 100, height: 100)) + self.branch = branch + } + + private func commonInit() { + Bundle.main.loadNibNamed("MarkerInfoWindowView", owner: self, options: nil) + contentView.autoresizingMask = [.flexibleHeight, .flexibleWidth] + } + + func make() -> UIView { + self.branchTitle.text = self.branch?.displayName() + self.contentView.layoutIfNeeded() + return self.contentView + } + + + +} diff --git a/MartHoliday/MartHoliday/View/MarkerInfoWindowView.xib b/MartHoliday/MartHoliday/View/MarkerInfoWindowView.xib new file mode 100644 index 0000000..ec9f1d9 --- /dev/null +++ b/MartHoliday/MartHoliday/View/MarkerInfoWindowView.xib @@ -0,0 +1,71 @@ + + + + + + + + + + + + + NanumSquareRoundOTFR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/MartHoliday/MartHoliday/ViewController/LocationSearchViewController.swift b/MartHoliday/MartHoliday/ViewController/LocationSearchViewController.swift index 7ee4406..16df087 100644 --- a/MartHoliday/MartHoliday/ViewController/LocationSearchViewController.swift +++ b/MartHoliday/MartHoliday/ViewController/LocationSearchViewController.swift @@ -43,7 +43,8 @@ class LocationSearchViewController: IndicatorViewController, NMFMapViewDelegate var currentState: State = .disabled var infoWindow = NMFInfoWindow() - var defaultInfoWindowImage = NMFInfoWindowDefaultTextSource.data() + + var markerInfoWindowDataSource = MarkerInfoWindowDataSource() override func viewDidLoad() { super.viewDidLoad() @@ -169,7 +170,7 @@ extension LocationSearchViewController { } private func showMarkers(of branches: BranchList) { - let cameraUpdate = NMFCameraUpdate(zoomTo: REDUCTION_MAP_ZOOM_MAX) + let cameraUpdate = NMFCameraUpdate(zoomTo: REDUCTION_MAP_ZOOM_MIN) cameraUpdate.animation = .easeOut naverMapView.mapView.moveCamera(cameraUpdate) @@ -185,9 +186,12 @@ extension LocationSearchViewController { if let marker = overlay as? NMFMarker { if let nextVC = self?.storyboard?.instantiateViewController(withIdentifier: "detailVC") as? DetailViewController { nextVC.branchData = marker.userInfo["branch"] as? Branch - let displayName = (marker.userInfo["branch"] as? Branch)?.displayName() ?? "마트" - self?.defaultInfoWindowImage.title = displayName - self?.infoWindow.dataSource = self?.defaultInfoWindowImage + + let markerInfoDataSource = MarkerInfoWindowDataSource() + markerInfoDataSource.branch = marker.userInfo["branch"] as? Branch + + self?.infoWindow.dataSource = markerInfoDataSource + self?.infoWindow.open(with: marker, align: .top) self?.infoWindow.touchHandler = { [weak self] (overlay) in self?.infoWindow.close()