[OpenLayers-Users] Using CRS not supported by proj4js

ldesousa luis.de.sousa at protonmail.ch
Thu Aug 15 07:33:09 PDT 2019


Hi all,

OpenLayers 5 uses by default the CRS associated with the EPSG code 3857. To
use a different CRS a proj4js object must be declared and registered (like
in the small example below). Unfortunately, the level of support provided by
proj4js is inferior to that found in PROJ and GDAL. It is easy to find a
service publishing data in a CRS not support by proj4js.

Since for a WMS service (for instance) all that is needed is a string
identifying the CRS (e.g. authority:id supported by PROJ) I would like to
know if it is possible to skip the proj4js object and use strings directly.

Thank you,

Luís 

var Map                 = ol.Map;        //~ import Map from 'ol/Map.js';
var View                = ol.View;       //~ import View from 'ol/View.js';
var TileLayer           = ol.layer.Tile; //~ import TileLayer from
'ol/layer/Tile.js';
var OSM                 = ol.source.OSM; //~ import OSM from
'ol/source/OSM.js';
var TileWMS           = ol.source.TileWMS; //~ import TileWMS from
'ol/source/TileWMS.js';  
var proj4             = proj4;             //~ import proj4 from 'proj4';
var register            = ol.proj.proj4.register; //~ import {register} from
'ol/proj/proj4';
      var getProjection       = ol.proj.get;     //~ import {get as
getProjection} from 'ol/proj';

proj4.defs('EPSG:152160',
        '+proj=igh +lat_0=0 +lon_0=0 +datum=WGS84 +units=m +no_defs');
register(proj4);
const homolosine = getProjection('EPSG:152160');

var layers = [
    new TileLayer({
      extent: [-1.99496e+07, -8.68326e+06, 1.99675e+07, 8.41393e+06],
      source: new TileWMS({
        url: 'http://localhost/cgi-bin/mapserv?map=/mapfiles/countries.map',
        params: {'LAYERS': 'Countries', 'TILED': true},
        serverType: 'mapserver',
        // Countries have transparency, so do not fade tiles:
        transition: 0
      })
    })
  ];
var map = new Map({
    layers: layers,
    target: 'map',
    view: new View({
      projection: homolosine,
      center: [0, 18000],
      zoom: 4
    })
  });



--
Sent from: http://osgeo-org.1560.x6.nabble.com/OpenLayers-Users-f3910695.html


More information about the Users mailing list