We construct a polynomial invariant of a virtual magnetic graph diagram by defining an index of an enhanced state. For a virtual link diagram, it equals the Miyazawa polynomial and then the maximal degree on $t$ of the polynomials not only gives a lower bound of the real crossing number but also that of the virtual crossing number. Moreover, by definition we can calculate the polynomial for a link in a thickened surface or a Gauss chord diagram directly without transforming it into a virtual link diagram.