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):
Is there something wrong in the projection definition? Or is it something with the OpenLayers OSM TileLayer? What am I missing here?