Along with its textile industry, St-Omer flourished in the 12th and 13th century. In 1127 the town received a communal charter from the count, William Clito, becoming the first town in West Flanders with city rights. Later on the city lost its leading position in the textile industry to Brugge. After the mysterious death of Count Baldwin I, the County of Flanders was weakened. In 1214 Philip II of France captured Baldwin's daughter Joan and her husband Ferdinand, Count of Flanders and forced them to sign the Treaty of Pont-à-Vendin, in which Artois was yielded to France. Ferdinand did not take this lying down, and allied with Emperor Otto IV and John, King of England, he battled Philip II at Bouvines, but was defeated. Despite the political separation for the next 170 years, the city remained part of the economic network of Flanders.