When I do this in JavaScript, using OpenLayers 3, it works:
ol.proj.transform([153.47, -28.11], 'EPSG:4326', 'EPSG:3857');
I realize that this is because OpenLayers already knows both projections and is able to transform between them.
I want to be able to project from 'EPSG:28356' (GDA94 zone 56) to 'EPSG:3857'. So, I've installed and imported proj4js, got the appropriate string from http://spatialreference.org/ref/epsg/gda94-mga-zone-56/proj4js/ and it gives me:
"+proj=utm +zone=56 +south +ellps=GRS80 +towgs84=200,0,0,0,0,0,0 +units=m +no_defs"
So, in my code:
proj4.defs("EPSG:28356", "+proj=utm +zone=56 +south +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs");
let projection = new ol.proj.Projection({
code: this.props.item.data.code,
units: this.props.item.data.units,
extent: this.props.item.data.extent
});
ol.proj.addProjection(projection);
let c1 = [543100.508297332, 6880073.9025688];
let c2 = ol.proj.transform(c1, 'EPSG:28356', 'EPSG:3857');
But this doesn't work. It didn't surprise me to get the exact same coordinates (somewhat rounded) back in c2, since the string states '+towgs84=0,0,0,0,0,0,0'.
I can also get the correct result from https://epsg.io/transform#s_srs=28356&t_srs=3857&x=543100.5082973&y=6880073.9025688 which would be [17080772.24, -3274771.77].
Does spatialreference.org give me the wrong proj4 string for this projection and if so, where to get a correct one? Or am I making some other mistake in trying to get this projection to work?