__esri is not defined

211
3
Jump to solution
03-03-2021 02:52 PM
PeteVitt
Occasional Contributor II

Hi I'm using Angular 11, Esri Javascript api 4.18 with the ESRI loader.  I'm getting the subject error at runtime when I try to create a new 'esri/geometry/SpatialReference' object. Wierdly, Intellisense recognizes the Spatial Reference Object before I run the code.  I'm also able to create the Map and MapView objects without problems.

Any idea why this is happening?  I'm attempting to define the Spatial Reference inside the ngOnInit method within the code that gets called after the esri loader loads the ESRI modules -- same place as where the Map and MapView get created.

Thanks

Pete

The ngOnInit method is below:

ngOnInit(): void {
    loadModules([
      'esri/Map',
      'esri/views/MapView',
      'esri/geometry/support/webMercatorUtils',
      'esri/geometry/Polygon',
      'esri/geometry/SpatialReference'
    ])
      .then(([EsriMapEsriMapViewEsriwebMercatorUtils,
        EsriPolygonEsriSpatialReference
      ]) => {
...
//********the map and view get created fine:*****************
 const map = new EsriMap({
          basemap: 'streets'
        });

        this.mapView = new EsriMapView({
          container: this.viewNode.nativeElement,
          center: [-117.533.9],
          zoom: 10,
          map: map
        });
//**************problem here *******************
          this.sr = new __esri.geometry.SpatialReference();//---> error here
          this.sr.wkid = 3857;
          //*************it can be autocasted
         // let sr = { 
          //   wkid:3857
          // }
 
 
Tags (1)
0 Kudos
1 Solution

Accepted Solutions
PeteVitt
Occasional Contributor II

I switched to ES Modules and the code is running fine.  Maybe something in my project configuration was causing ESRI loader not to work.

 

Pete

View solution in original post

0 Kudos
3 Replies
AndyGup
Esri Regular Contributor

@PeteVitt use the normal API pattern for initializing a new SpatialReference:

 

const sr = new SpatialReference({
  wkid: 3857
});

 

0 Kudos
PeteVitt
Occasional Contributor II

When I changed the code I get a compile error: "Module not found: Error: Can't resolve 'esri/geometry'"

0 Kudos
PeteVitt
Occasional Contributor II

I switched to ES Modules and the code is running fine.  Maybe something in my project configuration was causing ESRI loader not to work.

 

Pete

View solution in original post

0 Kudos