I had a rescue dog (GSD x Great Dane) years ago with similar behaviour.
On the lead she would work herself into a frenzy at the sight of another dog literally foaming at the mouth. However, off the lead she would play happily and had great manners around other dogs until the moment that she made physical contact with me (touching her collar, her touching my leg) then she would turn instantly aggressive to the other dog-like flicking a switch.
I hasten to add that by this point I did not let her off lead unless it was in very controlled circumstances.
With the help of a behaviourist we worked out that the original trigger for the aggression was our first training lesson approx. 3 months after we adopted her, I was nervous and she associated my anxiety with the presence of other dogs, her guarding instinct kicked in and she reacted accordingly. The trainers insisted that they could help but every week I got more nervous and she got more aggressive, after a few weeks we had a learned behaviour and were heading into a downward spiral.
It seems that her behaviour was caused by a combination of factors, my nerves, her instincts, age (18 months) and her previous circumstances of extreme neglect, no socialisation etc.
We see her every Saturday. Her owner leaves a lot to be desired. The dog is clearly aggressive but never leashed. Her stance (the dogs not the owners) is one that tells our dogs to keep their distance, which is fine except there is only so much sand and her 'space' is massive meaning our dogs have no option but to walk past her - it's that or go swimming.
Without fail this causes her to lunge aggressively at our dogs, which seems to start a sort of tag team thing with our dogs. Hers will grab the neck of the first dog it reaches, another of ours will then snap at her back end. She will let go of the first dog and grab the second, another dog will then snap at her back end. We successfully call our dogs back to us several times while this is going on but the owner won't leash her dog so it simply lunges at ours again and starts the whole thing off again until we have passed far enough away.
What is odd is that we encountered this dog again, further on our walk without her owner. It would appear that the dog ran off looking for us but she is lovely without her owner there. Very playful, relaxed, happy and waggy. If I hadn't seen the same woman come running after I wouldn't have believed it was the same dog.
Second the lady gets close enough the dog switches again back to being aggressive.