O'Reilly logo

OpenLayers 3 : Beginner's Guide by Erik Hazzard, Paul Spencer, Thomas Gratier

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – reprojecting extent

Until now, we only see how to do reprojection using points coordinates but how can we do it for extent?

  1. Head to one of the official examples at http://openlayers.org/en/v3.0.0/examples/wms-image-custom-proj.html?mode=raw and see that you have extent at the layer level typing:
    console.log(extent);
  2. Apply a built-in function to transform extent from one coordinate's projection to another one:
    ol.proj.transformExtent(extent, 'EPSG:21781', 'EPSG:4326');

What just happened ?

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required