Is there a working example for
projection | API Reference | ArcGIS API for JavaScript 4.10
I pasted the example to JSFiddle
I got the error_
Cannot read property '_getTransformation' of null
What do i miss?
Solved! Go to Solution.
Matthias,
You have to load the module first:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://js.arcgis.com/4.10/esri/css/main.css">
<script src="https://js.arcgis.com/4.10/"></script>
<script>
require([
"esri/geometry/projection",
"esri/geometry/SpatialReference",
"esri/geometry/Extent"
], function (projection,SpatialReference,Extent) {
const cs1 = new SpatialReference({
wkid: 4272 //PE_GCS_ED_1950
});
const cs2 = new SpatialReference({
wkid: 4167
});
const extent = new Extent({
xmin: -186.0,
ymin: -42.0,
xmax: -179.0,
ymax: -38.0
});
projection.load().then(function(evt) {
const geogtrans = projection.getTransformations(cs1, cs2, extent);
geogtrans.forEach(function(geogtran, index) {
geogtran.steps.forEach(function(step, index) {
console.log("step wkid: ", step.wkid);
});
});
});
});
</script>
</head>
<body >
Test
</body>
</html>
Matthias,
You have to load the module first:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://js.arcgis.com/4.10/esri/css/main.css">
<script src="https://js.arcgis.com/4.10/"></script>
<script>
require([
"esri/geometry/projection",
"esri/geometry/SpatialReference",
"esri/geometry/Extent"
], function (projection,SpatialReference,Extent) {
const cs1 = new SpatialReference({
wkid: 4272 //PE_GCS_ED_1950
});
const cs2 = new SpatialReference({
wkid: 4167
});
const extent = new Extent({
xmin: -186.0,
ymin: -42.0,
xmax: -179.0,
ymax: -38.0
});
projection.load().then(function(evt) {
const geogtrans = projection.getTransformations(cs1, cs2, extent);
geogtrans.forEach(function(geogtran, index) {
geogtran.steps.forEach(function(step, index) {
console.log("step wkid: ", step.wkid);
});
});
});
});
</script>
</head>
<body >
Test
</body>
</html>
Thank you Robert. Now it works!
The documentation at the esri page is wrong!
...Maybe they should fix that. Wrong documentation is just frustrating ...
Matthias,
Actually the load requirement is stated in the help documentation:
https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-projection.html#load
Loads this module's dependencies. This method must be called before projecting geometries.
I agree that it should be part of the code snippets though.