Any street or other railway company, occupying with any track any street, avenue, or alley or portion thereof, which may be ordered paved, repaved, macadamized, or graveled, may be charged with the expense of such improvement of such portion of such street, avenue, or alley so occupied by it between its tracks, between its rails, and for one foot beyond the outer rails; and the cost of such improvement may be collected and enforced against such company in such manner as may be provided by ordinance; or the mayor and city council or village board of trustees may by ordinance require such company to pave, repave, macadamize, or gravel such portion of such street, avenue, or alley occupied by such tracks and for one foot beyond its outside rails.