I am attempting to port an Openlayers2 site to OL5. The OL2 implementation has been working fine for years and does not have the issues described here.
I have most stuff working but am stumped by the following: the displayed mouse position, and the map.on events all report positions approx 5km south and 3km west of the true position on the map.
All maps are TMS grids in EPSG:2193. I allow display of mapposition coordinates in a range projections - including the NZ meter grid NZTM2000 (EPSG:2193) and lat/long WGS (EPSG:4326). But all coordinates are out by approximately 5km/3km or their degree equivalent in whatever projection I use. The magnitude of the error remains constant across all zoom levels and across the entire 2000km/3000km area of the map.
The relevant bits of code are below. Has anyone seen anything similar or got any suggestions of where to try looking/troubleshooting for mistakes? It's got me completely stumped.
proj4.defs('EPSG:2193', '+proj=tmerc +lat_0=0 +lon_0=173 +k=0.9996 +x_0=1600000 +y_0=10000000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs');
ol.proj.proj4.register(proj4);
var view = new ol.View({
center: [1600000, 5500000],
zoom: 2,
projection: ol.proj.get('EPSG:2193'),
maxResolution: 4891.969809375,
numZoomLevels: 11
});
mpc= new ol.control.MousePosition({
coordinateFormat: createStringXY(current_projdp),
projection: ol.proj.get('EPSG:'+current_proj)
});
topo50_2009=new TileLayer({
source: new XYZ({
projection: ol.proj.get('EPSG:2193'),
url: 'http://au.mapspast.org.nz/topo50/{z}/{x}/{-y}.png',
maxResolution: 4891.969809375,
numZoomLevels: 11
}),
name: 'NZTM Topo 2009',
visible: true,
projection: ol.proj.get('EPSG:2193'),
maxResolution: 4891.969809375,
numZoomLevels: 11
});
map_map = new Map({
view: view,
target: 'map',
layers: [topo50_2009],
controls: defaultControls().extend([ mpc ]),
});
==
Regarding HTML - there is nothing on the page other than the map at this stage.
<body>
<div id="map" class="map"></div>
<script> init_map(); </script>
</body>