googlemaps / googlemaps/google-maps-ios-utils

I want display multiple cluster images based on markers data

Open
#462 1 comment 1 reaction 0 assignees View on GitHub
priority: p2 type: bug
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.

Screenshot 2024-03-18 at 3 55 52 PM

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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.