I would wait until leaving was imminent, things can change and I wouldn't want to tell them and then end up not leaving. I'd give them as much notice as possible, but only when I was 100% certain I was leaving, a lot can change in a couple years time.