I need to transform the example coordinates to a different projection in Openlayers3, the EPSG:32628 to EPSG:3857. I made a function to do it but the result is exactly the same numbers.

function plsHelp(){
    var pt = [459123.1209, 3108334.7701];
    var scr = new ol.proj.Projection('EPSG:32628');
    var dest = new ol.proj.Projection('EPSG:3857');
    var test= ol.proj.transform(pt,scr,dest);

What is wrong with the function that is preventing the tranformation of the coordinates from EPSG:32628 to EPSG:3857 in Openlayers 3?

2 Answers 2


OpenLayers natively includes the two following projections only: EPSG:3857 and EPSG:4326. To be able to transform to or from any other projections, you must use the Proj4JS library.

Try adding the two following scripts, the first being the Proj4JS library itself, the other the definition of the EPSG:32628 projection:

<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.4.3/proj4.js"></script>
<script src="http://epsg.io/32628.js"></script>
  • After adding the scripts and removing the src and dest variables worked perfectly, thank you.
    – FoxTFM
    Apr 27, 2017 at 15:51

If it is the projection view only, you could define it right at beginning when you initiate the ol.view. code like:

   var view = new ol.View({
      //change projection to WGS84 
      projection: "EPSG:4326",
      center: [-98.5284468774974,50.71391708013823],
            zoom: 8

If you'd like to do a actual conversion, you could use openlayer's ol.proj.transform, from here. Code like below:

var oldCode = OSM_layer.getSource().getProjection().getCode(); // Getting projection of target layer 
newCoord = ol.proj.transformExtent([extent.j[0], extent.j[1], extent.j[2], extent.j[3]], oldCode, 'EPSG:4326'); // perform projection transform with given extent.
  • 1
    Thankyou so much! All over the internet, and this answer helped me get what I wanted over the line. Specifically this to get the current views extent after projection transform: const extent = view.calculateExtent(map.getSize()); const bboxCoords = ol.proj.transformExtent(extent, 'EPSG:3857', 'EPSG:4326');
    – Josh Mc
    Dec 5, 2020 at 4:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.