Manos Chorianopoulos

add custom pins at MapsViewController

...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
7 <key>Pods-SwiftWarplyFramework.xcscheme_^#shared#^_</key> 7 <key>Pods-SwiftWarplyFramework.xcscheme_^#shared#^_</key>
8 <dict> 8 <dict>
9 <key>orderHint</key> 9 <key>orderHint</key>
10 - <integer>0</integer> 10 + <integer>1</integer>
11 </dict> 11 </dict>
12 </dict> 12 </dict>
13 </dict> 13 </dict>
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
7 <key>SwiftWarplyFramework.xcscheme_^#shared#^_</key> 7 <key>SwiftWarplyFramework.xcscheme_^#shared#^_</key>
8 <dict> 8 <dict>
9 <key>orderHint</key> 9 <key>orderHint</key>
10 - <integer>1</integer> 10 + <integer>0</integer>
11 </dict> 11 </dict>
12 </dict> 12 </dict>
13 </dict> 13 </dict>
......
...@@ -441,6 +441,58 @@ import MapKit ...@@ -441,6 +441,58 @@ import MapKit
441 // return annotationView 441 // return annotationView
442 // } 442 // }
443 443
444 + // map view delegate
445 + public func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
446 +
447 +// guard !(annotation is MKUserLocation) else {
448 +// return nil
449 +// }
450 +
451 + var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "warply_custom")
452 + if (annotationView == nil) {
453 + annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "warply_custom")
454 + annotationView?.canShowCallout = false
455 +
456 + } else {
457 + annotationView?.annotation = annotation
458 + }
459 +
460 + // Add custom pin image
461 + annotationView?.frame = CGRect(x: 0, y: 0, width: 45, height: 60)
462 +
463 + let pinImageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 45, height: 60))
464 + pinImageView.contentMode = .scaleAspectFit
465 +
466 + if let pinImg = UIImage(named: "map_pin", in: MyEmptyClass.resourceBundle(), compatibleWith: nil) {
467 + pinImageView.image = pinImg
468 + }
469 +
470 + let logoImageView = UIImageView(frame: CGRect(x: 5, y: 5, width: 35, height: 35))
471 + logoImageView.contentMode = .scaleAspectFit
472 +
473 + let merchant = annotation as? MerchantAnnotation
474 + if let merchantModel = merchant?.model {
475 +
476 + let currentMerchant = merchantModel
477 +
478 + if let parent = self.parentMerchantsArray.first(where: {($0._uuid == currentMerchant._parent)}) {
479 + let currentMerchantParent = parent
480 +
481 + if (self.isMarket == true) {
482 + logoImageView.load(link: currentMerchantParent._img_preview , placeholder: UIImage(), cache: URLCache())
483 + } else {
484 + logoImageView.load(link: currentMerchant._img_preview , placeholder: UIImage(), cache: URLCache())
485 + }
486 + }
487 +
488 + }
489 +
490 + pinImageView.addSubview(logoImageView)
491 + annotationView?.addSubview(pinImageView)
492 +
493 + return annotationView
494 + }
495 +
444 public func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) { 496 public func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
445 let merchant = view.annotation as? MerchantAnnotation 497 let merchant = view.annotation as? MerchantAnnotation
446 let merchantModel = merchant!.model 498 let merchantModel = merchant!.model
......
1 +{
2 + "images" : [
3 + {
4 + "filename" : "map_pin.png",
5 + "idiom" : "universal",
6 + "scale" : "1x"
7 + },
8 + {
9 + "filename" : "map_pin 1.png",
10 + "idiom" : "universal",
11 + "scale" : "2x"
12 + },
13 + {
14 + "filename" : "map_pin 2.png",
15 + "idiom" : "universal",
16 + "scale" : "3x"
17 + }
18 + ],
19 + "info" : {
20 + "author" : "xcode",
21 + "version" : 1
22 + }
23 +}