If you genuinely believe that you consumed enough electrolytes and drank enough water ... and if you tried drinking more water and consuming more electrolytes (i.e. eating a package of salted almonds) when you started cramping ... and if none of that helped ...
How tight are the legs of your cycling shorts? Especially the elastic band at the bottom of the legs of your cycling shorts?