Rightpoint / BentoMap

Map Clustering for Swift.
MIT License
182 stars 10 forks source link

How to control the initial zoom rect #31

Open fraserscottmorrison opened 7 years ago

fraserscottmorrison commented 7 years ago

Hi, this is a question

I have a dataset of up to 1000 items but I want the map to initially zoom into the 10 that are closest to the users location.

So currently I populate the quad tree with the 100 items, and I also populate a second quad tree with the closest 10, then call

let zoomRect = self.mapView.mapRectThatFits(closest10QuadTree.bentoBox.root, edgePadding: type(of: self).mapInsets)

self.mapView.setVisibleMapRect(zoomRect, edgePadding: type(of: self).mapInsets, animated: true)

Which is working, but slow (3 seconds). Is there a better way to do this? Cheers Fraser

ateliercw commented 7 years ago

If you have the closest 10 items, it may be faster to just iterate through that list and save the minX, minY, maxX and maxY for those 10 items and use that to generate your inner zoom rect. That being said, when I was performance testing the app was relatively performant with data sets in the 100,000 element range stored in the quad tree. If the app is slow with that small of a set of items, I'd see if there are UI calls happening off the main thread (that can cause multi-second delays) or possibly only store a minimal subset of data in the quadtree (item ID, and details required for display) and use that itemID to look up the more complete object on node selection from something that's optimized for storing large object graphs like Core Data or Realm.