Skip to content

Commit

Permalink
Feat: Show markers and info windows #71
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
jinios committed Jun 29, 2019
1 parent 923049a commit 8550f04
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 5 deletions.
8 changes: 8 additions & 0 deletions MartHoliday/MartHoliday.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -246,6 +248,8 @@
FDE2542D21627303008B25C8 /* NoMapView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NoMapView.xib; sourceTree = "<group>"; };
FDEECC2C214CD3BD00F6FF09 /* MartHolidayTodayExtension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = MartHolidayTodayExtension.entitlements; sourceTree = "<group>"; };
FDEEE8E72163B5BD00E63733 /* NoMapView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoMapView.swift; sourceTree = "<group>"; };
FDF492C622B4E59100827025 /* MarkerInfoWindowView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MarkerInfoWindowView.xib; sourceTree = "<group>"; };
FDF492C822B4E59C00827025 /* MarkerInfoWindowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarkerInfoWindowView.swift; sourceTree = "<group>"; };
FDF8ABC1215B722800DA74C9 /* FavoriteBranch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoriteBranch.swift; sourceTree = "<group>"; };
FDF8ABC3215B76B400DA74C9 /* MainTableViewHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTableViewHeader.swift; sourceTree = "<group>"; };
FDF8ABC5215B76FC00DA74C9 /* MainTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTableViewCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -325,6 +329,8 @@
FDC19BA9215D2D54007D9A95 /* NoDataView.swift */,
FDEEE8E72163B5BD00E63733 /* NoMapView.swift */,
FD5359FD225F8BDB00AB48BE /* MartMapView.swift */,
FDF492C822B4E59C00827025 /* MarkerInfoWindowView.swift */,
FDF492C622B4E59100827025 /* MarkerInfoWindowView.xib */,
);
path = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
57 changes: 57 additions & 0 deletions MartHoliday/MartHoliday/View/MarkerInfoWindowView.swift
Original file line number Diff line number Diff line change
@@ -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
}



}
71 changes: 71 additions & 0 deletions MartHoliday/MartHoliday/View/MarkerInfoWindowView.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<customFonts key="customFonts">
<array key="NanumSquareRoundOTFR.otf">
<string>NanumSquareRoundOTFR</string>
</array>
</customFonts>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="MarkerInfoWindowView" customModule="MartHoliday" customModuleProvider="target">
<connections>
<outlet property="branchTitle" destination="gal-vv-uIe" id="49s-aC-qqS"/>
<outlet property="contentView" destination="LNM-4r-Da5" id="4fT-Kd-cm4"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB">
<rect key="frame" x="0.0" y="0.0" width="200" height="40"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="LNM-4r-Da5">
<rect key="frame" x="38" y="5" width="124" height="30"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" spacing="4" translatesAutoresizingMaskIntoConstraints="NO" id="I2y-vF-Qin">
<rect key="frame" x="7" y="5" width="110" height="20"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="이마트 성수점" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="gal-vv-uIe">
<rect key="frame" x="0.0" y="0.0" width="86" height="20"/>
<fontDescription key="fontDescription" name="NanumSquareRoundOTFR" family="NanumSquareRoundOTF" pointSize="15"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="rightArrow" translatesAutoresizingMaskIntoConstraints="NO" id="HIa-Wt-TSC">
<rect key="frame" x="90" y="0.0" width="20" height="20"/>
</imageView>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" constant="20" id="d9M-Uw-KMG"/>
</constraints>
</stackView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" secondItem="I2y-vF-Qin" secondAttribute="height" multiplier="1.5" id="S28-nF-rQn"/>
<constraint firstAttribute="trailing" secondItem="I2y-vF-Qin" secondAttribute="trailing" constant="7" id="ZRN-Ht-N9V"/>
<constraint firstItem="I2y-vF-Qin" firstAttribute="centerY" secondItem="LNM-4r-Da5" secondAttribute="centerY" id="nRl-If-v7W"/>
<constraint firstItem="I2y-vF-Qin" firstAttribute="leading" secondItem="LNM-4r-Da5" secondAttribute="leading" constant="7" id="uRm-gx-zG2"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="LNM-4r-Da5" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="centerY" id="PfA-Ks-2Lm"/>
<constraint firstItem="LNM-4r-Da5" firstAttribute="centerX" secondItem="iN0-l3-epB" secondAttribute="centerX" id="WIN-Vd-Q3A"/>
</constraints>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<point key="canvasLocation" x="-222" y="-117"/>
</view>
</objects>
<resources>
<image name="rightArrow" width="20" height="20"/>
</resources>
</document>
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)

Expand All @@ -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()
Expand Down

0 comments on commit 8550f04

Please sign in to comment.