Well, either he saw it or someone complained about it. Today, cops are becoming more and more aggressive and dangerous, be careful when dealing with them, you never know when you get a crazy one. Unless you have a local ordinance against such (I have never heard of such a thing), I doubt it is illegal. Also, since he didn't immediately come looking to arrest you, I doubt he was doing more than just being a dick, so to speak. All of that said, if someone complained I imagine he could warn or even arrest you for disturbing the peace, that's always an easy one to use if a complaint, even if legal. Would it stand up in court though? Either way, they win, having harassed you and made a record for you, even if you win against it, the record remains as a blemish for potential employers to see. Civilization! Ain't it great! At least we aren't lonely, nor would you be in jail, might be a new friend wanting to meet up with you there. My cousin was arrested for using his laser pointer to turn off a street light across from his house, a helicopter pilot complained he was being harassed by his green laser because he saw it and thought that was his intent. You can be arrested for pointing at aircraft even if you didn't intend it or know they were there or for that matter, even if they think you were trying to do so when you weren't, be careful.
I'm a pilot myself, have been for many years and I can tell you we can be real arrogant asses thinking we are sky kings and you lowly earthlings need to be kept at bay, you are ground dwellers and need to understand your place, we don't even want to see a laser pointing up into our domain, whether pointed directly at us or not.