Manos Chorianopoulos

Add MapViewController

...@@ -4367,66 +4367,6 @@ ...@@ -4367,66 +4367,6 @@
4367 <outlet property="titleLabel" destination="qfZ-mQ-mRL" id="1Bw-YT-TGA"/> 4367 <outlet property="titleLabel" destination="qfZ-mQ-mRL" id="1Bw-YT-TGA"/>
4368 </connections> 4368 </connections>
4369 </tableViewCell> 4369 </tableViewCell>
4370 - <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" selectionStyle="none" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="InboxTableViewCellId" id="tNJ-bm-aGv" customClass="InboxTableViewCell" customModule="SwiftWarplyFramework" customModuleProvider="target">
4371 - <rect key="frame" x="0.0" y="338" width="414" height="78.5"/>
4372 - <autoresizingMask key="autoresizingMask"/>
4373 - <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="tNJ-bm-aGv" id="A90-Li-IDd">
4374 - <rect key="frame" x="0.0" y="0.0" width="414" height="78.5"/>
4375 - <autoresizingMask key="autoresizingMask"/>
4376 - <subviews>
4377 - <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Iar-hb-ngF">
4378 - <rect key="frame" x="20" y="0.0" width="374" height="78.5"/>
4379 - <subviews>
4380 - <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="q3d-Y7-YoH">
4381 - <rect key="frame" x="0.0" y="0.0" width="205.5" height="78.5"/>
4382 - </imageView>
4383 - <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dNf-ph-58z">
4384 - <rect key="frame" x="215.5" y="30" width="148.5" height="18.5"/>
4385 - <fontDescription key="fontDescription" name="PeridotPE-Regular" family="Peridot PE" pointSize="15"/>
4386 - <color key="textColor" red="0.12941176469999999" green="0.12941176469999999" blue="0.12941176469999999" alpha="1" colorSpace="calibratedRGB"/>
4387 - <nil key="highlightedColor"/>
4388 - </label>
4389 - </subviews>
4390 - <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
4391 - <constraints>
4392 - <constraint firstAttribute="bottom" secondItem="q3d-Y7-YoH" secondAttribute="bottom" id="3lu-rv-RHI"/>
4393 - <constraint firstItem="dNf-ph-58z" firstAttribute="leading" secondItem="q3d-Y7-YoH" secondAttribute="trailing" constant="10" id="BE4-GU-dWc"/>
4394 - <constraint firstItem="q3d-Y7-YoH" firstAttribute="width" secondItem="Iar-hb-ngF" secondAttribute="width" multiplier="0.55" id="GNH-sm-qA8"/>
4395 - <constraint firstItem="q3d-Y7-YoH" firstAttribute="top" secondItem="Iar-hb-ngF" secondAttribute="top" id="H2X-D0-SQ0"/>
4396 - <constraint firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="dNf-ph-58z" secondAttribute="bottom" constant="10" id="HMr-jg-Egf"/>
4397 - <constraint firstItem="dNf-ph-58z" firstAttribute="centerY" secondItem="Iar-hb-ngF" secondAttribute="centerY" id="XRe-mw-R0J"/>
4398 - <constraint firstAttribute="trailing" secondItem="dNf-ph-58z" secondAttribute="trailing" constant="10" id="ZAx-jV-hle"/>
4399 - <constraint firstItem="q3d-Y7-YoH" firstAttribute="leading" secondItem="Iar-hb-ngF" secondAttribute="leading" id="d71-vY-Cgu"/>
4400 - <constraint firstItem="dNf-ph-58z" firstAttribute="top" relation="greaterThanOrEqual" secondItem="Iar-hb-ngF" secondAttribute="top" constant="30" id="oM5-Tj-eb3"/>
4401 - </constraints>
4402 - </view>
4403 - <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="new_icon" translatesAutoresizingMaskIntoConstraints="NO" id="0IZ-qO-cKj">
4404 - <rect key="frame" x="344" y="5" width="60" height="25"/>
4405 - <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
4406 - <constraints>
4407 - <constraint firstAttribute="width" constant="60" id="ltd-9h-en3"/>
4408 - <constraint firstAttribute="height" constant="25" id="sjV-4S-ggn"/>
4409 - </constraints>
4410 - </imageView>
4411 - </subviews>
4412 - <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
4413 - <constraints>
4414 - <constraint firstItem="0IZ-qO-cKj" firstAttribute="top" secondItem="A90-Li-IDd" secondAttribute="top" constant="5" id="1GR-gl-rM7"/>
4415 - <constraint firstAttribute="trailing" secondItem="0IZ-qO-cKj" secondAttribute="trailing" constant="10" id="6QW-pj-851"/>
4416 - <constraint firstItem="Iar-hb-ngF" firstAttribute="leading" secondItem="A90-Li-IDd" secondAttribute="leading" constant="20" id="DbD-oU-ViN"/>
4417 - <constraint firstAttribute="trailing" secondItem="Iar-hb-ngF" secondAttribute="trailing" constant="20" id="IQM-tY-Clq"/>
4418 - <constraint firstAttribute="bottom" secondItem="Iar-hb-ngF" secondAttribute="bottom" id="SKJ-aq-DIL"/>
4419 - <constraint firstItem="Iar-hb-ngF" firstAttribute="top" secondItem="A90-Li-IDd" secondAttribute="top" id="s7S-Fw-x5P"/>
4420 - </constraints>
4421 - </tableViewCellContentView>
4422 - <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
4423 - <connections>
4424 - <outlet property="campaignImage" destination="q3d-Y7-YoH" id="mSE-US-ead"/>
4425 - <outlet property="campaignTitleLabel" destination="dNf-ph-58z" id="OL1-vm-neo"/>
4426 - <outlet property="inboxView" destination="Iar-hb-ngF" id="sYI-hQ-yfh"/>
4427 - <outlet property="newBadgeImage" destination="0IZ-qO-cKj" id="2Vu-X1-ZX6"/>
4428 - </connections>
4429 - </tableViewCell>
4430 </prototypes> 4370 </prototypes>
4431 <connections> 4371 <connections>
4432 <outlet property="dataSource" destination="EDh-Zo-yDu" id="Few-SN-h9B"/> 4372 <outlet property="dataSource" destination="EDh-Zo-yDu" id="Few-SN-h9B"/>
...@@ -4468,17 +4408,34 @@ ...@@ -4468,17 +4408,34 @@
4468 <rect key="frame" x="0.0" y="0.0" width="414" height="896"/> 4408 <rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
4469 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> 4409 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
4470 <subviews> 4410 <subviews>
4471 - <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="MapViewController" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="hxt-S7-xrl"> 4411 + <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Rec-xf-ksW" userLabel="Main View">
4472 - <rect key="frame" x="127" y="437" width="145" height="21"/> 4412 + <rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
4473 - <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> 4413 + <subviews>
4474 - <fontDescription key="fontDescription" type="system" pointSize="17"/> 4414 + <mapView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" mapType="standard" translatesAutoresizingMaskIntoConstraints="NO" id="qZN-bc-ZwR">
4475 - <nil key="textColor"/> 4415 + <rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
4476 - <nil key="highlightedColor"/> 4416 + </mapView>
4477 - </label> 4417 + </subviews>
4418 + <color key="backgroundColor" systemColor="systemBackgroundColor"/>
4419 + <constraints>
4420 + <constraint firstItem="qZN-bc-ZwR" firstAttribute="top" secondItem="Rec-xf-ksW" secondAttribute="top" id="4kw-W4-pBb"/>
4421 + <constraint firstItem="qZN-bc-ZwR" firstAttribute="leading" secondItem="Rec-xf-ksW" secondAttribute="leading" id="6ig-4b-zI9"/>
4422 + <constraint firstAttribute="bottom" secondItem="qZN-bc-ZwR" secondAttribute="bottom" id="9X2-xK-rUq"/>
4423 + <constraint firstAttribute="trailing" secondItem="qZN-bc-ZwR" secondAttribute="trailing" id="L0O-xh-DcY"/>
4424 + </constraints>
4425 + </view>
4478 </subviews> 4426 </subviews>
4479 <viewLayoutGuide key="safeArea" id="bFi-bg-SVE"/> 4427 <viewLayoutGuide key="safeArea" id="bFi-bg-SVE"/>
4480 <color key="backgroundColor" systemColor="systemBackgroundColor"/> 4428 <color key="backgroundColor" systemColor="systemBackgroundColor"/>
4429 + <constraints>
4430 + <constraint firstAttribute="trailing" secondItem="Rec-xf-ksW" secondAttribute="trailing" id="BQY-2F-4YR"/>
4431 + <constraint firstItem="Rec-xf-ksW" firstAttribute="top" secondItem="YX1-Nw-62m" secondAttribute="top" id="HBe-12-Juu"/>
4432 + <constraint firstItem="Rec-xf-ksW" firstAttribute="leading" secondItem="YX1-Nw-62m" secondAttribute="leading" id="OjV-oz-5gW"/>
4433 + <constraint firstAttribute="bottom" secondItem="Rec-xf-ksW" secondAttribute="bottom" id="uP7-ob-anK"/>
4434 + </constraints>
4481 </view> 4435 </view>
4436 + <connections>
4437 + <outlet property="mapView" destination="qZN-bc-ZwR" id="3WA-X6-PXu"/>
4438 + </connections>
4482 </viewController> 4439 </viewController>
4483 <placeholder placeholderIdentifier="IBFirstResponder" id="7av-3d-VKz" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/> 4440 <placeholder placeholderIdentifier="IBFirstResponder" id="7av-3d-VKz" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
4484 </objects> 4441 </objects>
......
...@@ -5,25 +5,143 @@ ...@@ -5,25 +5,143 @@
5 // Created by Manos Chorianopoulos on 7/2/24. 5 // Created by Manos Chorianopoulos on 7/2/24.
6 // 6 //
7 7
8 +
8 import UIKit 9 import UIKit
10 +import MapKit
11 +
12 +@objc public class MapViewController: UIViewController, MKMapViewDelegate {
13 + @IBOutlet private var mapView: MKMapView!
14 +
15 + var merchantsArray:Array<swiftApi.MerchantModel> = []
16 +
9 17
10 -@objc public class MapViewController: UIViewController { 18 + var loading: Bool = false
19 + let initialLocation = CLLocation(latitude: 37.9641262, longitude: 23.7468592) // greece
11 20
12 public override func viewDidLoad() { 21 public override func viewDidLoad() {
13 super.viewDidLoad() 22 super.viewDidLoad()
14 23
15 - // Do any additional setup after loading the view. 24 +// self.hidesBottomBarWhenPushed = true
25 +
26 + mapView.delegate = self
27 + mapView.centerToLocation(initialLocation, regionRadius: 1000000)
28 +
29 + load()
16 } 30 }
17 31
32 + public override func viewWillAppear(_ animated: Bool) {
33 + super.viewWillAppear(animated)
18 34
19 - /* 35 +// self.navigationController?.hideHairline()
20 - // MARK: - Navigation 36 + }
21 37
22 - // In a storyboard-based application, you will often want to do a little preparation before navigation 38 + @objc func load() {
23 - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 39 +
24 - // Get the new view controller using segue.destination. 40 + if (loading) {
25 - // Pass the selected object to the new view controller. 41 + return;
42 + }
43 + showLoading()
44 +
45 + self.merchantsArray = generateRandomMerchantsInGreece()
46 + self.loadMapPins()
47 + showContent()
26 } 48 }
27 - */
28 49
50 + func generateRandomMerchantsInGreece() -> Array<swiftApi.MerchantModel> {
51 + // Define the approximate bounding box coordinates for Greece
52 + let greeceBoundingBox = MKCoordinateRegion(
53 + center: CLLocationCoordinate2D(latitude: 38.5, longitude: 23.0),
54 + span: MKCoordinateSpan(latitudeDelta: 2.0, longitudeDelta: 3.0)
55 + )
56 +
57 + // Generate 10 random merchants within Greece's bounding box
58 + var randomMerchants: Array<swiftApi.MerchantModel> = []
59 + for _ in 1...10 {
60 + let randomLatitude = Double.random(in: greeceBoundingBox.center.latitude - greeceBoundingBox.span.latitudeDelta / 2 ... greeceBoundingBox.center.latitude + greeceBoundingBox.span.latitudeDelta / 2)
61 + let randomLongitude = Double.random(in: greeceBoundingBox.center.longitude - greeceBoundingBox.span.longitudeDelta / 2 ... greeceBoundingBox.center.longitude + greeceBoundingBox.span.longitudeDelta / 2)
62 +
63 + let randomMerchant = swiftApi.MerchantModel()
64 + randomMerchant._latitude = randomLatitude
65 + randomMerchant._longitude = randomLongitude
66 +
67 + randomMerchants.append(randomMerchant)
68 + }
69 +
70 + return randomMerchants
71 + }
72 +
73 +
74 + private func showLoading() {
75 +
76 + loading = true
77 + }
78 +
79 + private func showContent() {
80 +
81 + loading = false
82 + }
83 +
84 + private func loadMapPins() {
85 + for item in merchantsArray {
86 + let pin = MerchantAnnotation(item)
87 +
88 + if let annotationView = mapView.view(for: pin) {
89 + annotationView.isEnabled = false
90 + }
91 + mapView.addAnnotation(pin)
92 +
93 + }
94 + }
95 +
96 + // map view delegate
97 + public func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
98 +
99 +// guard !(annotation is MKUserLocation) else {
100 +// return nil
101 +// }
102 +
103 + var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "warply_custom")
104 + if (annotationView == nil) {
105 + annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "warply_custom")
106 + annotationView?.canShowCallout = false
107 + } else {
108 + annotationView?.annotation = annotation
109 + }
110 +
111 + // custom pin image
112 + let customImageSize = CGSize(width: 60, height: 50)
113 +
114 + annotationView?.image = UIImage(named: "map_marker", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
115 +
116 +
117 + annotationView?.frame = CGRect(x: 0, y: 0, width: customImageSize.width, height: customImageSize.height)
118 +
119 + // Add shadow
120 + annotationView?.layer.shadowColor = UIColor(red: 0.00, green: 0.00, blue: 0.00, alpha: 0.16).cgColor
121 + annotationView?.layer.shadowOffset = CGSize(width: 0.0, height: 3.0)
122 + annotationView?.layer.shadowOpacity = 1.0
123 + annotationView?.layer.shadowRadius = 6.0
124 +
125 + return annotationView
126 + }
127 +
128 + public func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
129 + // Disable the default behavior of selecting and zooming in on the pin
130 + mapView.deselectAnnotation(view.annotation, animated: false)
131 + }
132 +
133 + public func mapView(_ mapView: MKMapView, didDeselect view: MKAnnotationView) {
134 +
135 + }
136 +}
137 +
138 +private extension MKMapView {
139 +
140 + func centerToLocation(_ location: CLLocation, regionRadius: CLLocationDistance = 1000) {
141 + let coordinateRegion = MKCoordinateRegion(
142 + center: location.coordinate,
143 + latitudinalMeters: regionRadius,
144 + longitudinalMeters: regionRadius)
145 + setRegion(coordinateRegion, animated: true)
146 + }
29 } 147 }
......