Created
May 18, 2019 09:42
-
-
Save chriswunsch00/05616e2fcd3d169a59a4588ee10c1d6d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func loadPins() { | |
var lamps = viewModel.batchLamps(forRect: mapView.visibleMapRect) | |
if lamps.count == 0 { | |
mapView.removeAnnotations(mapView.annotations) | |
return | |
} else if lamps.count > 100 { | |
let range = 100...lamps.count - 1 | |
lamps.removeSubrange(range) | |
} | |
//Get non-visible existing annotations: | |
let nonVisible = mapView.annotations.filter { (annotation: MKAnnotation) -> Bool in | |
return lamps.contains(where: { $0.id != annotation.title }) | |
} | |
mapView.removeAnnotations(nonVisible) | |
let unique = lamps.filter { (lamp: Lamp) -> Bool in | |
return !mapView.annotations.contains(where: { $0.title == lamp.id }) | |
} | |
let annotations = unique.map({ return convertLamp($0) }) | |
mapView.addAnnotations(annotations) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment