googlemaps / googlemaps/google-maps-ios-utils
Maps: calling GMUHeatmapTileLayer.clearTileCache() has no effect in updating heatmap's options such as radius, gradient etc
- Dominant language
- Objective-C
- Stars
- 778
- Forks
- 441
- PR merge metrics
- No merged PRs in 30d
Description
Hi, i believe there is a bug when calling clearTileCache() after changing heatmap's properties such as radius etc,. I have installed GoogleMapsUtils (v6.0.1-beta) via Carthage on an M1 machine.
#### Environment details
M1 machine
Xcode 13.1
Carthage 0.38.0
Google-Maps-Utils 6.0.1-beta
#### Code example
```
class Heatmap: UIViewController {
private var mapView: GMSMapView!
private var heatmapLayer: GMUHeatmapTileLayer!
override func viewDidLoad() {
super.viewDidLoad()
heatmapLayer = GMUHeatmapTileLayer()
heatmapLayer.map = mapView
addUISlider(x: 5, y: 80, width: 170, height: 15, minVal: 0.05, maxVal: 10.0, objcFunc: #selector(self.opacitySliderValueDidChange(_:)))
addUISlider(x: 5, y: 120, width: 170, height: 15, minVal: 10, maxVal: 60, objcFunc: #selector(self.radiusSliderValueDidChange(_:)))
}
// ...
func addHeatmap() {
// Get the data: latitude/longitude positions of police stations.
guard let path = Bundle.main.url(forResource: "police_stations", withExtension: "json") else {
return
}
guard let data = try? Data(contentsOf: path) else {
return
}
guard let json = try? JSONSerialization.jsonObject(with: data, options: []) else {
return
}
guard let object = json as? [[String: Any]] else {
print("Could not read the JSON.")
return
}
var list = [GMUWeightedLatLng]()
for item in object {
let lat = item["lat"] as! CLLocationDegrees
let lng = item["lng"] as! CLLocationDegrees
let coords = GMUWeightedLatLng(
coordinate: CLLocationCoordinate2DMake(lat, lng),
intensity: 1.0
)
list.append(coords)
}
// Add the latlngs to the heatmap layer.
heatmapLayer.weightedData = list
}
private func addUISlider(
x: Int,
y: Int,
width: Int,
height: Int,
minVal: Float,
maxVal: Float,
objcFunc: Selector) {
let slider = UISlider(frame:CGRect(x: x, y: y, width: width, height: height))
slider.minimumValue = minVal
slider.maximumValue = maxVal
slider.isContinuous = true
slider.addTarget(self, action: objcFunc, for: .valueChanged)
view.addSubview(slider)
}
@objc
func opacitySliderValueDidChange(_ sender: UISlider!) {
let step: Float = 0.05
let stepValue = sender.value / step * step
sender.value = stepValue
heatmapLayer.opacity = stepValue
heatmapLayer.clearTileCache()
}
@objc
func radiusSliderValueDidChange(_ sender: UISlider!) {
let step = 1
let stepValue = Int(sender.value) / step * step
sender.value = Float(stepValue)
radius = UInt(stepValue)
heatmapLayer.radius = radius
heatmapLayer.clearTileCache()
}
}
```
Changing heatmap's opacity shows instantly in the map, even _without_ calling .clearTileCache() afterwards. Calling it in this case only rerenders the tiles and slows down the zoom in/ zoom out experience.
While creating a new heatmap layer with the desired radius -- seems like the change is taken into considerate only in the initialization. Calling .clearTileCache() afterwards just rerenders the tiles without updating aynthing. Same holds for these other options: gradient, minimumZoomIntensity, maximumZoomIntensity.
Thanks!
Contributor guide
Assessment
This issue has not been assessed yet.