Annotations filter by viewport

Implementation for #540 and related minor improvements.
What you said is a problem here?

(You can always create a pull request and put questions directly in the code.)