Until now, we only see how to do reprojection using points coordinates but how can we do it for extent?
console.log(extent);
ol.proj.transformExtent(extent, 'EPSG:21781', 'EPSG:4326');
We reused the function behind the ol.proj.transform function without knowledge.
The ol.proj.transformExtent method expects an extent as a first parameter, as a second parameter, it needs the origin projection, and as a third parameter, it's the destination projection. We declared that we use as input the extent; as origin, EPSG:2181; and as destination, EPSG:4326. At the internal OpenLayers 3 library level, the function loops on the extent and transforms each coordinate.
With this function, if we need to get a bounding box in EPSG:4326 from local projections, it will really help.
If you remember Chapter 4, Interacting with Raster Data Source, we introduced you to the tiled and untiled raster. Most tiled rasters do not serve in a foreign projection, for example, a non-Spherical Mercator projection, but contrary to most cases, WMS sources can be served and consume using custom projections.