Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriswunsch00/05616e2fcd3d169a59a4588ee10c1d6d to your computer and use it in GitHub Desktop.
Save chriswunsch00/05616e2fcd3d169a59a4588ee10c1d6d to your computer and use it in GitHub Desktop.
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