Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maps: calling GMUHeatmapTileLayer.clearTileCache() has no effect in updating heatmap's options such as radius, gradient etc #402

Open
kvog001 opened this issue Apr 20, 2022 · 5 comments
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@kvog001
Copy link

kvog001 commented Apr 20, 2022

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!

@kvog001 kvog001 added triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Apr 20, 2022
@jpoehnelt
Copy link
Contributor

@kvogli Thank you for opening this issue. 🙏
Please check out these other resources that might be applicable:

This is an automated message, feel free to ignore.

@Rexios80
Copy link

You have to call heatmapLayer.map = yourMapView first

#154 (comment)

@Rexios80
Copy link

This should probably be documented here: https://developers.google.com/maps/documentation/ios-sdk/utility/heatmap#change-the-dataset

I had the same issue, and the instructions on that site are pretty much just outright incorrect

@kvog001
Copy link
Author

kvog001 commented Apr 20, 2022

You have to call heatmapLayer.map = yourMapView first

#154 (comment)

Thanks for the help! That seems to work only halfway though - the rendering is still quite laggy after updating the radius and not as responsive as compared to changing the opacity. I'm not sure if this is the final solution or there is a better one (possibly a bug may still persist?)

And yes i agree that the documentation needs an update for this section.

@Rexios80
Copy link

I see the same behavior on iOS and Android. Web is the only platform that updates instantly.

@jpoehnelt jpoehnelt removed their assignment Jun 17, 2022
@iHackSubhodip iHackSubhodip added the priority: p3 Desirable enhancement or fix. May not be included in next release. label Nov 9, 2024
@wangela wangela removed the triage me I really want to be triaged. label Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

5 participants