//MARK: ⚡+++ MKMapViewDelegate アノテーションビューを返すメソッド
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
print("== MKMapViewDelegate - viewFor annotation")
// MARK: === アノテーションビューを生成する。
let anoPinView = MKPinAnnotationView()
// MARK: === アノテーションビューに座標、タイトル、サブタイトルを設定する。
anoPinView.annotation = annotation
// MARK: === 現在地のアノテーションビューを設定する。
if annotation === mapView.userLocation { // 現在地を示すアノテーションの場合はデフォルトのまま
let identifier = "annotation"
if let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "annotation") { // 再利用できる場合はそのまま返す
return annotationView
}
else { // 再利用できるアノテーションが無い場合(初回など)は生成する
let annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: identifier)
annotationView.image = UIImage(named: "curpos2") //⭐のマーク印
return annotationView
}
}
// MARK: === 「吹き出し」の編集 == カスタムAnnotationの表示
else if let customAnno = annotation as? CustomMKPointAnnotation {
// ・・・ CustomMKPointAnnotation は、プチカスタマ用のMKAnnotationです。
}
else{
anoPinView.pinTintColor = UIColor.purple
}
//吹き出しの表示をONにする。
anoPinView.canShowCallout = true
return anoPinView
}