googlemaps / googlemaps/google-maps-ios-utils
I want display multiple cluster images based on markers data
- Dominant language
- Objective-C
- Stars
- 778
- Forks
- 441
- PR merge metrics
- No merged PRs in 30d
Description
Hi all,
I want to display cluster images based on marker data on the cluster, able to update the cluster image but it applies to all the clusters. Please see the bellow screenshot.
func renderer(_ renderer: GMUClusterRenderer, willRenderMarker marker: GMSMarker) {
let zoom = Int(mapView.camera.zoom)
let clusteredItems = clusterManager.algorithm.clusters(atZoom: Float(zoom))
if let clusterItem = marker.userData as? GMUCluster {
for staticCluster in clusteredItems {
let movingItems = Double(staticCluster.items.filter { $0.title == "MapsMarkerGreen" }.count)
let idleItems = Double(staticCluster.items.filter { $0.title == "MapsMarkerBlue" }.count)
let stoppedLessThan60 = Double(staticCluster.items.filter { $0.title == "MapsMarkerYellow" }.count)
let stoppedGreaterThan60 = Double(staticCluster.items.filter { $0.title == "MapsMarkerRed" }.count)
let outOfRange = Double(staticCluster.items.filter { $0.title == "MapsMarkerGrey" }.count)
let totalItems = staticCluster.items.count
let multiColorBorderView = PercentageColorBorderView(frame: CGRect(x: 0, y: 0, width: 44, height: 44))
multiColorBorderView.updateBorderColors([(.green, movingItems), (.blue, idleItems), (.yellow, stoppedLessThan60), (.red, stoppedGreaterThan60), (.gray, outOfRange)])
let countLabel = UILabel(frame: CGRect(x: 2, y: 2, width: 40, height: 40))
countLabel.text = String(totalItems)
countLabel.textAlignment = .center
countLabel.font = UIFont(name: "", size: 15)
countLabel.textColor = .white
multiColorBorderView.addSubview(countLabel)
multiColorBorderView.setNeedsDisplay()
multiColorBorderView.backgroundColor = .clear
let clusterImage = multiColorBorderView.asImages()
marker.icon = clusterImage
}
}
}
Contributor guide
Assessment
This issue has not been assessed yet.