1

I am no more able to reproject a point in OpenLayers 6:

let center = ol.proj.transform(
  [2600000.0, 1200000.0],
  'EPSG:2056',
  'EPSG:4326'
);

=>
enter image description here

But this is working:

let center = ol.proj.transform(
  [46.88668, 7.47806],
  'EPSG:4326',
  'EPSG:3857'
);

Adding this line doesn't work: ol.proj.proj4.register(proj4); (as suggested in this GitHub page: https://github.com/openlayers/openlayers/issues/9199): enter image description here

Even when defining a proj4js string before, nothing changes:

proj4js.defs["EPSG:2056"] = "+proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 +k_0=1 +x_0=2600000 +y_0=1200000 +ellps=bessel +towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs";    
ol.proj.proj4.register(proj4);

Is OpenLayers not able to natively handle other standard projection than EPSG:4326 and EPSG:3857?

What did I missed?

OL source that I use is from here: https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.5.0/build/ol.js

And I proj4js from here: https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.7.0/proj4.js

1

I figure it out:

The proj string has to be given as:

proj4.defs("EPSG:2056","+proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 +k_0=1 +x_0=2600000 +y_0=1200000 +ellps=bessel +towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs");
ol.proj.proj4.register(proj4);

not as:

proj4js.defs["EPSG:2056"] = "+proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 +k_0=1 +x_0=2600000 +y_0=1200000 +ellps=bessel +towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs";    
ol.proj.proj4.register(proj4);

In the latter case, proj4js in undefined. Maybe it's deprecated in favor of proj4(?).

An example is shown in this jsfiddle: https://jsfiddle.net/dtyrws39/

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.