Example for Projection

1863
3
Jump to solution
02-27-2019 05:13 AM
MatthiasHahn2
New Contributor II

Is there a working example for 

projection | API Reference | ArcGIS API for JavaScript 4.10 

I pasted the example to JSFiddle 

Edit fiddle - JSFiddle  

I got the error_

Cannot read property '_getTransformation' of null 

What do i miss?

Tags (1)
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

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>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

3 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

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>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
MatthiasHahn2
New Contributor II

Thank you Robert. Now it works!

The documentation at the esri page is wrong! 

...Maybe they should fix that. Wrong documentation is just frustrating ...

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

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.

Heather Gonzago

0 Kudos