Rightpoint / BentoMap

Map Clustering for Swift.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Small movements seem to cause clustering changes in sample code

aodhol opened this issue · comments

If you scroll the map left or right the clusters seem to change. Is the desired behaviour? I've attempted to rectify this by rounding the zoom scale to 6 decimal places and comparing with the previous before updating the annotations...

@aodhol the rect that clustering is pulled from need to be rounded relative to the current step size to make the clusters stay the same between pans.

@ateliercw How might I round the rect relative to the step size? I tried passing in an integral MapRect with little effect..

@aodhol If I recall correctly, the answer is using modulo division to find the x and y offset relative to the step size, then offsetting the lookup rects origin by that value.

I tried this: (without success), if this what you meant?

let scaleFactor: Double

// Prevents divide by zero errors from cropping up if handed bad data
if cellSize == 0 || zoomScale == 0 {
    scaleFactor = 1
} else {
    scaleFactor = zoomScale / Double(cellSize)
}

let stepSize = CGFloat(1.0 / scaleFactor)
// round the rect relative to the step size
let offsetRect = MKMapRectOffset(root, root.origin.x.truncatingRemainder(dividingBy: Double(stepSize)), root.origin.y.truncatingRemainder(dividingBy: Double(stepSize)))

let clusterResults = mapData.clusteredDataWithinMapRect(offsetRect,
                                                        zoomScale: zoomScale,
                                                        cellSize: Double(cellSize))

Note, the root rect (derived from the visibleMapRect) and consequently the step size here are changing even with the slightest of pan movements..

(thanks by the way!)

@aodhol - 0.3.2 should fix the jitter without requiring any changes to the example project, the math was much easier to figure out inside the lookup than from outside

@ateliercw It works perfectly! Thanks Michael, stellar work :)