I have a Node mapping application that uses openlayers V5.3.0. When I try to transform geometries from EPSG:4326 to a projection defined using proj4.defs I get this error message: TypeError: Cannot read property 'getCode' of null
If I change openLayers to version 4.6.4 the code to transform the geometries works.
Has anyone else experienced this issue?
The following HTML demonstrates the problem.
<html>
<head>
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" >
<title>Projection Test</title>
<script
src="https://code.jquery.com/jquery-2.2.4.min.js"
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
crossorigin="anonymous"></script>
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/openlayers/4.6.4/ol-debug.js"></script> -->
<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.5.0/proj4.js"></script>
<script>proj4.defs("EPSG:28355","+proj=utm +zone=55 +south +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs");</script>
<script>
$(document).ready(function() {
let gJSONOpts = {
dataProjection: "EPSG:3857",
featureProjection: "EPSG:28355"
};
let jsonPt = {
"type": "Feature",
"id": "GEO_BRM_STOPS.fid--79f50be5_16adc4d0ce7_6a6b",
"geometry": {
"type": "Point",
"coordinates": [16154413.50099648, -4988654.4460995]
},
"geometry_name": "OBJ"
};
let feature = new ol.format.GeoJSON().readFeature(jsonPt.geometry, gJSONOpts);
let tg = feature.getGeometry().transform('EPSG:28355', "EPSG:4326");
let out = 'Projected Coordinates: ' + tg.getCoordinates()[0] + ', ' +tg.getCoordinates()[1];
$("#mapvwr").html(out);
});
</script>
</head>
<body>
<div id="mapvwr">
</div>
</body>
</html>
Paste the above into an html file and show it in the browser.
Uncomment this line:
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/openlayers/4.6.4/ol-debug.js"></script> -->
and comment out the following line:
<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
To see the correct result:
Projected Coordinates: 145.11756553931886, -40.83921285742692