This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Man { | |
var closure: (() -> Void)? | |
var name: String = "Frank" | |
init() { | |
closure = { [weak self] in | |
guard let self = self else { return } | |
print("Init with \(self.name)") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Man { | |
var closure: (() -> Void)? | |
var name: String = "Frank" | |
init() { | |
closure = { print("Init with \(self.name)") } | |
} | |
deinit { | |
print("Deinit") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func log(WithDefaultValue anything: Any, file: String = #file, line: Int = #line, column: Int = #column, function: String = #function) { | |
print("log: \(anything) \nfile = \(file) \ncolumn = \(column) \nline = \(line) \nfunction = \(function)") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func log(anything: Any) { | |
print("log: \(anything)\n #file: \(#file)\n #line: \(#line)\n #column: \(#column)\n #function: \(#function)\n #dsohandle: \(#dsohandle)") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: - GMUClusterRendererDelegate | |
extension ViewController: GMUClusterRendererDelegate { | |
/// 回傳一標記,此 delegate 可用來控制標記的生命週期。例如:設定標記的座標、圖片等等 | |
/// - Parameter renderer: _ | |
/// - Parameter object: _ | |
func renderer(_ renderer: GMUClusterRenderer, markerFor object: Any) -> GMSMarker? { | |
switch object { | |
case let clusterItem as ClusterItem: | |
return MyMaker(markerData: clusterItem.markerData) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: - Property | |
var clusterManager: GMUClusterManager! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 初始化地圖上的 Cluster Item | |
self.initMapViewMarker(markerDataFromServerDataList) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 初始化地圖上的 Cluster Item | |
/// - Parameter markerDataFromServerDataList: _ | |
private func initMapViewMarker(_ markerDataFromServerDataList: [MarkerData]) { | |
markerDataFromServerDataList | |
.map{ MyMaker(markerData: $0) } | |
.forEach { | |
let item = ClusterItem(markerData: $0.markerData) | |
self.clusterManager.add(item) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let markerDataFromServerDataList: [MarkerData] = [ | |
MarkerData(position: CLLocationCoordinate2D(latitude: 25.033671, longitude: 121.564427), title: "Taiwan", snippet: "台北101"), | |
MarkerData(position: CLLocationCoordinate2D(latitude: 25.037962, longitude: 121.564561), title: "Taiwan", snippet: "台北市政府"), | |
MarkerData(position: CLLocationCoordinate2D(latitude: 25.037056, longitude: 121.568149), title: "Taiwan", snippet: "信義威秀"), | |
MarkerData(position: CLLocationCoordinate2D(latitude: 25.029127, longitude: 121.553888), title: "Taiwan", snippet: "通化街"), | |
MarkerData(position: CLLocationCoordinate2D(latitude: 25.028163, longitude: 121.570634), title: "Taiwan", snippet: "象山") | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 生成 Cluster Manager | |
let iconGenerator = GMUDefaultClusterIconGenerator() | |
let algorithm = GMUNonHierarchicalDistanceBasedAlgorithm() | |
let renderer = GMUDefaultClusterRenderer(mapView: self.mapView, clusterIconGenerator: iconGenerator) | |
renderer.delegate = self | |
self.clusterManager = GMUClusterManager(map: self.mapView, algorithm: algorithm, renderer: renderer) | |
self.clusterManager.setDelegate(self, mapDelegate: self) |
NewerOlder