1

I am new to OpenLayers and haven't been able to figure out this problem by searching online. I am using a custom projection in OpenLayers 7.4.0 with proj4 2.9.0 as demonstrated in this example. The projection definition I am using was taken directly from EPSG:28992 Amersfoort / RD New. Here is my code:

import proj4 from 'proj4';
import { register } from 'ol/proj/proj4.js';
import { get as getProjection } from 'ol/proj.js';

proj4.defs("EPSG:28992",
  "+proj=sterea +lat_0=52.1561605555556 +lon_0=5.38763888888889"
  + " +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel"
  + " +towgs84=565.4171,50.3319,465.5524,1.9342,-1.6677,9.1019,4.0725"
  + " +units=m +no_defs +type=crs"
);

register(proj4);
const rd = getProjection('EPSG:28992');

const map = new Map({
  interactions: defaultInteractions({ dragPan: false }).extend([
    new DragPan({
      condition: function (mapBrowserEvent) {
        return (
          mapBrowserEvent.originalEvent.isPrimary &&
          mapBrowserEvent.originalEvent.button < 2
        );
      },
    }),
  ]),
  target: 'map',
  layers: [
    new TileLayer({
      source: new OSM({
        projection: rd
      })
    }),
    new ImageLayer({
      source: new ImageWMS({
        url: 'https://service.pdok.nl/rws/ahn/wms/v1_0',
        params: { 'LAYERS': 'dtm_05m' },
        projection: rd
      }),
    }),
  ],
  view: new View({
    center: [150000, 463000],
    zoom: 13,
    projection: rd
  })
});

I've added an OSM layer and a WMS layer (taken from here). But when I look at my map, the OSM and WMS layers are slightly translated (only translated, not scaled or skewed):

enter image description here

Is there something wrong in the projection definition? Or is it something with the OpenLayers OSM TileLayer? What am I missing here?

8
  • There is a difference between that projection definition and the one used by the server. You could try any of these alternatives epsg.io/28992-4833 epsg.io/28992-15934 epsg.io/28992-1112 epsg.io/28992-1672 epsg.io/28992-8572 and this very old GeoServer definition geoserver-users.narkive.com/GbCNUXVz/… seems to work well with your data. OSM is always served as EPSG:3857 and will be reprojected by OpenLayers, specifying a projection in its options has no effect.
    – Mike
    Commented Aug 9, 2023 at 10:14
  • @Mike, I've tried all of those, including the old GeoServer definition and none of them do the job. I had indeed already figured out that the projection attribute in those layers did not do anything. When I import both those OSM and WMS layers in QGIS with the CRS set as EPSG:28992 they do overlap (using some kind of inverse projection EPSG:19914). I don't get it...
    – pklaassen
    Commented Aug 9, 2023 at 10:57
  • If you specify EPSG:3857 as the WMS projection OpenLayers will reproject it as well as The OSM - Inefficient but the alignment looks better
    – Mike
    Commented Aug 9, 2023 at 12:04
  • 1
    This appears to be the proj4 definition used by the service pdok-ngr.readthedocs.io/…
    – Mike
    Commented Aug 9, 2023 at 13:46
  • 1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.