import view from @argis/core

472
3
Jump to solution
08-09-2021 01:39 AM
KenjooYeap
New Contributor II

Hi, 

I'm having a hard time figuring how to import "view" from "@arcgis/core/views/View" to use the `view.whenLayerview()` function` while trying to refactor the code to use WebPack. 

 

I am getting the following error: 

uncaught TypeError: _arcgis_core_views_View__WEBPACK_IMPORTED_MODULE_0__.whenLayerView is not a function

 

I have also tried using "import * as view from @arcgis/core.views/View" but that didn't help. 

 

Thanks for your replies !

0 Kudos
1 Solution

Accepted Solutions
KenjooYeap
New Contributor II

Thanks for your replies! 

I found the problem, my error was trying to import view from @arcgis/core module while the view needed for the whenLayerView is the reference to the MapView. importing the view from where mapview is defined instead works. 

View solution in original post

0 Kudos
3 Replies
BenElan
Esri Contributor

I suggest using this sample as a starting point for your app:

https://github.com/Esri/jsapi-resources/tree/master/esm-samples/webpack

If your issue is still reproducible in that sample we can take a closer look.

0 Kudos
AndyGup
Esri Regular Contributor

Tagging onto Ben's comment, add this code to that sample and it should just work:

  map.add(layer);

  view.whenLayerView(layer).then((layerView) => {
    console.log(layerView);
  })
  .catch((error) => {
    console.error(error);
  });

 

0 Kudos
KenjooYeap
New Contributor II

Thanks for your replies! 

I found the problem, my error was trying to import view from @arcgis/core module while the view needed for the whenLayerView is the reference to the MapView. importing the view from where mapview is defined instead works. 

0 Kudos